Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
PaymentStrategyFactory,
toResolvableModule,
} from '@bigcommerce/checkout-sdk/payment-integration-api';
import { createPayPalCommerceSdk } from '@bigcommerce/checkout-sdk/paypal-commerce-utils';
import { createPayPalSdkScriptLoader } from '@bigcommerce/checkout-sdk/paypal-utils';
import { LoadingIndicator } from '@bigcommerce/checkout-sdk/ui';

import createPayPalCommerceIntegrationService from '../create-paypal-commerce-integration-service';
Expand All @@ -16,7 +16,7 @@ const createPayPalCommerceAlternativeMethodsPaymentStrategy: PaymentStrategyFact
new PayPalCommerceAlternativeMethodsPaymentStrategy(
paymentIntegrationService,
createPayPalCommerceIntegrationService(paymentIntegrationService),
createPayPalCommerceSdk(),
createPayPalSdkScriptLoader(),
new LoadingIndicator({
containerStyles: LOADING_INDICATOR_STYLES,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import {
PaymentIntegrationServiceMock,
} from '@bigcommerce/checkout-sdk/payment-integrations-test-utils';
import {
createPayPalCommerceSdk,
PayPalCommerceSdk,
} from '@bigcommerce/checkout-sdk/paypal-commerce-utils';
createPayPalSdkScriptLoader,
PayPalSdkScriptLoader,
} from '@bigcommerce/checkout-sdk/paypal-utils';
import { LoadingIndicator } from '@bigcommerce/checkout-sdk/ui';

import {
Expand Down Expand Up @@ -48,7 +48,7 @@ describe('PayPalCommerceAlternativeMethodsPaymentStrategy', () => {
let paypalCommerceIntegrationService: PayPalCommerceIntegrationService;
let paypalSdk: PayPalSDK;
let strategy: PayPalCommerceAlternativeMethodsPaymentStrategy;
let paypalCommerceSdk: PayPalCommerceSdk;
let paypalSdkScriptLoader: PayPalSdkScriptLoader;

const paypalOrderId = 'paypal123';

Expand Down Expand Up @@ -84,12 +84,12 @@ describe('PayPalCommerceAlternativeMethodsPaymentStrategy', () => {
loadingIndicator = new LoadingIndicator();
paypalCommerceIntegrationService = getPayPalCommerceIntegrationServiceMock();
paymentIntegrationService = new PaymentIntegrationServiceMock();
paypalCommerceSdk = createPayPalCommerceSdk();
paypalSdkScriptLoader = createPayPalSdkScriptLoader();

strategy = new PayPalCommerceAlternativeMethodsPaymentStrategy(
paymentIntegrationService,
paypalCommerceIntegrationService,
paypalCommerceSdk,
paypalSdkScriptLoader,
loadingIndicator,
);

Expand All @@ -101,7 +101,7 @@ describe('PayPalCommerceAlternativeMethodsPaymentStrategy', () => {
'getBillingAddressOrThrow',
).mockReturnValue(billingAddress);

jest.spyOn(paypalCommerceSdk, 'getPayPalApmsSdk').mockResolvedValue(paypalSdk);
jest.spyOn(paypalSdkScriptLoader, 'getPayPalApmsSdk').mockResolvedValue(paypalSdk);
jest.spyOn(paypalCommerceIntegrationService, 'createOrder').mockResolvedValue(
paypalOrderId,
);
Expand Down Expand Up @@ -230,13 +230,16 @@ describe('PayPalCommerceAlternativeMethodsPaymentStrategy', () => {

await strategy.initialize(initializationOptions);

expect(paypalCommerceSdk.getPayPalApmsSdk).not.toHaveBeenCalled();
expect(paypalSdkScriptLoader.getPayPalApmsSdk).not.toHaveBeenCalled();
});

it('loads paypal sdk', async () => {
await strategy.initialize(initializationOptions);

expect(paypalCommerceSdk.getPayPalApmsSdk).toHaveBeenCalledWith(paymentMethod, 'USD');
expect(paypalSdkScriptLoader.getPayPalApmsSdk).toHaveBeenCalledWith(
paymentMethod,
'USD',
);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import {
PaymentStrategy,
TimeoutError,
} from '@bigcommerce/checkout-sdk/payment-integration-api';
import { PayPalApmSdk, PayPalCommerceSdk } from '@bigcommerce/checkout-sdk/paypal-commerce-utils';
import {
PayPalApmSdk,
PayPalInitializationData,
PayPalSdkScriptLoader,
} from '@bigcommerce/checkout-sdk/paypal-utils';
import { LoadingIndicator } from '@bigcommerce/checkout-sdk/ui';
import { isExperimentEnabled } from '@bigcommerce/checkout-sdk/utility';

Expand Down Expand Up @@ -47,7 +51,7 @@ export default class PayPalCommerceAlternativeMethodsPaymentStrategy implements
constructor(
private paymentIntegrationService: PaymentIntegrationService,
private paypalCommerceIntegrationService: PayPalCommerceIntegrationService,
private paypalCommerceSdk: PayPalCommerceSdk,
private paypalSdkScriptLoader: PayPalSdkScriptLoader,
private loadingIndicator: LoadingIndicator,
private pollingInterval: number = POLLING_INTERVAL,
private maxPollingIntervalTime: number = MAX_POLLING_TIME,
Expand Down Expand Up @@ -86,7 +90,7 @@ export default class PayPalCommerceAlternativeMethodsPaymentStrategy implements
}

const state = this.paymentIntegrationService.getState();
const paymentMethod = state.getPaymentMethodOrThrow<PayPalCommerceInitializationData>(
const paymentMethod = state.getPaymentMethodOrThrow<PayPalInitializationData>(
methodId,
gatewayId,
);
Expand All @@ -108,7 +112,7 @@ export default class PayPalCommerceAlternativeMethodsPaymentStrategy implements
return;
}

this.paypalApms = await this.paypalCommerceSdk.getPayPalApmsSdk(
this.paypalApms = await this.paypalSdkScriptLoader.getPayPalApmsSdk(
paymentMethod,
state.getCartOrThrow().currency.code,
);
Expand Down