Skip to content
Draft
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 @@ -360,6 +360,8 @@ export interface PayPalCommerceButtons {
render(id: string): void;
close(): void;
isEligible(): boolean;
hasReturned?(): boolean;
resume?(): void;
}

export interface PayPalCommerceButtonsOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ describe('PayPalCommerceButtonStrategy', () => {
await strategy.initialize(initializationOptions);

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

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

expect(paypalSdk.Buttons).toHaveBeenCalledWith({
appSwitchWhenAvailable: true,
fundingSource: paypalSdk.FUNDING.PAYPAL,
style: paypalCommerceOptions.style,
createOrder: expect.any(Function),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,14 @@ export default class PayPalCommerceButtonStrategy implements CheckoutButtonStrat
const { isHostedCheckoutEnabled } = paymentMethod.initializationData || {};

const defaultCallbacks = {
appSwitchWhenAvailable: true, // Need an indicator to trigger App Switch
createOrder: () => this.paypalCommerceIntegrationService.createOrder('paypalcommerce'),
onApprove: ({ orderID }: ApproveCallbackPayload) =>
this.paypalCommerceIntegrationService.tokenizePayment(methodId, orderID),
};

console.log('DEFAULT', defaultCallbacks);

const buyNowFlowCallbacks = {
onClick: () => this.handleClick(buyNowInitializeOptions),
onCancel: () => this.paymentIntegrationService.loadDefaultCheckout(),
Expand All @@ -134,7 +137,16 @@ export default class PayPalCommerceButtonStrategy implements CheckoutButtonStrat
const paypalButton = paypalSdk.Buttons(buttonRenderOptions);

if (paypalButton.isEligible()) {
paypalButton.render(`#${containerId}`);
// AppSwitch Flow
if (paypalButton?.hasReturned && paypalButton.hasReturned()) {
console.log('HAS RETURNED');
if (paypalButton.resume) {
paypalButton?.resume();
}
} else {
console.log('RENDER');
paypalButton.render(`#${containerId}`);
}
} else if (onEligibilityFailure && typeof onEligibilityFailure === 'function') {
onEligibilityFailure();
} else {
Expand Down