diff --git a/packages/paypal-commerce-integration/src/paypal-commerce-fastlane/create-paypal-commerce-fastlane-customer-strategy.ts b/packages/paypal-commerce-integration/src/paypal-commerce-fastlane/create-paypal-commerce-fastlane-customer-strategy.ts index fd61748314..97345c920c 100644 --- a/packages/paypal-commerce-integration/src/paypal-commerce-fastlane/create-paypal-commerce-fastlane-customer-strategy.ts +++ b/packages/paypal-commerce-integration/src/paypal-commerce-fastlane/create-paypal-commerce-fastlane-customer-strategy.ts @@ -3,9 +3,9 @@ import { toResolvableModule, } from '@bigcommerce/checkout-sdk/payment-integration-api'; import { - createPayPalCommerceFastlaneUtils, - createPayPalCommerceSdk, -} from '@bigcommerce/checkout-sdk/paypal-commerce-utils'; + createPayPalFastlaneUtils, + createPayPalSdkScriptLoader, +} from '@bigcommerce/checkout-sdk/paypal-utils'; import PayPalCommerceFastlaneCustomerStrategy from './paypal-commerce-fastlane-customer-strategy'; @@ -14,8 +14,8 @@ const createPayPalCommerceFastlaneCustomerStrategy: CustomerStrategyFactory< > = (paymentIntegrationService) => new PayPalCommerceFastlaneCustomerStrategy( paymentIntegrationService, - createPayPalCommerceSdk(), - createPayPalCommerceFastlaneUtils(), + createPayPalSdkScriptLoader(), + createPayPalFastlaneUtils(), ); export default toResolvableModule(createPayPalCommerceFastlaneCustomerStrategy, [ diff --git a/packages/paypal-commerce-integration/src/paypal-commerce-fastlane/paypal-commerce-fastlane-customer-strategy.spec.ts b/packages/paypal-commerce-integration/src/paypal-commerce-fastlane/paypal-commerce-fastlane-customer-strategy.spec.ts index 8070b54819..76e85cd2d5 100644 --- a/packages/paypal-commerce-integration/src/paypal-commerce-fastlane/paypal-commerce-fastlane-customer-strategy.spec.ts +++ b/packages/paypal-commerce-integration/src/paypal-commerce-fastlane/paypal-commerce-fastlane-customer-strategy.spec.ts @@ -14,23 +14,23 @@ import { PaymentIntegrationServiceMock, } from '@bigcommerce/checkout-sdk/payment-integrations-test-utils'; import { - createPayPalCommerceFastlaneUtils, - createPayPalCommerceSdk, - getPayPalCommerceAcceleratedCheckoutPaymentMethod, + createPayPalFastlaneUtils, + createPayPalSdkScriptLoader, + getPayPalAcceleratedCheckoutPaymentMethod, getPayPalFastlaneSdk, - PayPalCommerceFastlaneUtils, - PayPalCommerceSdk, PayPalFastlaneAuthenticationState, PayPalFastlaneSdk, -} from '@bigcommerce/checkout-sdk/paypal-commerce-utils'; + PayPalFastlaneUtils, + PayPalSdkScriptLoader, +} from '@bigcommerce/checkout-sdk/paypal-utils'; import PayPalCommerceFastlaneCustomerStrategy from './paypal-commerce-fastlane-customer-strategy'; describe('PayPalCommerceFastlaneCustomerStrategy', () => { let paymentIntegrationService: PaymentIntegrationService; let paymentMethod: PaymentMethod; - let paypalCommerceFastlaneUtils: PayPalCommerceFastlaneUtils; - let paypalCommerceSdk: PayPalCommerceSdk; + let paypalCommerceFastlaneUtils: PayPalFastlaneUtils; + let paypalSdkScriptLoader: PayPalSdkScriptLoader; let paypalFastlaneSdk: PayPalFastlaneSdk; let strategy: PayPalCommerceFastlaneCustomerStrategy; @@ -155,16 +155,16 @@ describe('PayPalCommerceFastlaneCustomerStrategy', () => { }; beforeEach(() => { - paymentMethod = getPayPalCommerceAcceleratedCheckoutPaymentMethod(); + paymentMethod = getPayPalAcceleratedCheckoutPaymentMethod(); paypalFastlaneSdk = getPayPalFastlaneSdk(); paymentIntegrationService = new PaymentIntegrationServiceMock(); - paypalCommerceSdk = createPayPalCommerceSdk(); - paypalCommerceFastlaneUtils = createPayPalCommerceFastlaneUtils(); + paypalSdkScriptLoader = createPayPalSdkScriptLoader(); + paypalCommerceFastlaneUtils = createPayPalFastlaneUtils(); strategy = new PayPalCommerceFastlaneCustomerStrategy( paymentIntegrationService, - paypalCommerceSdk, + paypalSdkScriptLoader, paypalCommerceFastlaneUtils, ); @@ -183,7 +183,7 @@ describe('PayPalCommerceFastlaneCustomerStrategy', () => { jest.spyOn(state, 'getBillingAddress').mockReturnValue(getBillingAddress()); jest.spyOn(state, 'getStoreConfigOrThrow').mockReturnValue(storeConfig); - jest.spyOn(paypalCommerceSdk, 'getPayPalFastlaneSdk').mockImplementation(() => + jest.spyOn(paypalSdkScriptLoader, 'getPayPalFastlaneSdk').mockImplementation(() => Promise.resolve(paypalFastlaneSdk), ); jest.spyOn(paypalCommerceFastlaneUtils, 'initializePayPalFastlane'); @@ -297,7 +297,7 @@ describe('PayPalCommerceFastlaneCustomerStrategy', () => { it('loads paypal sdk and initialises paypal fastlane in production mode', async () => { await strategy.initialize(initializationOptions); - expect(paypalCommerceSdk.getPayPalFastlaneSdk).toHaveBeenCalledWith( + expect(paypalSdkScriptLoader.getPayPalFastlaneSdk).toHaveBeenCalledWith( paymentMethod, cart.currency.code, cart.id, @@ -320,7 +320,7 @@ describe('PayPalCommerceFastlaneCustomerStrategy', () => { await strategy.initialize(initializationOptions); - expect(paypalCommerceSdk.getPayPalFastlaneSdk).toHaveBeenCalledWith( + expect(paypalSdkScriptLoader.getPayPalFastlaneSdk).toHaveBeenCalledWith( paymentMethod, cart.currency.code, cart.id, @@ -342,13 +342,13 @@ describe('PayPalCommerceFastlaneCustomerStrategy', () => { 'getPaymentMethodOrThrow', ).mockReturnValue(paymentMethod); - jest.spyOn(paypalCommerceSdk, 'getPayPalFastlaneSdk').mockImplementation(() => + jest.spyOn(paypalSdkScriptLoader, 'getPayPalFastlaneSdk').mockImplementation(() => Promise.reject(), ); await strategy.initialize(initializationOptions); - expect(paypalCommerceSdk.getPayPalFastlaneSdk).toHaveBeenCalled(); + expect(paypalSdkScriptLoader.getPayPalFastlaneSdk).toHaveBeenCalled(); expect(paypalCommerceFastlaneUtils.initializePayPalFastlane).not.toHaveBeenCalled(); }); }); diff --git a/packages/paypal-commerce-integration/src/paypal-commerce-fastlane/paypal-commerce-fastlane-customer-strategy.ts b/packages/paypal-commerce-integration/src/paypal-commerce-fastlane/paypal-commerce-fastlane-customer-strategy.ts index 06b2654ce3..dc8565aba2 100644 --- a/packages/paypal-commerce-integration/src/paypal-commerce-fastlane/paypal-commerce-fastlane-customer-strategy.ts +++ b/packages/paypal-commerce-integration/src/paypal-commerce-fastlane/paypal-commerce-fastlane-customer-strategy.ts @@ -9,13 +9,13 @@ import { } from '@bigcommerce/checkout-sdk/payment-integration-api'; import { getFastlaneStyles, - PayPalCommerceFastlaneUtils, - PayPalCommerceInitializationData, - PayPalCommerceSdk, PayPalFastlaneAuthenticationResult, PayPalFastlaneAuthenticationState, PayPalFastlaneStylesOption, -} from '@bigcommerce/checkout-sdk/paypal-commerce-utils'; + PayPalFastlaneUtils, + PayPalInitializationData, + PayPalSdkScriptLoader, +} from '@bigcommerce/checkout-sdk/paypal-utils'; import PayPalCommerceFastlaneCustomerInitializeOptions, { WithPayPalCommerceFastlaneCustomerInitializeOptions, @@ -24,8 +24,8 @@ import PayPalCommerceFastlaneCustomerInitializeOptions, { export default class PayPalCommerceFastlaneCustomerStrategy implements CustomerStrategy { constructor( private paymentIntegrationService: PaymentIntegrationService, - private paypalCommerceSdk: PayPalCommerceSdk, - private paypalCommerceFastlaneUtils: PayPalCommerceFastlaneUtils, + private paypalSdkScriptLoader: PayPalSdkScriptLoader, + private paypalFastlaneUtils: PayPalFastlaneUtils, ) {} async initialize( @@ -44,18 +44,17 @@ export default class PayPalCommerceFastlaneCustomerStrategy implements CustomerS const state = this.paymentIntegrationService.getState(); const cart = state.getCartOrThrow(); - const paymentMethod = - state.getPaymentMethodOrThrow(methodId); + const paymentMethod = state.getPaymentMethodOrThrow(methodId); const isTestModeEnabled = !!paymentMethod.initializationData?.isDeveloperModeApplicable; - const paypalFastlaneSdk = await this.paypalCommerceSdk.getPayPalFastlaneSdk( + const paypalFastlaneSdk = await this.paypalSdkScriptLoader.getPayPalFastlaneSdk( paymentMethod, cart.currency.code, cart.id, ); - await this.paypalCommerceFastlaneUtils.initializePayPalFastlane( + await this.paypalFastlaneUtils.initializePayPalFastlane( paypalFastlaneSdk, isTestModeEnabled, this.getFastlaneStyles(methodId, paypalcommercefastlane), @@ -132,14 +131,12 @@ export default class PayPalCommerceFastlaneCustomerStrategy implements CustomerS const billingAddress = state.getBillingAddress(); const customerEmail = customer?.email || billingAddress?.email || ''; - const { customerContextId } = await this.paypalCommerceFastlaneUtils.lookupCustomerOrThrow( + const { customerContextId } = await this.paypalFastlaneUtils.lookupCustomerOrThrow( customerEmail, ); const authenticationResult = - await this.paypalCommerceFastlaneUtils.triggerAuthenticationFlowOrThrow( - customerContextId, - ); + await this.paypalFastlaneUtils.triggerAuthenticationFlowOrThrow(customerContextId); const isAuthenticationFlowCanceled = authenticationResult.authenticationState === PayPalFastlaneAuthenticationState.CANCELED; @@ -147,9 +144,9 @@ export default class PayPalCommerceFastlaneCustomerStrategy implements CustomerS await this.updateCustomerDataState(methodId, authenticationResult); if (isAuthenticationFlowCanceled) { - this.paypalCommerceFastlaneUtils.removeStorageSessionId(); + this.paypalFastlaneUtils.removeStorageSessionId(); } else { - this.paypalCommerceFastlaneUtils.updateStorageSessionId(cartId); + this.paypalFastlaneUtils.updateStorageSessionId(cartId); } } @@ -161,7 +158,7 @@ export default class PayPalCommerceFastlaneCustomerStrategy implements CustomerS const cart = state.getCartOrThrow(); const { authenticationState, addresses, billingAddress, shippingAddress, instruments } = - this.paypalCommerceFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData( + this.paypalFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData( methodId, authenticationResult, ); @@ -182,7 +179,7 @@ export default class PayPalCommerceFastlaneCustomerStrategy implements CustomerS ); const paymentMethod = - updatedState.getPaymentMethodOrThrow(methodId); + updatedState.getPaymentMethodOrThrow(methodId); const { isFastlaneShippingOptionAutoSelectEnabled } = paymentMethod.initializationData || {}; const consignments = updatedState.getConsignments() || []; @@ -213,8 +210,7 @@ export default class PayPalCommerceFastlaneCustomerStrategy implements CustomerS paypalcommercefastlane: PayPalCommerceFastlaneCustomerInitializeOptions | undefined, ): PayPalFastlaneStylesOption | undefined { const state = this.paymentIntegrationService.getState(); - const paymentMethod = - state.getPaymentMethodOrThrow(methodId); + const paymentMethod = state.getPaymentMethodOrThrow(methodId); const { fastlaneStyles, isFastlaneStylingEnabled } = paymentMethod.initializationData || {};