Skip to content

Commit c19f5af

Browse files
refactor(payment): PAYPAL-6433 hide shipping callbacks
1 parent 19c3f08 commit c19f5af

5 files changed

Lines changed: 42 additions & 6 deletions

File tree

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,33 @@ describe('PayPalCommerceCreditButtonStrategy', () => {
472472
});
473473
});
474474

475+
it('initializes PayPal button to render with shipping options when server side shipping callbacks disabled', async () => {
476+
const paymentMethodWithShippingOptionsFeature = {
477+
...paymentMethod,
478+
initializationData: {
479+
...paymentMethod.initializationData,
480+
isHostedCheckoutEnabled: true,
481+
isServerSideShippingCallbacksEnabled: false,
482+
},
483+
};
484+
485+
jest.spyOn(
486+
paymentIntegrationService.getState(),
487+
'getPaymentMethodOrThrow',
488+
).mockReturnValue(paymentMethodWithShippingOptionsFeature);
489+
490+
await strategy.initialize(initializationOptions);
491+
492+
expect(paypalSdk.Buttons).toHaveBeenCalledWith({
493+
fundingSource: paypalSdk.FUNDING.PAYLATER,
494+
style: paypalCommerceCreditOptions.style,
495+
createOrder: expect.any(Function),
496+
onApprove: expect.any(Function),
497+
onShippingAddressChange: expect.any(Function),
498+
onShippingOptionsChange: expect.any(Function),
499+
});
500+
});
501+
475502
it('renders PayPal button if it is eligible', async () => {
476503
const renderMock = jest.fn();
477504

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ export default class PayPalCommerceCreditButtonStrategy implements CheckoutButto
224224

225225
await this.paypalIntegrationService.submitPayment(methodId, data.orderID);
226226

227-
onComplete?.();
227+
if (onComplete && typeof onComplete === 'function') {
228+
onComplete();
229+
}
228230

229231
return true; // FIXME: Do we really need to return true here?
230232
} catch (error) {

packages/paypal-commerce-integration/src/paypal-commerce-credit/paypal-commerce-credit-customer-strategy.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ export default class PayPalCommerceCreditCustomerStrategy implements CustomerStr
220220
await this.paymentIntegrationService.submitOrder({}, { params: { methodId } });
221221
await this.paypalCommerceIntegrationService.submitPayment(methodId, data.orderID);
222222

223-
onComplete?.();
223+
if (onComplete && typeof onComplete === 'function') {
224+
onComplete();
225+
}
224226
} catch (error) {
225227
this.handleError(error);
226228
}

packages/paypal-utils/src/paypal-button-creation-service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ class PaypalButtonCreationService {
141141

142142
await this.paypalIntegrationService.submitPayment(methodId, data.orderID);
143143

144-
onComplete?.();
144+
if (onComplete && typeof onComplete === 'function') {
145+
onComplete();
146+
}
145147
} catch (error) {
146148
this.handleError(error);
147149
}

packages/paypal-utils/src/paypal-integration-service.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,20 @@ export default class PayPalIntegrationService {
138138
): Promise<void> {
139139
const state = this.paymentIntegrationService.getState();
140140
const cart = state.getCartOrThrow();
141-
const consignment = state.getConsignmentsOrThrow()[0];
141+
let consignment;
142+
if (!isServerSideShippingCallbacksEnabled) {
143+
consignment = state.getConsignmentsOrThrow()[0];
144+
}
142145

143146
try {
144147
await this.paypalRequestSender.updateOrder(providerId, {
145148
availableShippingOptions: isServerSideShippingCallbacksEnabled
146149
? []
147-
: consignment.availableShippingOptions,
150+
: consignment?.availableShippingOptions,
148151
cartId: cart.id,
149152
selectedShippingOption: isServerSideShippingCallbacksEnabled
150153
? null
151-
: consignment.selectedShippingOption,
154+
: consignment?.selectedShippingOption,
152155
...(methodId ? { methodId } : {}),
153156
...(orderId ? { orderId } : {}),
154157
});

0 commit comments

Comments
 (0)