Skip to content

Instantly share code, notes, and snippets.

@0xjocke
Created January 20, 2017 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xjocke/739f966711472d7dce78f119201c10e2 to your computer and use it in GitHub Desktop.
Save 0xjocke/739f966711472d7dce78f119201c10e2 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