Skip to content

Commit 6edf06b

Browse files
committed
feat(payment): PAYPAL-5758 update PaypalCommerceFastlaneShippingStrategy using paypal-utils package
1 parent fa8e460 commit 6edf06b

File tree

6 files changed

+34
-30
lines changed

6 files changed

+34
-30
lines changed

packages/core/src/shipping/create-shipping-strategy-registry.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ import {
88
BraintreeScriptLoader,
99
BraintreeSDKVersionManager,
1010
} from '@bigcommerce/checkout-sdk/braintree-utils';
11-
import {
12-
createPayPalCommerceFastlaneUtils,
13-
createPayPalCommerceSdk,
14-
} from '@bigcommerce/checkout-sdk/paypal-commerce-utils';
11+
import { createPayPalFastlaneUtils, createPaypalSdk } from '@bigcommerce/checkout-sdk/paypal-utils';
1512
import { StripeScriptLoader } from '@bigcommerce/checkout-sdk/stripe-utils';
1613

1714
import { BillingAddressActionCreator, BillingAddressRequestSender } from '../billing';
@@ -110,8 +107,8 @@ export default function createShippingStrategyRegistry(
110107
consignmentActionCreator,
111108
paymentMethodActionCreator,
112109
new PaymentProviderCustomerActionCreator(),
113-
createPayPalCommerceSdk(),
114-
createPayPalCommerceFastlaneUtils(),
110+
createPaypalSdk(),
111+
createPayPalFastlaneUtils(),
115112
),
116113
);
117114

packages/core/src/shipping/strategies/paypal-commerce/paypal-commerce-fastlane-shipping-strategy.spec.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ import {
99
getShippingAddress,
1010
} from '@bigcommerce/checkout-sdk/payment-integrations-test-utils';
1111
import {
12-
createPayPalCommerceFastlaneUtils,
13-
createPayPalCommerceSdk,
14-
getPayPalCommerceAcceleratedCheckoutPaymentMethod,
12+
createPayPalFastlaneUtils,
13+
createPaypalSdk,
14+
getPayPalAcceleratedCheckoutPaymentMethod,
1515
getPayPalFastlane,
1616
getPayPalFastlaneAuthenticationResultMock,
1717
getPayPalFastlaneSdk,
18-
PayPalCommerceFastlaneUtils,
19-
PayPalCommerceSdk,
2018
PayPalFastlaneAuthenticationState,
2119
PayPalFastlaneSdk,
22-
} from '@bigcommerce/checkout-sdk/paypal-commerce-utils';
20+
PayPalFastlaneUtils,
21+
PaypalSdk,
22+
} from '@bigcommerce/checkout-sdk/paypal-utils';
2323

