@@ -88,7 +88,7 @@ export default class BigCommercePaymentsButtonStrategy implements CheckoutButton
8888 false ,
8989 ) ;
9090
91- this . renderButton ( containerId , methodId , bigcommerce_payments ) ;
91+ this . renderButton ( containerId , methodId , bigcommerce_payments , isBuyNowFlow ) ;
9292 }
9393
9494 deinitialize ( ) : Promise < void > {
@@ -99,6 +99,7 @@ export default class BigCommercePaymentsButtonStrategy implements CheckoutButton
9999 containerId : string ,
100100 methodId : string ,
101101 bigcommerce_payments : BigCommercePaymentsButtonInitializeOptions ,
102+ isBuyNowFlow ?: boolean ,
102103 ) : void {
103104 const { buyNowInitializeOptions, style, onComplete, onEligibilityFailure } =
104105 bigcommerce_payments ;
@@ -107,9 +108,14 @@ export default class BigCommercePaymentsButtonStrategy implements CheckoutButton
107108 const state = this . paymentIntegrationService . getState ( ) ;
108109 const paymentMethod =
109110 state . getPaymentMethodOrThrow < BigCommercePaymentsInitializationData > ( methodId ) ;
110- const { isHostedCheckoutEnabled } = paymentMethod . initializationData || { } ;
111+ const { isHostedCheckoutEnabled, isAppSwitchEnabled } =
112+ paymentMethod . initializationData || { } ;
111113
112114 const defaultCallbacks = {
115+ ...( ! isBuyNowFlow &&
116+ this . isPaypalCommerceAppSwitchEnabled ( methodId ) && {
117+ appSwitchWhenAvailable : true ,
118+ } ) ,
113119 createOrder : ( ) =>
114120 this . bigCommercePaymentsIntegrationService . createOrder ( 'bigcommerce_payments' ) ,
115121 onApprove : ( { orderID } : ApproveCallbackPayload ) =>
@@ -122,10 +128,12 @@ export default class BigCommercePaymentsButtonStrategy implements CheckoutButton
122128 } ;
123129
124130 const hostedCheckoutCallbacks = {
125- onShippingAddressChange : ( data : ShippingAddressChangeCallbackPayload ) =>
126- this . onShippingAddressChange ( data ) ,
127- onShippingOptionsChange : ( data : ShippingOptionChangeCallbackPayload ) =>
128- this . onShippingOptionsChange ( data ) ,
131+ ...( ! isAppSwitchEnabled && {
132+ onShippingAddressChange : ( data : ShippingAddressChangeCallbackPayload ) =>
133+ this . onShippingAddressChange ( data ) ,
134+ onShippingOptionsChange : ( data : ShippingOptionChangeCallbackPayload ) =>
135+ this . onShippingOptionsChange ( data ) ,
136+ } ) ,
129137 onApprove : ( data : ApproveCallbackPayload , actions : ApproveCallbackActions ) =>
130138 this . onHostedCheckoutApprove ( data , actions , methodId , onComplete ) ,
131139 } ;
@@ -141,7 +149,11 @@ export default class BigCommercePaymentsButtonStrategy implements CheckoutButton
141149 const paypalButton = paypalSdk . Buttons ( buttonRenderOptions ) ;
142150
143151 if ( paypalButton . isEligible ( ) ) {
144- paypalButton . render ( `#${ containerId } ` ) ;
152+ if ( paypalButton . hasReturned ?.( ) && this . isPaypalCommerceAppSwitchEnabled ( methodId ) ) {
153+ paypalButton . resume ?.( ) ;
154+ } else {
155+ paypalButton . render ( `#${ containerId } ` ) ;
156+ }
145157 } else if ( onEligibilityFailure && typeof onEligibilityFailure === 'function' ) {
146158 onEligibilityFailure ( ) ;
147159 } else {
@@ -259,4 +271,17 @@ export default class BigCommercePaymentsButtonStrategy implements CheckoutButton
259271 throw error ;
260272 }
261273 }
274+
275+ /**
276+ *
277+ * PayPal AppSwitch enabling handling
278+ *
279+ */
280+ private isPaypalCommerceAppSwitchEnabled ( methodId : string ) : boolean {
281+ const state = this . paymentIntegrationService . getState ( ) ;
282+ const paymentMethod =
283+ state . getPaymentMethodOrThrow < BigCommercePaymentsInitializationData > ( methodId ) ;
284+
285+ return paymentMethod . initializationData ?. isAppSwitchEnabled ?? false ;
286+ }
262287}
0 commit comments