Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Pay - Throwing error when required config is missing #3179

Merged
merged 2 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/stale-days-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@adyen/adyen-web': patch
---

Google Pay - Throwing error in case the merchant id is missing
50 changes: 36 additions & 14 deletions packages/lib/src/components/GooglePay/GooglePay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('GooglePay', () => {
describe('onClick()', () => {
test('should not call "initiatePayment" if the onClick reject() is called', async () => {
const googlepay = new GooglePay(global.core, {
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
onClick(resolve, reject) {
reject();
}
Expand All @@ -73,6 +74,7 @@ describe('GooglePay', () => {

test('should call "initiatePayment" if the onClick resolve() is called', async () => {
const googlepay = new GooglePay(global.core, {
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
onClick(resolve) {
resolve();
}
Expand All @@ -89,16 +91,27 @@ describe('GooglePay', () => {

describe('isExpress flag', () => {
test('should add subtype: express when isExpress is configured', () => {
const googlepay = new GooglePay(global.core, { isExpress: true });
const googlepay = new GooglePay(global.core, {
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
isExpress: true
});
expect(googlepay.data.paymentMethod).toHaveProperty('subtype', 'express');
});
test('should not add subtype: express when isExpress is omitted', () => {
const googlepay = new GooglePay(global.core);
const googlepay = new GooglePay(global.core, {
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' }
});
expect(googlepay.data.paymentMethod).not.toHaveProperty('subtype', 'express');
});

test('should throw error when express callbacks are passed but isExpress flag is not set', () => {
expect(() => new GooglePay(global.core, { paymentDataCallbacks: { onPaymentDataChanged: jest.fn() } })).toThrow();
expect(
() =>
new GooglePay(global.core, {
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
paymentDataCallbacks: { onPaymentDataChanged: jest.fn() }
})
).toThrow();
});
});

Expand All @@ -112,6 +125,7 @@ describe('GooglePay', () => {
const onPaymentCompletedMock = jest.fn();

const gpay = new GooglePay(global.core, {
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
onSubmit: onSubmitMock,
onPaymentCompleted: onPaymentCompletedMock
});
Expand Down Expand Up @@ -176,6 +190,7 @@ describe('GooglePay', () => {
});

new GooglePay(global.core, {
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
onSubmit: onSubmitMock
});

Expand Down Expand Up @@ -214,6 +229,7 @@ describe('GooglePay', () => {
const onPaymentFailedMock = jest.fn();

const gpay = new GooglePay(global.core, {
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
i18n: global.i18n,
onSubmit: onSubmitMock,
onPaymentFailed: onPaymentFailedMock
Expand Down Expand Up @@ -256,6 +272,7 @@ describe('GooglePay', () => {
const onPaymentFailedMock = jest.fn();

const gpay = new GooglePay(global.core, {
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
i18n: global.i18n,
onSubmit: onSubmitMock,
onPaymentFailed: onPaymentFailedMock
Expand Down Expand Up @@ -338,7 +355,10 @@ describe('GooglePay', () => {

test('should provide GooglePay auth event and formatted data', () => {
const onAuthorizedMock = jest.fn();
new GooglePay(global.core, { onAuthorized: onAuthorizedMock });
new GooglePay(global.core, {
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
onAuthorized: onAuthorizedMock
});

// @ts-ignore GooglePayService is mocked
const onPaymentAuthorized = GooglePayService.mock.calls[0][1].onPaymentAuthorized;
Expand All @@ -354,6 +374,7 @@ describe('GooglePay', () => {
const onPaymentFailedMock = jest.fn();

new GooglePay(global.core, {
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
i18n: global.i18n,
onAuthorized: onAuthorizedMock,
onPaymentFailed: onPaymentFailedMock
Expand Down Expand Up @@ -383,6 +404,7 @@ describe('GooglePay', () => {
const onPaymentCompletedMock = jest.fn();

const gpay = new GooglePay(global.core, {
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
i18n: global.i18n,
onAuthorized: onAuthorizedMock,
onPaymentCompleted: onPaymentCompletedMock
Expand All @@ -399,7 +421,10 @@ describe('GooglePay', () => {
});

test('should make the payments call if onAuthorized is not provided', async () => {
const gpay = new GooglePay(global.core, { i18n: global.i18n });
const gpay = new GooglePay(global.core, {
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
i18n: global.i18n
});

const paymentCall = jest.spyOn(gpay as any, 'makePaymentsCall');

Expand All @@ -414,7 +439,7 @@ describe('GooglePay', () => {

describe('isAvailable()', () => {
test('should resolve if GooglePay is available', async () => {
const gpay = new GooglePay(global.core);
const gpay = new GooglePay(global.core, { configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' } });
gpay.isReadyToPay = jest.fn(() => {
return Promise.resolve({ result: true });
});
Expand All @@ -423,7 +448,7 @@ describe('GooglePay', () => {
});

test('should reject if is not available', async () => {
const gpay = new GooglePay(global.core);
const gpay = new GooglePay(global.core, { configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' } });
gpay.isReadyToPay = jest.fn(() => {
return Promise.resolve({ result: false });
});
Expand All @@ -432,7 +457,7 @@ describe('GooglePay', () => {
});

test('should reject if "paymentMethodPresent" is false', async () => {
const gpay = new GooglePay(global.core);
const gpay = new GooglePay(global.core, { configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' } });
gpay.isReadyToPay = jest.fn(() => {
return Promise.resolve({ result: true, paymentMethodPresent: false });
});
Expand All @@ -442,19 +467,15 @@ describe('GooglePay', () => {
});

describe('Process CA based configuration data', () => {
test('Retrieves default merchantId', () => {
const gpay = new GooglePay(global.core);
expect(gpay.props.configuration.merchantId).toEqual('');
});

test('Retrieves merchantId from configuration', () => {
const gpay = new GooglePay(global.core, { configuration: { merchantId: 'abcdef', gatewayMerchantId: 'TestMerchant' } });
expect(gpay.props.configuration.merchantId).toEqual('abcdef');
});

test('Retrieves merchantId from configuration', () => {
test('Retrieves merchantOrigin from configuration', () => {
const gpay = new GooglePay(global.core, {
configuration: {
merchantId: 'abcdef',
gatewayMerchantId: 'TestMerchant',
merchantOrigin: 'example.com'
}
Expand All @@ -476,6 +497,7 @@ describe('GooglePay', () => {
console.log = jest.fn(() => {});

gpay = new GooglePay(global.core, {
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
type: 'googlepay',
isInstantPayment: true,
modules: {
Expand Down
7 changes: 7 additions & 0 deletions packages/lib/src/components/GooglePay/GooglePay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ class GooglePay extends UIElement<GooglePayConfiguration> {
);
}

if (!this.props.configuration.merchantId) {
throw new AdyenCheckoutError(
'IMPLEMENTATION_ERROR',
'GooglePay - Missing merchantId. Please ensure the it is correctly configured in your customer area.'
);
}

this.googlePay = new GooglePayService(this.props.environment, {
...(isExpress && paymentDataCallbacks?.onPaymentDataChanged && { onPaymentDataChanged: paymentDataCallbacks.onPaymentDataChanged }),
onPaymentAuthorized: this.onPaymentAuthorized
Expand Down
Loading