2424
import { BillingAddress, BillingAddressActionCreator } from '../../../billing';
2525
import BillingAddressRequestSender from '../../../billing/billing-address-request-sender';
@@ -48,8 +48,8 @@ describe('PayPalCommerceFastlaneShippingStrategy', () => {
4848
let paymentMethod: PaymentMethod;
4949
let paymentProviderCustomerActionCreator: PaymentProviderCustomerActionCreator;
5050
let paypalFastlaneSdk: PayPalFastlaneSdk;
51-
let paypalCommerceSdk: PayPalCommerceSdk;
52-
let paypalCommerceFastlaneUtils: PayPalCommerceFastlaneUtils;
51+
let paypalCommerceSdk: PaypalSdk;
52+
let paypalCommerceFastlaneUtils: PayPalFastlaneUtils;
5353
let store: CheckoutStore;
5454
let storeConfig: StoreConfig;
5555
let strategy: PayPalCommerceFastlaneShippingStrategy;
@@ -98,7 +98,7 @@ describe('PayPalCommerceFastlaneShippingStrategy', () => {
9898
cart = getCart();
9999
customer = { ...getCustomer(), isGuest: true };
100100
storeConfig = getConfig().storeConfig;
101-
paymentMethod = getPayPalCommerceAcceleratedCheckoutPaymentMethod();
101+
paymentMethod = getPayPalAcceleratedCheckoutPaymentMethod();
102102
paypalFastlaneSdk = getPayPalFastlaneSdk();
103103

104104
store = createCheckoutStore();
@@ -114,8 +114,8 @@ describe('PayPalCommerceFastlaneShippingStrategy', () => {
114114
new PaymentMethodRequestSender(requestSender),
115115
);
116116
paymentProviderCustomerActionCreator = new PaymentProviderCustomerActionCreator();
117-
paypalCommerceSdk = createPayPalCommerceSdk();
118-
paypalCommerceFastlaneUtils = createPayPalCommerceFastlaneUtils();
117+
paypalCommerceSdk = createPaypalSdk();
118+
paypalCommerceFastlaneUtils = createPayPalFastlaneUtils();
119119

120120
strategy = new PayPalCommerceFastlaneShippingStrategy(
121121
store,

packages/core/src/shipping/strategies/paypal-commerce/paypal-commerce-fastlane-shipping-strategy.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import {
33
getFastlaneStyles,
44
isPayPalCommerceAcceleratedCheckoutCustomer,
55
isPayPalFastlaneCustomer,
6-
PayPalCommerceFastlaneUtils,
7-
PayPalCommerceInitializationData,
8-
PayPalCommerceSdk,
96
PayPalFastlaneAuthenticationState,
107
PayPalFastlaneStylesOption,
11-
} from '@bigcommerce/checkout-sdk/paypal-commerce-utils';
8+
PayPalFastlaneUtils,
9+
PayPalInitializationData,
10+
PaypalSdk,
11+
} from '@bigcommerce/checkout-sdk/paypal-utils';
1212

1313
import { AddressRequestBody } from '../../../address';
1414
import { BillingAddressActionCreator } from '../../../billing';
@@ -27,8 +27,8 @@ export default class PayPalCommerceFastlaneShippingStrategy implements ShippingS
2727
private _consignmentActionCreator: ConsignmentActionCreator,
2828
private _paymentMethodActionCreator: PaymentMethodActionCreator,
2929
private _paymentProviderCustomerActionCreator: PaymentProviderCustomerActionCreator,
30-
private _paypalCommerceSdk: PayPalCommerceSdk,
31-
private _paypalCommerceFastlaneUtils: PayPalCommerceFastlaneUtils,
30+
private _paypalCommerceSdk: PaypalSdk,
31+
private _paypalCommerceFastlaneUtils: PayPalFastlaneUtils,
3232
) {}
3333

3434
updateAddress(
@@ -91,7 +91,7 @@ export default class PayPalCommerceFastlaneShippingStrategy implements ShippingS
9191

9292
private async _getPayPalPaymentMethodOrThrow(
9393
methodId: string,
94-
): Promise<PaymentMethod<PayPalCommerceInitializationData>> {
94+
): Promise<PaymentMethod<PayPalInitializationData>> {
9595
const state = this._store.getState();
9696
const paymentMethod = state.paymentMethods.getPaymentMethod(methodId);
9797

packages/paypal-utils/src/mocks/get-paypal-payment-method.mock.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export default function getPayPalPaymentMethod(): PaymentMethod {
4848
isPayPalCommerceAnalyticsV2Enabled: false,
4949
isPayPalCreditAvailable: false,
5050
isVenmoEnabled: false,
51+
isDeveloperModeApplicable: false,
5152
shouldRenderFields: true,
5253
shouldRunAcceleratedCheckout: false,
5354
isHostedCheckoutEnabled: false,

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,15 @@ export default class PayPalIntegrationService {
212212

213213
const selectedShippingOption = selectedShippingOptionId
214214
? availableShippingOptions.find((option) => option.id === selectedShippingOptionId)
215-
: availableShippingOptions.find(
216-
(option) => option.id === consignment.selectedShippingOption?.id,
217-
);
215+
: availableShippingOptions.find((option) => {
216+
if (consignment.selectedShippingOption) {
217+
const shippingOptionId = consignment.selectedShippingOption.id;
218+
219+
return option.id === shippingOptionId;
220+
}
221+
222+
return false;
223+
});
218224

219225
const shippingOptionToSelect =
220226
selectedShippingOption || recommendedShippingOption || availableShippingOptions[0];
@@ -293,8 +299,8 @@ export default class PayPalIntegrationService {
293299
* Buttons style methods
294300
*
295301
*/
296-
getValidButtonStyle(style?: PayPalButtonStyleOptions): PayPalButtonStyleOptions {
297-
const { color, height, label, shape } = style || {};
302+
getValidButtonStyle(style: PayPalButtonStyleOptions = {}): PayPalButtonStyleOptions {
303+
const { color, height, label, shape } = style;
298304

299305
const validStyles = {
300306
color: color && StyleButtonColor[color] ? color : undefined,

packages/paypal-utils/src/paypal-sdk-script-loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export default class PaypalSdkScriptLoader {
163163
): PayPalSdkConfig {
164164
const { id, clientToken, initializationData } = paymentMethod;
165165

166-
if (!initializationData?.clientId) {
166+
if (!initializationData || !initializationData.clientId) {
167167
throw new MissingDataError(MissingDataErrorType.MissingPaymentMethod);
168168
}
169169

0 commit comments

Comments
 (0)