Skip to content

Commit 7aaca5c

Browse files
authored
fix: c2p customer email is set from basket (#1178)
1 parent 6545aa5 commit 7aaca5c

5 files changed

Lines changed: 17 additions & 11 deletions

File tree

src/cartridges/app_adyen_SFRA/cartridge/client/default/js/adyen_checkout/__tests__/checkoutConfiguration.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ beforeEach(() => {
2929
querySelector = document.querySelector;
3030
window.Configuration = { environment: 'TEST' };
3131
window.klarnaWidgetEnabled = true;
32+
window.merchantAccount = 'test_merchant';
33+
window.customerEmail = 'test@email.com';
3234
store.checkoutConfiguration = {};
3335
setCheckoutConfiguration()
3436
card = getCardConfig();
@@ -49,6 +51,8 @@ describe('Checkout Configuration', () => {
4951
const data = { paymentMethod: { type: 'scheme' } };
5052
card.onChange({ isValid: true, data }, { props: { holderName: 'test' } });
5153
expect(store.selectedPayment.isValid).toBeTruthy();
54+
expect(card.clickToPayConfiguration.shopperEmail).toBe(window.customerEmail);
55+
expect(card.clickToPayConfiguration.merchantDisplayName).toBe(window.merchantAccount);
5256
});
5357

5458
it('handles onFieldValid', () => {

src/cartridges/app_adyen_SFRA/cartridge/client/default/js/adyen_checkout/checkoutConfiguration.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,8 @@ function getGiftCardConfig() {
202202
async: false,
203203
success: (data) => {
204204
giftcardBalance = data.balance;
205-
document.querySelector(
206-
'button[value="submit-payment"]',
207-
).disabled = false;
205+
document.querySelector('button[value="submit-payment"]').disabled =
206+
false;
208207
if (data.resultCode === constants.SUCCESS) {
209208
const {
210209
giftCardsInfoMessageContainer,
@@ -230,9 +229,8 @@ function getGiftCardConfig() {
230229
initialPartialObject.totalDiscountedAmount;
231230
});
232231

233-
document.querySelector(
234-
'button[value="submit-payment"]',
235-
).disabled = true;
232+
document.querySelector('button[value="submit-payment"]').disabled =
233+
true;
236234
giftCardsInfoMessageContainer.innerHTML = '';
237235
giftCardsInfoMessageContainer.classList.remove(
238236
'gift-cards-info-message-container',

src/cartridges/app_adyen_SFRA/cartridge/client/default/js/adyen_checkout/renderGiftcardComponent.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,8 @@ function removeGiftCards() {
9898
giftCardsInfoMessageContainer.classList.remove(
9999
'gift-cards-info-message-container',
100100
);
101-
document.querySelector(
102-
'button[value="submit-payment"]',
103-
).disabled = false;
101+
document.querySelector('button[value="submit-payment"]').disabled =
102+
false;
104103

105104
if (res.resultCode === constants.RECEIVED) {
106105
document

src/cartridges/app_adyen_SFRA/cartridge/templates/default/checkout/billing/adyenComponentForm.isml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
window.installments = '${pdict.adyen.installments}';
6060
window.googleMerchantID = '${pdict.adyen.googleMerchantID}';
6161
window.merchantAccount = '${pdict.adyen.merchantAccount}';
62-
window.customerEmail = '${customer && customer.profile && customer.profile.email ? customer.profile.email : ''}';
62+
window.customerEmail = '${pdict.AdyenHelper.getCustomerEmail()}';
6363
var showStoreDetails = ${customer.authenticated && adyenRecurringPaymentsEnabled};
6464
</script>
6565

src/cartridges/int_adyen_SFRA/cartridge/adyen/utils/adyenHelper.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const StringUtils = require('dw/util/StringUtils');
3131
const Money = require('dw/value/Money');
3232
const TaxMgr = require('dw/order/TaxMgr');
3333
const ShippingLocation = require('dw/order/ShippingLocation');
34+
const BasketMgr = require('dw/order/BasketMgr');
3435
//script includes
3536
const ShippingMethodModel = require('*/cartridge/models/shipping/shippingMethod');
3637
const collections = require('*/cartridge/scripts/util/collections');
@@ -299,7 +300,6 @@ let adyenHelperObj = {
299300
},
300301

301302
getBasketAmount() {
302-
const BasketMgr = require('dw/order/BasketMgr');
303303
const currentBasket = BasketMgr.getCurrentBasket();
304304
if(!currentBasket) {
305305
return;
@@ -313,6 +313,11 @@ let adyenHelperObj = {
313313
return JSON.stringify(amount);
314314
},
315315

316+
getCustomerEmail() {
317+
const currentBasket = BasketMgr.getCurrentBasket();
318+
return currentBasket ? currentBasket.customerEmail : '';
319+
},
320+
316321
// returns an array containing the donation amounts configured in the custom preferences for Adyen Giving
317322
getDonationAmounts() {
318323
let returnValue = [];

0 commit comments

Comments
 (0)