Skip to content

Commit 3ad8d1a

Browse files
committed
feat(payment): headless wallet button integration service + paypal strategy
1 parent 9f81004 commit 3ad8d1a

File tree

6 files changed

+43
-1
lines changed

6 files changed

+43
-1
lines changed

packages/apple-pay-integration/src/apple-pay-button-strategy.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,18 @@ describe('ApplePayButtonStrategy', () => {
154154
).rejects.toThrow(MissingDataError);
155155
});
156156

157+
it('throws error if canMakePayments returns false', async () => {
158+
jest.spyOn(console, 'error').mockImplementation(jest.fn());
159+
160+
MockApplePaySession.canMakePayments = jest.fn().mockReturnValue(false);
161+
162+
await strategy.initialize(getApplePayButtonInitializationOptions());
163+
164+
expect(console.error).toHaveBeenCalled();
165+
166+
MockApplePaySession.canMakePayments = jest.fn().mockReturnValue(true);
167+
});
168+
157169
it('throws error when params object is empty', async () => {
158170
await expect(
159171
strategy.initialize({

packages/apple-pay-integration/src/apple-pay-button-strategy.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ export default class ApplePayButtonStrategy implements CheckoutButtonStrategy {
125125

126126
assertApplePayWindow(window);
127127

128+
if (!this._sessionFactory.canMakePayment()) {
129+
console.error('This device is not capable of making Apple Pay payments');
130+
131+
return;
132+
}
133+
128134
if (!methodId || !applepay) {
129135
throw new MissingDataError(MissingDataErrorType.MissingPaymentMethod);
130136
}

packages/apple-pay-integration/src/apple-pay-customer-strategy.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,18 @@ describe('ApplePayCustomerStrategy', () => {
157157
await expect(strategy.initialize({})).rejects.toThrow(MissingDataError);
158158
});
159159

160+
it('throws error if canMakePayments returns false', async () => {
161+
jest.spyOn(console, 'error').mockImplementation(jest.fn());
162+
163+
MockApplePaySession.canMakePayments = jest.fn().mockReturnValue(false);
164+
165+
await strategy.initialize(getApplePayCustomerInitializationOptions());
166+
167+
expect(console.error).toHaveBeenCalled();
168+
169+
MockApplePaySession.canMakePayments = jest.fn().mockReturnValue(true);
170+
});
171+
160172
it('sets up request for digital items', async () => {
161173
const cart = getCart();
162174

packages/apple-pay-integration/src/apple-pay-customer-strategy.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ export default class ApplePayCustomerStrategy implements CustomerStrategy {
9292

9393
assertApplePayWindow(window);
9494

95+
if (!this._sessionFactory.canMakePayment()) {
96+
console.error('This device is not capable of making Apple Pay payments');
97+
98+
return;
99+
}
100+
95101
try {
96102
this._paymentMethod = state.getPaymentMethodOrThrow(methodId);
97103
} catch (_e) {

packages/apple-pay-integration/src/apple-pay-session-factory.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,10 @@ export default class ApplePaySessionFactory {
1818

1919
return new ApplePaySession(1, request);
2020
}
21+
22+
canMakePayment(): boolean {
23+
assertApplePayWindow(window);
24+
25+
return ApplePaySession.canMakePayments();
26+
}
2127
}

packages/apple-pay-integration/src/mocks/apple-pay-payment.mock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export class MockApplePaySession {
22
static supportsVersion: () => boolean;
3-
static canMakePayments: () => boolean;
3+
static canMakePayments: () => boolean = jest.fn().mockReturnValue(true);
44

55
addEventListener = jest.fn();
66
dispatchEvent = jest.fn();

0 commit comments

Comments
 (0)