Skip to content

Commit

Permalink
feat(payment): CHECKOUT-2358 Add extra data for CyberSource
Browse files Browse the repository at this point in the history
Add customerGroup, deviceFingerprint and coupon list for CyberSource.
  • Loading branch information
icatalina committed Sep 1, 2017
1 parent f1c0499 commit e29dbf7
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/payment/v1/payment-mappers/customer-mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default class CustomerMapper {
const { customer = {}, quoteMeta = {} } = data;

return omitNil({
customer_group: customer.customerGroupName ? { name: customer.customerGroupName } : null,
geo_ip_country_code: quoteMeta.request ? quoteMeta.request.geoCountryCode : null,
id: customer.customerId ? toString(customer.customerId) : null,
session_token: quoteMeta.request ? quoteMeta.request.sessionHash : null,
Expand Down
14 changes: 14 additions & 0 deletions src/payment/v1/payment-mappers/order-mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default class OrderMapper {

return omitNil({
billing_address: this.mapToBillingAddress(data),
coupons: this.mapToCoupons(data),
currency: order.currency,
id: order.orderId ? toString(order.orderId) : null,
items: this.mapToItems(data),
Expand All @@ -42,6 +43,19 @@ export default class OrderMapper {
return address;
}

/**
* @private
* @param {PaymentRequestData} data
* @returns {Coupon[]}
*/
mapToCoupons({ order = {} }) {
if (order.coupon && order.coupon.coupons) {
return order.coupon.coupons.map(({ code }) => ({ code }));
}

return [];
}

/**
* @private
* @param {PaymentRequestData} data
Expand Down
9 changes: 8 additions & 1 deletion src/payment/v1/payment-mappers/payment-mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ export default class PaymentMapper {
* @returns {Object}
*/
mapToPayment(data) {
const { order = {}, payment = {}, paymentMethod = {}, quoteMeta = {} } = data;
const {
order = {},
orderMeta = {},
payment = {},
paymentMethod = {},
quoteMeta = {},
} = data;

const payload = {
device_info: quoteMeta.request ? quoteMeta.request.deviceSessionId : null,
device: orderMeta.deviceFingerprint ? { fingerprint_id: orderMeta.deviceFingerprint } : null,
gateway: this.paymentMethodIdMapper.mapToId(paymentMethod),
notify_url: order.callbackUrl,
return_url: paymentMethod.returnUrl || (order.payment ? order.payment.returnUrl : null),
Expand Down
5 changes: 5 additions & 0 deletions src/typedefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,8 @@
* @property {string} storeLanguage
* @property {string} storeName
*/

/**
* @typedef {Object} Coupon
* @property {string} code
*/
11 changes: 11 additions & 0 deletions test/mocks/payment-request-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const paymentRequestDataMock = {
],
},
customer: {
customerGroupName: 'b2b',
customerId: '123',
email: '[email protected]',
firstName: 'Foo',
Expand All @@ -60,6 +61,13 @@ const paymentRequestDataMock = {
},
order: {
callbackUrl: '/order/123/payment',
coupon: {
coupons: [{
code: 'fiver',
name: 'Five off',
discount: '$5.00 off the order total',
}],
},
currency: 'AUD',
discount: {
integerAmount: 0,
Expand All @@ -82,6 +90,9 @@ const paymentRequestDataMock = {
},
token: 'abc123',
},
orderMeta: {
deviceFingerprint: 'xyz1234',
},
payment: {
ccCvv: '123',
ccExpiry: {
Expand Down
1 change: 1 addition & 0 deletions test/payment/v1/payment-mappers/customer-mapper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('CustomerMapper', () => {
const output = customerMapper.mapToCustomer(data);

expect(output).toEqual({
customer_group: { name: data.customer.customerGroupName },
geo_ip_country_code: data.quoteMeta.request.geoCountryCode,
id: `${data.customer.customerId}`,
session_token: data.quoteMeta.request.sessionHash,
Expand Down
4 changes: 4 additions & 0 deletions test/payment/v1/payment-mappers/order-mapper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ describe('OrderMapper', () => {
street_2: data.shippingAddress.addressLine2,
zip: data.shippingAddress.postCode,
},
coupons: [{
code: data.order.coupon.coupons[0].code,
}],
totals: {
grand_total: data.order.grandTotal.integerAmount,
handling: data.order.handling.integerAmount,
Expand All @@ -73,6 +76,7 @@ describe('OrderMapper', () => {

it('returns an empty object if the input does not contain order information', () => {
expect(orderMapper.mapToOrder({})).toEqual({
coupons: [],
billing_address: {},
items: [],
shipping_address: {},
Expand Down
6 changes: 6 additions & 0 deletions test/payment/v1/payment-mappers/payment-mapper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ describe('PaymentMapper', () => {
verification_value: data.payment.ccCvv,
year: parseInt(data.payment.ccExpiry.year, 10),
},
device: {
fingerprint_id: data.orderMeta.deviceFingerprint,
},
device_info: data.quoteMeta.request.deviceSessionId,
gateway: data.paymentMethod.id,
notify_url: data.order.callbackUrl,
Expand All @@ -55,6 +58,9 @@ describe('PaymentMapper', () => {
credit_card_token: {
token: data.paymentMethod.nonce,
},
device: {
fingerprint_id: data.orderMeta.deviceFingerprint,
},
device_info: data.quoteMeta.request.deviceSessionId,
gateway: data.paymentMethod.id,
notify_url: data.order.callbackUrl,
Expand Down

0 comments on commit e29dbf7

Please sign in to comment.