Skip to content

Commit

Permalink
One payment methods call for all express payments (#1211)
Browse files Browse the repository at this point in the history
* chore: comment invoking payment methods in cart
* chore: adapt all payment methods to use the payments method response
  • Loading branch information
amihajlovski authored Nov 12, 2024
1 parent 93b40af commit 9296108
Show file tree
Hide file tree
Showing 12 changed files with 469 additions and 458 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @jest-environment jsdom
*/
const applePayExpressModule = require('../applePayExpressCommon');
const applePayExpressModule = require('../applePayExpress');
const {
createApplePayButton,
initializeCheckout,
Expand All @@ -10,7 +10,7 @@ const {
onShippingContactSelected,
handleAuthorised,
handleError
} = require("../applePayExpressCommon");
} = require("../applePayExpress");

const APPLE_PAY = 'applepay';
const mockCreate = jest.fn();
Expand All @@ -25,7 +25,7 @@ let spy;
global.checkout = { create: mockCreate };
global.fetch = jest.fn();

jest.mock('../applePayExpressCommon', () => ({
jest.mock('../applePayExpress', () => ({
handleAuthorised: jest.fn(),
handleError: jest.fn(),
getPaymentMethods: jest.fn(),
Expand Down Expand Up @@ -763,6 +763,7 @@ describe('onShippingMethodSelected function', () => {
},
}),
};
global.fetch = jest.fn().mockResolvedValueOnce(mockCalculationResponse)
selectShippingMethod = jest.fn().mockImplementation((data, resolveApplePay) => {
return mockCalculationResponse
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
const {
callPaymentFromComponent,
saveShopperDetails,
redirectToReviewPage,
makeExpressPaymentDetailsCall,
updateComponent,
handleShippingAddressChange,
handleShippingOptionChange,
getPaypalButtonConfig,
mountPaypalComponent,
} = require('../paypalExpress.js')
const helpers = require('../adyen_checkout/helpers');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ const {
handleApplePayResponse,
callPaymentFromComponent,
formatCustomerObject,
} = require('../../applePayExpressCommon');

} = require('../../applePayExpress');

beforeEach(() => {
jest.clearAllMocks();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
const {
checkIfExpressMethodsAreReady,
updateLoadedExpressMethods,
getPaymentMethods,
} = require('./commons');
const { AMAZON_PAY } = require('./constants');

async function mountAmazonPayComponent() {
async function init(paymentMethodsResponse) {
try {
const paymentMethods = await getPaymentMethods();
const data = await paymentMethods.json();
const paymentMethodsResponse = data?.AdyenPaymentMethods;
const applicationInfo = data?.applicationInfo;
const applicationInfo = paymentMethodsResponse?.applicationInfo;
const checkout = await AdyenCheckout({
environment: window.environment,
clientKey: window.clientKey,
Expand All @@ -20,10 +16,15 @@ async function mountAmazonPayComponent() {
},
});

const amazonPayConfig = paymentMethodsResponse?.paymentMethods.find(
(pm) => pm.type === AMAZON_PAY,
)?.configuration;
if (!amazonPayConfig) return;
const amazonPayConfig =
paymentMethodsResponse?.AdyenPaymentMethods?.paymentMethods.find(
(pm) => pm.type === AMAZON_PAY,
)?.configuration;
if (!amazonPayConfig) {
updateLoadedExpressMethods(AMAZON_PAY);
checkIfExpressMethodsAreReady();
return;
}

const amazonPayButtonConfig = {
showPayButton: true,
Expand All @@ -42,4 +43,6 @@ async function mountAmazonPayComponent() {
}
}

mountAmazonPayComponent();
module.exports = {
init,
};
Loading

0 comments on commit 9296108

Please sign in to comment.