Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ describe('ApplePayButtonStrategy', () => {
).rejects.toThrow(MissingDataError);
});

it('throws error if canMakePayments returns false', async () => {
jest.spyOn(console, 'error').mockImplementation(jest.fn());

MockApplePaySession.canMakePayments = jest.fn().mockReturnValue(false);

await strategy.initialize(getApplePayButtonInitializationOptions());

expect(console.error).toHaveBeenCalled();

MockApplePaySession.canMakePayments = jest.fn().mockReturnValue(true);
});

it('throws error when params object is empty', async () => {
await expect(
strategy.initialize({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ export default class ApplePayButtonStrategy implements CheckoutButtonStrategy {

assertApplePayWindow(window);

if (!this._sessionFactory.canMakePayment()) {
console.error('This device is not capable of making Apple Pay payments');

return;
}

if (!methodId || !applepay) {
throw new MissingDataError(MissingDataErrorType.MissingPaymentMethod);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,18 @@ describe('ApplePayCustomerStrategy', () => {
await expect(strategy.initialize({})).rejects.toThrow(MissingDataError);
});

it('throws error if canMakePayments returns false', async () => {
jest.spyOn(console, 'error').mockImplementation(jest.fn());

MockApplePaySession.canMakePayments = jest.fn().mockReturnValue(false);

await strategy.initialize(getApplePayCustomerInitializationOptions());

expect(console.error).toHaveBeenCalled();

MockApplePaySession.canMakePayments = jest.fn().mockReturnValue(true);
});

it('sets up request for digital items', async () => {
const cart = getCart();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ export default class ApplePayCustomerStrategy implements CustomerStrategy {

assertApplePayWindow(window);

if (!this._sessionFactory.canMakePayment()) {
console.error('This device is not capable of making Apple Pay payments');

return;
}

try {
this._paymentMethod = state.getPaymentMethodOrThrow(methodId);
} catch (_e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ export default class ApplePaySessionFactory {

return new ApplePaySession(1, request);
}

canMakePayment(): boolean {
assertApplePayWindow(window);

return ApplePaySession.canMakePayments();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export class MockApplePaySession {
static supportsVersion: () => boolean;
static canMakePayments: () => boolean;
static canMakePayments: () => boolean = jest.fn().mockReturnValue(true);

addEventListener = jest.fn();
dispatchEvent = jest.fn();
Expand Down