From dbb8b14c88ae4e2479a62b780a659c76e97defe9 Mon Sep 17 00:00:00 2001 From: Zenit Shkreli <69572953+zenit2001@users.noreply.github.com> Date: Fri, 8 Dec 2023 14:41:39 +0100 Subject: [PATCH] fix: enabled adyen giving for apple pay payments --- .../cartridge/client/default/js/applePayExpress.js | 2 ++ .../int_adyen_overlay/cartridge/scripts/adyenGiving.js | 6 +++++- .../int_adyen_overlay/cartridge/scripts/util/adyenHelper.js | 4 ++-- tests/playwright/fixtures/USD.spec.mjs | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/cartridges/int_adyen_SFRA/cartridge/client/default/js/applePayExpress.js b/src/cartridges/int_adyen_SFRA/cartridge/client/default/js/applePayExpress.js index f8f51ae72..bf99bab0b 100644 --- a/src/cartridges/int_adyen_SFRA/cartridge/client/default/js/applePayExpress.js +++ b/src/cartridges/int_adyen_SFRA/cartridge/client/default/js/applePayExpress.js @@ -81,6 +81,8 @@ function handleAuthorised(response, resolveApplePay) { paymentMethod: response.fullResponse?.paymentMethod ? response.fullResponse.paymentMethod : response.fullResponse?.additionalData?.paymentMethod, + donationToken: response.fullResponse?.donationToken, + amount: response.fullResponse?.amount, }); document.querySelector('#showConfirmationForm').submit(); } diff --git a/src/cartridges/int_adyen_overlay/cartridge/scripts/adyenGiving.js b/src/cartridges/int_adyen_overlay/cartridge/scripts/adyenGiving.js index b4c4bd60b..9197b386d 100644 --- a/src/cartridges/int_adyen_overlay/cartridge/scripts/adyenGiving.js +++ b/src/cartridges/int_adyen_overlay/cartridge/scripts/adyenGiving.js @@ -44,12 +44,16 @@ function donate(donationReference, donationAmount, orderToken) { const paymentData = JSON.parse(paymentInstrument.paymentTransaction.custom.Adyen_log); const paymentCurrency = paymentData.amount.currency; const availableDonationAmounts = AdyenHelper.getDonationAmounts(); - paymentMethodVariant = paymentInstrument.custom.Adyen_Payment_Method_Variant; + paymentMethodVariant = paymentData.paymentMethod?.type || paymentData.fullResponse?.paymentMethod?.type; // for iDeal donations, the payment method variant needs to be set to sepadirectdebit if (paymentMethodVariant === 'ideal') { paymentMethodVariant = 'sepadirectdebit'; } + // for Apple Pay donations, the payment method variant needs to be the brand + if (paymentMethodVariant === 'applepay'){ + paymentMethodVariant = paymentData.paymentMethod?.brand || paymentData.fullResponse?.paymentMethod?.brand; + } const requestObject = { merchantAccount: AdyenConfigs.getAdyenMerchantAccount(), donationAccount: AdyenConfigs.getAdyenGivingCharityAccount(), diff --git a/src/cartridges/int_adyen_overlay/cartridge/scripts/util/adyenHelper.js b/src/cartridges/int_adyen_overlay/cartridge/scripts/util/adyenHelper.js index fb04116ac..c68b412a5 100644 --- a/src/cartridges/int_adyen_overlay/cartridge/scripts/util/adyenHelper.js +++ b/src/cartridges/int_adyen_overlay/cartridge/scripts/util/adyenHelper.js @@ -683,8 +683,8 @@ var adyenHelperObj = { ? result.resultCode : ''; order.custom.Adyen_value = '0'; - if (result.donationToken){ - paymentInstrument.paymentTransaction.custom.Adyen_donationToken = result.donationToken; + if (result.donationToken || result.fullResponse?.donationToken){ + paymentInstrument.paymentTransaction.custom.Adyen_donationToken = result.donationToken || result.fullResponse.donationToken; } // Save full response to transaction custom attribute paymentInstrument.paymentTransaction.custom.Adyen_log = JSON.stringify( diff --git a/tests/playwright/fixtures/USD.spec.mjs b/tests/playwright/fixtures/USD.spec.mjs index eb781fa46..2c0963186 100644 --- a/tests/playwright/fixtures/USD.spec.mjs +++ b/tests/playwright/fixtures/USD.spec.mjs @@ -56,7 +56,7 @@ for (const environment of environments) { await checkoutPage.expectRefusal(); }); - test('Card payment no 3DS with adyen giving donation success', async () => { + test('Card payment no 3DS with adyen giving donation success @quick', async () => { await cards.doCardPayment(cardData.noThreeDs); await checkoutPage.completeCheckout(); await checkoutPage.makeSuccessfulDonation();