Skip to content

Instantly share code, notes, and snippets.

@0xjocke
Created January 20, 2017 11:09
Show Gist options
  • Save 0xjocke/da4e9103a382584a95cea86416ac5f53 to your computer and use it in GitHub Desktop.
Save 0xjocke/da4e9103a382584a95cea86416ac5f53 to your computer and use it in GitHub Desktop.
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