Skip to content

Commit e5e9dae

Browse files
committed
feat(payment): PAYPAL-5760 Update PayPalCommerceFastlaneCustomerStrategy using paypal-utils package
1 parent 3f3ebb7 commit e5e9dae

File tree

3 files changed

+38
-42
lines changed

3 files changed

+38
-42
lines changed

packages/paypal-commerce-integration/src/paypal-commerce-fastlane/create-paypal-commerce-fastlane-customer-strategy.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import {
33
toResolvableModule,
44
} from '@bigcommerce/checkout-sdk/payment-integration-api';
55
import {
6-
createPayPalCommerceFastlaneUtils,
7-
createPayPalCommerceSdk,
8-
} from '@bigcommerce/checkout-sdk/paypal-commerce-utils';
6+
createPayPalFastlaneUtils,
7+
createPayPalSdkScriptLoader,
8+
} from '@bigcommerce/checkout-sdk/paypal-utils';
99

1010
import PayPalCommerceFastlaneCustomerStrategy from './paypal-commerce-fastlane-customer-strategy';
1111

@@ -14,8 +14,8 @@ const createPayPalCommerceFastlaneCustomerStrategy: CustomerStrategyFactory<
1414
> = (paymentIntegrationService) =>
1515
new PayPalCommerceFastlaneCustomerStrategy(
1616
paymentIntegrationService,
17-
createPayPalCommerceSdk(),
18-
createPayPalCommerceFastlaneUtils(),
17+
createPayPalSdkScriptLoader(),
18+
createPayPalFastlaneUtils(),
1919
);
2020

