Skip to content

Commit 953500d

Browse files
Calculate correct tax for applePay express (#1079)
* fix: calculate correct tax for applePay express * test: update unit tests
1 parent 125e268 commit 953500d

3 files changed

Lines changed: 44 additions & 4 deletions

File tree

src/cartridges/app_adyen_SFRA/cartridge/client/default/js/applePayExpress.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ initializeCheckout()
233233
country: shippingContact.country,
234234
countryCode: shippingContact.countryCode,
235235
stateCode: shippingContact.administrativeArea,
236+
postalCode: shippingContact.postalCode,
236237
})}`,
237238
);
238239
if (shippingMethods.ok) {

src/cartridges/int_adyen_SFRA/cartridge/adyen/scripts/expressPayments/__tests__/shippingMethods.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/* eslint-disable global-require */
2+
const BasketMgr = require('dw/order/BasketMgr');
23
const AdyenHelper = require('*/cartridge/adyen/utils/adyenHelper');
34

45
let res;
56
let req;
67
const next = jest.fn();
78

89
const callGetShippingMethods = require('../shippingMethods');
10+
const Logger = require("../../../../../../../../jest/__mocks__/dw/system/Logger");
911

1012
beforeEach(() => {
1113
jest.clearAllMocks();
@@ -15,6 +17,7 @@ beforeEach(() => {
1517
city: 'Amsterdam',
1618
countryCode: 'NL',
1719
stateCode: 'AMS',
20+
postalCode: '1001',
1821
shipmentUUID: 'mocked_uuid',
1922
},
2023
locale: { id: 'nl_NL' },
@@ -52,4 +55,28 @@ describe('Shipping methods', () => {
5255
callGetShippingMethods(req, res, next);
5356
expect(res.json).not.toHaveBeenCalled();
5457
});
58+
it('Should update shipping address for the basket', () => {
59+
const Logger = require('../../../../../../../../jest/__mocks__/dw/system/Logger');
60+
const setCityMock = jest.fn()
61+
const setPostalCodeMock = jest.fn()
62+
const setStateCodeMock = jest.fn()
63+
const setCountryCodeMock = jest.fn()
64+
const currentBasketMock = {
65+
getDefaultShipment: jest.fn(() =>({
66+
createShippingAddress: jest.fn(() => ({
67+
setCity: setCityMock,
68+
setPostalCode: setPostalCodeMock,
69+
setStateCode: setStateCodeMock,
70+
setCountryCode: setCountryCodeMock
71+
}))
72+
})),
73+
};
74+
BasketMgr.getCurrentBasket.mockReturnValueOnce(currentBasketMock);
75+
callGetShippingMethods(req, res, next);
76+
expect(setCityMock).toHaveBeenCalledWith('Amsterdam');
77+
expect(setPostalCodeMock).toHaveBeenCalledWith('1001');
78+
expect(setStateCodeMock).toHaveBeenCalledWith('AMS');
79+
expect(setCountryCodeMock).toHaveBeenCalledWith('NL');
80+
expect(Logger.error.mock.calls.length).toBe(0);
81+
});
5582
});

src/cartridges/int_adyen_SFRA/cartridge/adyen/scripts/expressPayments/shippingMethods.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const BasketMgr = require('dw/order/BasketMgr');
2+
const Transaction = require('dw/system/Transaction');
23
const AdyenLogs = require('*/cartridge/adyen/logs/adyenCustomLogs');
34
const AdyenHelper = require('*/cartridge/adyen/utils/adyenHelper');
45

@@ -13,14 +14,25 @@ function callGetShippingMethods(req, res, next) {
1314
city: req.querystring.city,
1415
countryCode: req.querystring.countryCode,
1516
stateCode: req.querystring.stateCode,
17+
postalCode: req.querystring.postalCode,
1618
};
1719
}
1820
const currentBasket = BasketMgr.getCurrentBasket();
21+
const shipment = currentBasket.getDefaultShipment();
22+
Transaction.wrap(() => {
23+
let { shippingAddress } = shipment;
24+
if (!shippingAddress) {
25+
shippingAddress = currentBasket
26+
.getDefaultShipment()
27+
.createShippingAddress();
28+
}
29+
shippingAddress.setCity(address.city);
30+
shippingAddress.setPostalCode(address.postalCode);
31+
shippingAddress.setStateCode(address.stateCode);
32+
shippingAddress.setCountryCode(address.countryCode);
33+
});
1934
const currentShippingMethodsModels =
20-
AdyenHelper.getApplicableShippingMethods(
21-
currentBasket.getDefaultShipment(),
22-
address,
23-
);
35+
AdyenHelper.getApplicableShippingMethods(shipment, address);
2436
res.json({
2537
shippingMethods: currentShippingMethodsModels,
2638
});

0 commit comments

Comments
 (0)