Skip to content

Commit 9822c32

Browse files
feat(payment): Added AppSwitch
1 parent 435b7f9 commit 9822c32

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

packages/paypal-commerce-integration/src/paypal-commerce-types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ export interface PayPalCommerceButtons {
360360
render(id: string): void;
361361
close(): void;
362362
isEligible(): boolean;
363+
hasReturned?(): boolean;
364+
resume?(): void;
363365
}
364366

365367
export interface PayPalCommerceButtonsOptions {

packages/paypal-commerce-integration/src/paypal-commerce/paypal-commerce-button-strategy.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ describe('PayPalCommerceButtonStrategy', () => {
371371
await strategy.initialize(initializationOptions);
372372

373373
expect(paypalSdk.Buttons).toHaveBeenCalledWith({
374+
appSwitchWhenAvailable: true,
374375
fundingSource: paypalSdk.FUNDING.PAYPAL,
375376
style: paypalCommerceOptions.style,
376377
createOrder: expect.any(Function),
@@ -382,6 +383,7 @@ describe('PayPalCommerceButtonStrategy', () => {
382383
await strategy.initialize(buyNowInitializationOptions);
383384

384385
expect(paypalSdk.Buttons).toHaveBeenCalledWith({
386+
appSwitchWhenAvailable: true,
385387
fundingSource: paypalSdk.FUNDING.PAYPAL,
386388
style: paypalCommerceOptions.style,
387389
createOrder: expect.any(Function),
@@ -408,6 +410,7 @@ describe('PayPalCommerceButtonStrategy', () => {
408410
await strategy.initialize(initializationOptions);
409411

410412
expect(paypalSdk.Buttons).toHaveBeenCalledWith({
413+
appSwitchWhenAvailable: true,
411414
fundingSource: paypalSdk.FUNDING.PAYPAL,
412415
style: paypalCommerceOptions.style,
413416
createOrder: expect.any(Function),

packages/paypal-commerce-integration/src/paypal-commerce/paypal-commerce-button-strategy.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export default class PayPalCommerceButtonStrategy implements CheckoutButtonStrat
104104
const { isHostedCheckoutEnabled } = paymentMethod.initializationData || {};
105105

106106
const defaultCallbacks = {
107+
appSwitchWhenAvailable: true, // Need an indicator to trigger App Switch
107108
createOrder: () => this.paypalCommerceIntegrationService.createOrder('paypalcommerce'),
108109
onApprove: ({ orderID }: ApproveCallbackPayload) =>
109110
this.paypalCommerceIntegrationService.tokenizePayment(methodId, orderID),
@@ -134,7 +135,14 @@ export default class PayPalCommerceButtonStrategy implements CheckoutButtonStrat
134135
const paypalButton = paypalSdk.Buttons(buttonRenderOptions);
135136

136137
if (paypalButton.isEligible()) {
137-
paypalButton.render(`#${containerId}`);
138+
// AppSwitch Flow
139+
if (paypalButton?.hasReturned && paypalButton.hasReturned()) {
140+
if (paypalButton.resume) {
141+
paypalButton?.resume();
142+
}
143+
} else {
144+
paypalButton.render(`#${containerId}`);
145+
}
138146
} else if (onEligibilityFailure && typeof onEligibilityFailure === 'function') {
139147
onEligibilityFailure();
140148
} else {

0 commit comments

Comments
 (0)