Skip to content

Commit 9c8e772

Browse files
committed
feat(checkout): CHECKOUT-9388 Lazy load customer strategies
1 parent 942e132 commit 9c8e772

File tree

27 files changed

+177
-13
lines changed

27 files changed

+177
-13
lines changed

packages/amazon-pay-v2-integration/src/AmazonPayV2Button.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { createAmazonPayV2CustomerStrategy } from '@bigcommerce/checkout-sdk/integrations';
12
import React, { FunctionComponent, useEffect } from 'react';
23

34
import { CheckoutButton } from '@bigcommerce/checkout/checkout-button-integration';
@@ -35,7 +36,7 @@ const AmazonPayV2Button: FunctionComponent<CheckoutButtonProps> = (props) => {
3536

3637
return (
3738
<div className="AmazonPayContainer">
38-
<CheckoutButton {...props} />
39+
<CheckoutButton {...props} integrations={[createAmazonPayV2CustomerStrategy]} />
3940
</div>
4041
);
4142
};

packages/bigcommerce-payments-integration/src/BigCommercePayments/BigCommercePaymentsButton.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
createCheckoutService,
55
createLanguageService,
66
} from '@bigcommerce/checkout-sdk';
7+
import { createBigCommercePaymentsCustomerStrategy } from '@bigcommerce/checkout-sdk/integrations';
78
import React from 'react';
89

910
import { CheckoutButtonProps } from '@bigcommerce/checkout/payment-integration-api';
@@ -39,6 +40,7 @@ describe('BigCommercePaymentsButton', () => {
3940

4041
expect(checkoutService.initializeCustomer).toHaveBeenCalledWith({
4142
methodId: defaultProps.methodId,
43+
integrations: [createBigCommercePaymentsCustomerStrategy],
4244
bigcommerce_payments: {
4345
container: 'bigcommerce-payments-button-container',
4446
onClick: expect.any(Function),

packages/bigcommerce-payments-integration/src/BigCommercePayments/BigCommercePaymentsButton.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { createBigCommercePaymentsCustomerStrategy } from '@bigcommerce/checkout-sdk/integrations';
12
import React, { FunctionComponent } from 'react';
23

34
import { CheckoutButton } from '@bigcommerce/checkout/checkout-button-integration';
@@ -18,6 +19,7 @@ const BigCommercePaymentsButton: FunctionComponent<CheckoutButtonProps> = (props
1819
<CheckoutButton
1920
additionalInitializationOptions={additionalInitializationOptions}
2021
{...props}
22+
integrations={[createBigCommercePaymentsCustomerStrategy]}
2123
/>
2224
);
2325
};

packages/bigcommerce-payments-integration/src/BigCommercePaymentsPayLater/BigcommercePaymentsPayLaterButton.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
createCheckoutService,
55
createLanguageService,
66
} from '@bigcommerce/checkout-sdk';
7+
import { createBigCommercePaymentsPayLaterCustomerStrategy } from '@bigcommerce/checkout-sdk/integrations';
78
import React from 'react';
89

910
import { CheckoutButtonProps } from '@bigcommerce/checkout/payment-integration-api';
@@ -39,6 +40,7 @@ describe('BigcommercePaymentsPayLaterButton', () => {
3940

4041
expect(checkoutService.initializeCustomer).toHaveBeenCalledWith({
4142
methodId: defaultProps.methodId,
43+
integrations: [createBigCommercePaymentsPayLaterCustomerStrategy],
4244
bigcommerce_payments_paylater: {
4345
container: 'bigcommerce-payments-paylater-button-container',
4446
onClick: expect.any(Function),

packages/bigcommerce-payments-integration/src/BigCommercePaymentsPayLater/BigcommercePaymentsPayLaterButton.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { createBigCommercePaymentsPayLaterCustomerStrategy } from '@bigcommerce/checkout-sdk/integrations';
12
import React, { FunctionComponent } from 'react';
23

34
import { CheckoutButton } from '@bigcommerce/checkout/checkout-button-integration';
@@ -18,6 +19,7 @@ const BigcommercePaymentsPayLaterButton: FunctionComponent<CheckoutButtonProps>
1819
<CheckoutButton
1920
additionalInitializationOptions={additionalInitializationOptions}
2021
{...props}
22+
integrations={[createBigCommercePaymentsPayLaterCustomerStrategy]}
2123
/>
2224
);
2325
};

packages/bolt-integration/src/BoltEmbeddedPaymentMethod.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { createBoltPaymentStrategy } from '@bigcommerce/checkout-sdk/integrations';
1+
import { CustomerInitializeOptions } from '@bigcommerce/checkout-sdk';
2+
import {
3+
createBoltCustomerStrategy,
4+
createBoltPaymentStrategy,
5+
} from '@bigcommerce/checkout-sdk/integrations';
26
import React, { FunctionComponent, useCallback, useState } from 'react';
37

48
import { HostedWidgetPaymentComponent } from '@bigcommerce/checkout/hosted-widget-integration';
@@ -49,6 +53,16 @@ const BoltEmbeddedPaymentMethod: FunctionComponent<PaymentMethodProps> = ({
4953
[checkoutService, boltEmbeddedContainerId, setFieldValue],
5054
);
5155

56+
const initializeBoltCustomer = useCallback(
57+
(options: CustomerInitializeOptions) => {
58+
return checkoutService.initializeCustomer({
59+
...options,
60+
integrations: [createBoltCustomerStrategy],
61+
});
62+
},
63+
[checkoutService],
64+
);
65+
5266
const renderCustomPaymentForm = useCallback(
5367
() => (
5468
<BoltCustomForm
@@ -73,6 +87,7 @@ const BoltEmbeddedPaymentMethod: FunctionComponent<PaymentMethodProps> = ({
7387
deinitializePayment={checkoutService.deinitializePayment}
7488
disableSubmit={disableSubmit}
7589
hidePaymentSubmitButton={hidePaymentSubmitButton}
90+
initializeCustomer={initializeBoltCustomer}
7691
initializePayment={initializeBoltPayment}
7792
instruments={instruments}
7893
isInitializing={isInitializingPayment()}

packages/checkout-button-integration/src/CheckoutButton.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ const CheckoutButton: FunctionComponent<CheckoutButtonProps> = ({
1414
onUnhandledError,
1515
onWalletButtonClick,
1616
additionalInitializationOptions,
17+
integrations,
1718
}) => {
1819
const initializeCustomerStrategyOrThrow = async () => {
1920
try {
2021
await initializeCustomer({
2122
methodId,
23+
integrations,
2224
[methodId]: {
2325
container: containerId,
2426
onUnhandledError,

packages/core/src/app/customer/CheckoutButtonContainer.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CheckoutSelectors, CheckoutService } from '@bigcommerce/checkout-sdk';
22
import classNames from 'classnames';
3-
import React, { FunctionComponent, memo } from 'react';
3+
import React, { FunctionComponent, lazy, memo } from 'react';
44

55
import { TranslatedString, useLocale } from '@bigcommerce/checkout/locale';
66
import { CheckoutContextProps , useStyleContext } from '@bigcommerce/checkout/payment-integration-api';
@@ -10,7 +10,8 @@ import { withCheckout } from '../checkout';
1010

1111
import { getSupportedMethodIds } from './getSupportedMethods';
1212
import resolveCheckoutButton from './resolveCheckoutButton';
13-
import CheckoutButtonV1Resolver from './WalletButtonV1Resolver';
13+
14+
const CheckoutButtonV1Resolver = lazy(() => import(/* webpackChunkName: "wallet-button-v1-resolver" */'./WalletButtonV1Resolver'));
1415

1516
interface CheckoutButtonContainerProps {
1617
isPaymentStepActive: boolean;

packages/core/src/app/customer/CheckoutButtonList.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
CustomerRequestOptions,
77
} from '@bigcommerce/checkout-sdk';
88
import { noop } from 'lodash';
9-
import React, { FunctionComponent, memo } from 'react';
9+
import React, { FunctionComponent, lazy, memo } from 'react';
1010

1111
import { TranslatedString, useLocale } from '@bigcommerce/checkout/locale';
1212
import { CheckoutContextProps } from '@bigcommerce/checkout/payment-integration-api';
@@ -16,8 +16,8 @@ import { withCheckout } from '../checkout';
1616

1717
import { getSupportedMethodIds } from './getSupportedMethods';
1818
import resolveCheckoutButton from './resolveCheckoutButton';
19-
import CheckoutButtonV1Resolver from './WalletButtonV1Resolver';
20-
import { LazyContainer } from '@bigcommerce/checkout/ui';
19+
20+
const CheckoutButtonV1Resolver = lazy(() => import(/* webpackChunkName: "wallet-button-v1-resolver" */'./WalletButtonV1Resolver'));
2121

2222
export interface CheckoutButtonListProps {
2323
checkoutSettings: CheckoutSettings;

packages/core/src/app/customer/Customer.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
SignInEmail,
1212
StoreConfig,
1313
} from '@bigcommerce/checkout-sdk';
14+
import { createBigCommercePaymentsFastlaneCustomerStrategy, createBoltCustomerStrategy, createBraintreeFastlaneCustomerStrategy, createPayPalCommerceFastlaneCustomerStrategy, createStripeLinkV2CustomerStrategy, createStripeUPECustomerStrategy } from '@bigcommerce/checkout-sdk/integrations';
1415
import { noop } from 'lodash';
1516
import React, { Component, ReactNode } from 'react';
1617

@@ -128,7 +129,18 @@ class Customer extends Component<CustomerProps & WithCheckoutCustomerProps & Ana
128129

129130
try {
130131
if (providerWithCustomCheckout && providerWithCustomCheckout !== PaymentMethodId.StripeUPE) {
131-
await initializeCustomer({methodId: providerWithCustomCheckout});
132+
// TODO: Split out into separate chunks so they can be lazy loaded
133+
await initializeCustomer({
134+
methodId: providerWithCustomCheckout,
135+
integrations: [
136+
createBigCommercePaymentsFastlaneCustomerStrategy,
137+
createBraintreeFastlaneCustomerStrategy,
138+
createPayPalCommerceFastlaneCustomerStrategy,
139+
createBoltCustomerStrategy,
140+
createStripeUPECustomerStrategy,
141+
createStripeLinkV2CustomerStrategy,
142+
],
143+
});
132144
}
133145
} catch (error) {
134146
onUnhandledError(error);

0 commit comments

Comments
 (0)