Skip to content

Commit b285076

Browse files
authored
Merge pull request #40 from icatalina/CHECKOUT-2358
CHECKOUT-2358 Add extra data for CyberSource
2 parents b172441 + e29dbf7 commit b285076

8 files changed

Lines changed: 50 additions & 1 deletion

File tree

src/payment/v1/payment-mappers/customer-mapper.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default class CustomerMapper {
1616
const { customer = {}, quoteMeta = {} } = data;
1717

1818
return omitNil({
19+
customer_group: customer.customerGroupName ? { name: customer.customerGroupName } : null,
1920
geo_ip_country_code: quoteMeta.request ? quoteMeta.request.geoCountryCode : null,
2021
id: customer.customerId ? toString(customer.customerId) : null,
2122
session_token: quoteMeta.request ? quoteMeta.request.sessionHash : null,

src/payment/v1/payment-mappers/order-mapper.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default class OrderMapper {
1717

1818
return omitNil({
1919
billing_address: this.mapToBillingAddress(data),
20+
coupons: this.mapToCoupons(data),
2021
currency: order.currency,
2122
id: order.orderId ? toString(order.orderId) : null,
2223
items: this.mapToItems(data),
@@ -42,6 +43,19 @@ export default class OrderMapper {
4243
return address;
4344
}
4445

46+
/**
47+
* @private
48+
* @param {PaymentRequestData} data
49+
* @returns {Coupon[]}
50+
*/
51+
mapToCoupons({ order = {} }) {
52+
if (order.coupon && order.coupon.coupons) {
53+
return order.coupon.coupons.map(({ code }) => ({ code }));
54+
}
55+
56+
return [];
57+
}
58+
4559
/**
4660
* @private
4761
* @param {PaymentRequestData} data

src/payment/v1/payment-mappers/payment-mapper.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,17 @@ export default class PaymentMapper {
3030
* @returns {Object}
3131
*/
3232
mapToPayment(data) {
33-
const { order = {}, payment = {}, paymentMethod = {}, quoteMeta = {} } = data;
33+
const {
34+
order = {},
35+
orderMeta = {},
36+
payment = {},
37+
paymentMethod = {},
38+
quoteMeta = {},
39+
} = data;
3440

3541
const payload = {
3642
device_info: quoteMeta.request ? quoteMeta.request.deviceSessionId : null,
43+
device: orderMeta.deviceFingerprint ? { fingerprint_id: orderMeta.deviceFingerprint } : null,
3744
gateway: this.paymentMethodIdMapper.mapToId(paymentMethod),
3845
notify_url: order.callbackUrl,
3946
return_url: paymentMethod.returnUrl || (order.payment ? order.payment.returnUrl : null),

src/typedefs.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,8 @@
102102
* @property {string} storeLanguage
103103
* @property {string} storeName
104104
*/
105+
106+
/**
107+
* @typedef {Object} Coupon
108+
* @property {string} code
109+
*/

test/mocks/payment-request-data.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const paymentRequestDataMock = {
5151
],
5252
},
5353
customer: {
54+
customerGroupName: 'b2b',
5455
customerId: '123',
5556
email: 'email@bigcommerce.com',
5657
firstName: 'Foo',
@@ -60,6 +61,13 @@ const paymentRequestDataMock = {
6061
},
6162
order: {
6263
callbackUrl: '/order/123/payment',
64+
coupon: {
65+
coupons: [{
66+
code: 'fiver',
67+
name: 'Five off',
68+
discount: '$5.00 off the order total',
69+
}],
70+
},
6371
currency: 'AUD',
6472
discount: {
6573
integerAmount: 0,
@@ -82,6 +90,9 @@ const paymentRequestDataMock = {
8290
},
8391
token: 'abc123',
8492
},
93+
orderMeta: {
94+
deviceFingerprint: 'xyz1234',
95+
},
8596
payment: {
8697
ccCvv: '123',
8798
ccExpiry: {

test/payment/v1/payment-mappers/customer-mapper.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe('CustomerMapper', () => {
2020
const output = customerMapper.mapToCustomer(data);
2121

2222
expect(output).toEqual({
23+
customer_group: { name: data.customer.customerGroupName },
2324
geo_ip_country_code: data.quoteMeta.request.geoCountryCode,
2425
id: `${data.customer.customerId}`,
2526
session_token: data.quoteMeta.request.sessionHash,

test/payment/v1/payment-mappers/order-mapper.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ describe('OrderMapper', () => {
6060
street_2: data.shippingAddress.addressLine2,
6161
zip: data.shippingAddress.postCode,
6262
},
63+
coupons: [{
64+
code: data.order.coupon.coupons[0].code,
65+
}],
6366
totals: {
6467
grand_total: data.order.grandTotal.integerAmount,
6568
handling: data.order.handling.integerAmount,
@@ -73,6 +76,7 @@ describe('OrderMapper', () => {
7376

7477
it('returns an empty object if the input does not contain order information', () => {
7578
expect(orderMapper.mapToOrder({})).toEqual({
79+
coupons: [],
7680
billing_address: {},
7781
items: [],
7882
shipping_address: {},

test/payment/v1/payment-mappers/payment-mapper.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ describe('PaymentMapper', () => {
3535
verification_value: data.payment.ccCvv,
3636
year: parseInt(data.payment.ccExpiry.year, 10),
3737
},
38+
device: {
39+
fingerprint_id: data.orderMeta.deviceFingerprint,
40+
},
3841
device_info: data.quoteMeta.request.deviceSessionId,
3942
gateway: data.paymentMethod.id,
4043
notify_url: data.order.callbackUrl,
@@ -55,6 +58,9 @@ describe('PaymentMapper', () => {
5558
credit_card_token: {
5659
token: data.paymentMethod.nonce,
5760
},
61+
device: {
62+
fingerprint_id: data.orderMeta.deviceFingerprint,
63+
},
5864
device_info: data.quoteMeta.request.deviceSessionId,
5965
gateway: data.paymentMethod.id,
6066
notify_url: data.order.callbackUrl,

0 commit comments

Comments
 (0)