2121
export default toResolvableModule(createPayPalCommerceFastlaneCustomerStrategy, [

packages/paypal-commerce-integration/src/paypal-commerce-fastlane/paypal-commerce-fastlane-customer-strategy.spec.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@ import {
1414
PaymentIntegrationServiceMock,
1515
} from '@bigcommerce/checkout-sdk/payment-integrations-test-utils';
1616
import {
17-
createPayPalCommerceFastlaneUtils,
18-
createPayPalCommerceSdk,
19-
getPayPalCommerceAcceleratedCheckoutPaymentMethod,
17+
createPayPalFastlaneUtils,
18+
createPayPalSdkScriptLoader,
19+
getPayPalAcceleratedCheckoutPaymentMethod,
2020
getPayPalFastlaneSdk,
21-
PayPalCommerceFastlaneUtils,
22-
PayPalCommerceSdk,
2321
PayPalFastlaneAuthenticationState,
2422
PayPalFastlaneSdk,
25-
} from '@bigcommerce/checkout-sdk/paypal-commerce-utils';
23+
PayPalFastlaneUtils,
24+
PayPalSdkScriptLoader,
25+
} from '@bigcommerce/checkout-sdk/paypal-utils';
2626

2727
import PayPalCommerceFastlaneCustomerStrategy from './paypal-commerce-fastlane-customer-strategy';
2828

2929
describe('PayPalCommerceFastlaneCustomerStrategy', () => {
3030
let paymentIntegrationService: PaymentIntegrationService;
3131
let paymentMethod: PaymentMethod;
32-
let paypalCommerceFastlaneUtils: PayPalCommerceFastlaneUtils;
33-
let paypalCommerceSdk: PayPalCommerceSdk;
32+
let paypalCommerceFastlaneUtils: PayPalFastlaneUtils;
33+
let paypalSdkScriptLoader: PayPalSdkScriptLoader;
3434
let paypalFastlaneSdk: PayPalFastlaneSdk;
3535
let strategy: PayPalCommerceFastlaneCustomerStrategy;
3636

@@ -155,16 +155,16 @@ describe('PayPalCommerceFastlaneCustomerStrategy', () => {
155155
};
156156

157157
beforeEach(() => {
158-
paymentMethod = getPayPalCommerceAcceleratedCheckoutPaymentMethod();
158+
paymentMethod = getPayPalAcceleratedCheckoutPaymentMethod();
159159
paypalFastlaneSdk = getPayPalFastlaneSdk();
160160

161161
paymentIntegrationService = new PaymentIntegrationServiceMock();
162-
paypalCommerceSdk = createPayPalCommerceSdk();
163-
paypalCommerceFastlaneUtils = createPayPalCommerceFastlaneUtils();
162+
paypalSdkScriptLoader = createPayPalSdkScriptLoader();
163+
paypalCommerceFastlaneUtils = createPayPalFastlaneUtils();
164164

165165
strategy = new PayPalCommerceFastlaneCustomerStrategy(
166166
paymentIntegrationService,
167-
paypalCommerceSdk,
167+
paypalSdkScriptLoader,
168168
paypalCommerceFastlaneUtils,
169169
);
170170

@@ -183,7 +183,7 @@ describe('PayPalCommerceFastlaneCustomerStrategy', () => {
183183
jest.spyOn(state, 'getBillingAddress').mockReturnValue(getBillingAddress());
184184
jest.spyOn(state, 'getStoreConfigOrThrow').mockReturnValue(storeConfig);
185185

186-
jest.spyOn(paypalCommerceSdk, 'getPayPalFastlaneSdk').mockImplementation(() =>
186+
jest.spyOn(paypalSdkScriptLoader, 'getPayPalFastlaneSdk').mockImplementation(() =>
187187
Promise.resolve(paypalFastlaneSdk),
188188
);
189189
jest.spyOn(paypalCommerceFastlaneUtils, 'initializePayPalFastlane');
@@ -297,7 +297,7 @@ describe('PayPalCommerceFastlaneCustomerStrategy', () => {
297297
it('loads paypal sdk and initialises paypal fastlane in production mode', async () => {
298298
await strategy.initialize(initializationOptions);
299299

300-
expect(paypalCommerceSdk.getPayPalFastlaneSdk).toHaveBeenCalledWith(
300+
expect(paypalSdkScriptLoader.getPayPalFastlaneSdk).toHaveBeenCalledWith(
301301
paymentMethod,
302302
cart.currency.code,
303303
cart.id,
@@ -320,7 +320,7 @@ describe('PayPalCommerceFastlaneCustomerStrategy', () => {
320320

321321
await strategy.initialize(initializationOptions);
322322

323-
expect(paypalCommerceSdk.getPayPalFastlaneSdk).toHaveBeenCalledWith(
323+
expect(paypalSdkScriptLoader.getPayPalFastlaneSdk).toHaveBeenCalledWith(
324324
paymentMethod,
325325
cart.currency.code,
326326
cart.id,
@@ -342,13 +342,13 @@ describe('PayPalCommerceFastlaneCustomerStrategy', () => {
342342
'getPaymentMethodOrThrow',
343343
).mockReturnValue(paymentMethod);
344344

345-
jest.spyOn(paypalCommerceSdk, 'getPayPalFastlaneSdk').mockImplementation(() =>
345+
jest.spyOn(paypalSdkScriptLoader, 'getPayPalFastlaneSdk').mockImplementation(() =>
346346
Promise.reject(),
347347
);
348348

349349
await strategy.initialize(initializationOptions);
350350

351-
expect(paypalCommerceSdk.getPayPalFastlaneSdk).toHaveBeenCalled();
351+
expect(paypalSdkScriptLoader.getPayPalFastlaneSdk).toHaveBeenCalled();
352352
expect(paypalCommerceFastlaneUtils.initializePayPalFastlane).not.toHaveBeenCalled();
353353
});
354354
});

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

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import {
99
} from '@bigcommerce/checkout-sdk/payment-integration-api';
1010
import {
1111
getFastlaneStyles,
12-
PayPalCommerceFastlaneUtils,
13-
PayPalCommerceInitializationData,
14-
PayPalCommerceSdk,
1512
PayPalFastlaneAuthenticationResult,
1613
PayPalFastlaneAuthenticationState,
1714
PayPalFastlaneStylesOption,
18-
} from '@bigcommerce/checkout-sdk/paypal-commerce-utils';
15+
PayPalFastlaneUtils,
16+
PayPalInitializationData,
17+
PayPalSdkScriptLoader,
18+
} from '@bigcommerce/checkout-sdk/paypal-utils';
1919

2020
import PayPalCommerceFastlaneCustomerInitializeOptions, {
2121
WithPayPalCommerceFastlaneCustomerInitializeOptions,
@@ -24,8 +24,8 @@ import PayPalCommerceFastlaneCustomerInitializeOptions, {
2424
export default class PayPalCommerceFastlaneCustomerStrategy implements CustomerStrategy {
2525
constructor(
2626
private paymentIntegrationService: PaymentIntegrationService,
27-
private paypalCommerceSdk: PayPalCommerceSdk,
28-
private paypalCommerceFastlaneUtils: PayPalCommerceFastlaneUtils,
27+
private paypalSdkScriptLoader: PayPalSdkScriptLoader,
28+
private paypalFastlaneUtils: PayPalFastlaneUtils,
2929
) {}
3030

3131
async initialize(
@@ -44,18 +44,17 @@ export default class PayPalCommerceFastlaneCustomerStrategy implements CustomerS
4444

4545
const state = this.paymentIntegrationService.getState();
4646
const cart = state.getCartOrThrow();
47-
const paymentMethod =
48-
state.getPaymentMethodOrThrow<PayPalCommerceInitializationData>(methodId);
47+
const paymentMethod = state.getPaymentMethodOrThrow<PayPalInitializationData>(methodId);
4948

5049
const isTestModeEnabled = !!paymentMethod.initializationData?.isDeveloperModeApplicable;
5150

52-
const paypalFastlaneSdk = await this.paypalCommerceSdk.getPayPalFastlaneSdk(
51+
const paypalFastlaneSdk = await this.paypalSdkScriptLoader.getPayPalFastlaneSdk(
5352
paymentMethod,
5453
cart.currency.code,
5554
cart.id,
5655
);
5756

58-
await this.paypalCommerceFastlaneUtils.initializePayPalFastlane(
57+
await this.paypalFastlaneUtils.initializePayPalFastlane(
5958
paypalFastlaneSdk,
6059
isTestModeEnabled,
6160
this.getFastlaneStyles(methodId, paypalcommercefastlane),
@@ -132,24 +131,22 @@ export default class PayPalCommerceFastlaneCustomerStrategy implements CustomerS
132131
const billingAddress = state.getBillingAddress();
133132
const customerEmail = customer?.email || billingAddress?.email || '';
134133

135-
const { customerContextId } = await this.paypalCommerceFastlaneUtils.lookupCustomerOrThrow(
134+
const { customerContextId } = await this.paypalFastlaneUtils.lookupCustomerOrThrow(
136135
customerEmail,
137136
);
138137

139138
const authenticationResult =
140-
await this.paypalCommerceFastlaneUtils.triggerAuthenticationFlowOrThrow(
141-
customerContextId,
142-
);
139+
await this.paypalFastlaneUtils.triggerAuthenticationFlowOrThrow(customerContextId);
143140

144141
const isAuthenticationFlowCanceled =
145142
authenticationResult.authenticationState === PayPalFastlaneAuthenticationState.CANCELED;
146143

147144
await this.updateCustomerDataState(methodId, authenticationResult);
148145

149146
if (isAuthenticationFlowCanceled) {
150-
this.paypalCommerceFastlaneUtils.removeStorageSessionId();
147+
this.paypalFastlaneUtils.removeStorageSessionId();
151148
} else {
152-
this.paypalCommerceFastlaneUtils.updateStorageSessionId(cartId);
149+
this.paypalFastlaneUtils.updateStorageSessionId(cartId);
153150
}
154151
}
155152

@@ -161,7 +158,7 @@ export default class PayPalCommerceFastlaneCustomerStrategy implements CustomerS
161158
const cart = state.getCartOrThrow();
162159

163160
const { authenticationState, addresses, billingAddress, shippingAddress, instruments } =
164-
this.paypalCommerceFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(
161+
this.paypalFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(
165162
methodId,
166163
authenticationResult,
167164
);
@@ -182,7 +179,7 @@ export default class PayPalCommerceFastlaneCustomerStrategy implements CustomerS
182179
);
183180

184181
const paymentMethod =
185-
updatedState.getPaymentMethodOrThrow<PayPalCommerceInitializationData>(methodId);
182+
updatedState.getPaymentMethodOrThrow<PayPalInitializationData>(methodId);
186183
const { isFastlaneShippingOptionAutoSelectEnabled } =
187184
paymentMethod.initializationData || {};
188185
const consignments = updatedState.getConsignments() || [];
@@ -213,8 +210,7 @@ export default class PayPalCommerceFastlaneCustomerStrategy implements CustomerS
213210
paypalcommercefastlane: PayPalCommerceFastlaneCustomerInitializeOptions | undefined,
214211
): PayPalFastlaneStylesOption | undefined {
215212
const state = this.paymentIntegrationService.getState();
216-
const paymentMethod =
217-
state.getPaymentMethodOrThrow<PayPalCommerceInitializationData>(methodId);
213+
const paymentMethod = state.getPaymentMethodOrThrow<PayPalInitializationData>(methodId);
218214

219215
const { fastlaneStyles, isFastlaneStylingEnabled } = paymentMethod.initializationData || {};
220216

0 commit comments

Comments
 (0)