Created
January 20, 2017 11:08
-
-
Save 0xjocke/739f966711472d7dce78f119201c10e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { get } from 'lodash' | |
// add second argument to get() where default is wanted | |
const parsePayment = (payment) => { | |
const payerInfo = get(payment, ['payer', 'payer_info']) | |
const item = get(payment, 'transactions[0]') | |
return { | |
id: payment.id, | |
created: moment(payment.create_time).format('X'), | |
email: get(payerInfo, ['email']), | |
firstName: get(payerInfo, ['first_name']), | |
lastName: get(payerInfo, ['last_name']), | |
state: get(payerInfo, ['shipping_address', 'state']), | |
country: get(payerInfo, ['shipping_address', 'country_code']), | |
amount: parseInt(get(item, ['amount', 'total']), 0) * 100, | |
description: get(item, 'item_list,items[0].name'), | |
metadata: { | |
quantity: parseInt(get(item, 'item_list,items[0].quantity'), 10) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment