Skip to content

Commit 69ae597

Browse files
committed
feat(payment): add checkout locale to Stripe elements
1 parent 84056ba commit 69ae597

17 files changed

+27
-13
lines changed

packages/core/src/cart/cart-selector.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default interface CartSelector {
1212
getCartOrThrow(): Cart;
1313
getLoadError(): Error | undefined;
1414
isLoading(): boolean;
15+
getLocale(): string | undefined;
1516
}
1617

1718
export type CartSelectorFactory = (state: CartState) => CartSelector;
@@ -36,12 +37,18 @@ export function createCartSelectorFactory() {
3637
(status) => () => status,
3738
);
3839

40+
const getLocale = createSelector(
41+
(state: CartState) => state.data?.locale,
42+
(data) => () => data,
43+
);
44+
3945
return memoizeOne((state: CartState = DEFAULT_STATE): CartSelector => {
4046
return {
4147
getCart: getCart(state),
4248
getCartOrThrow: getCartOrThrow(state),
4349
getLoadError: getLoadError(state),
4450
isLoading: isLoading(state),
51+
getLocale: getLocale(state),
4552
};
4653
});
4754
}

packages/core/src/cart/cart.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ export default interface Cart {
3535
createdTime: string;
3636
updatedTime: string;
3737
source?: CartSource;
38+
locale?: string;
3839
}

packages/core/src/payment-integration/create-payment-integration-selectors.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { cloneResult as clone } from '../common/utility';
55

66
export default function createPaymentIntegrationSelectors({
77
billingAddress: { getBillingAddress, getBillingAddressOrThrow },
8-
cart: { getCart, getCartOrThrow },
8+
cart: { getCart, getCartOrThrow, getLocale: getCartLocale },
99
checkout: { getCheckout, getCheckoutOrThrow, getOutstandingBalance },
1010
config: {
1111
getContextConfig,
@@ -50,6 +50,7 @@ export default function createPaymentIntegrationSelectors({
5050
return {
5151
getHost: clone(getHost),
5252
getLocale: clone(getLocale),
53+
getCartLocale: clone(getCartLocale),
5354
getBillingAddress: clone(getBillingAddress),
5455
getBillingAddressOrThrow: clone(getBillingAddressOrThrow),
5556
getCart: clone(getCart),

packages/core/src/shipping/strategies/stripe-upe/stripe-upe-shipping-strategy.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ describe('StripeUPEShippingStrategy', () => {
142142
getStripeUPE(),
143143
);
144144

145-
jest.spyOn(store.getState().config, 'getLocale').mockReturnValue('en');
145+
jest.spyOn(store.getState().cart, 'getLocale').mockReturnValue('en');
146146
});
147147

148148
afterEach(() => {

packages/core/src/shipping/strategies/stripe-upe/stripe-upe-shipping-strategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export default class StripeUPEShippingStrategy implements ShippingStrategy {
9696

9797
this._stripeUPEClient = await this._stripeUPEScriptLoader.getStripeClient(
9898
initializationData,
99-
state.config.getLocale(),
99+
state.cart.getLocale(),
100100
STRIPE_UPE_CLIENT_BETAS,
101101
STRIPE_UPE_CLIENT_API_VERSION,
102102
);

packages/payment-integration-api/src/payment-integration-selectors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { Consignment, ShippingAddress } from './shipping';
1717
export default interface PaymentIntegrationSelectors {
1818
getHost(): string | undefined;
1919
getLocale(): string | undefined;
20+
getCartLocale(): string | undefined;
2021

2122
getBillingAddress(): BillingAddress | undefined;
2223
getBillingAddressOrThrow(): BillingAddress;

packages/payment-integrations-test-utils/src/test-utils/payment-integration-service.mock.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const state = {
3232
getCustomerOrThrow: jest.fn(() => getCustomer()),
3333
getHost: jest.fn(),
3434
getLocale: jest.fn(),
35+
getCartLocale: jest.fn(),
3536
getOrder: jest.fn(() => getOrder()),
3637
getOrderOrThrow: jest.fn(() => getOrder()),
3738
getOrderMeta: jest.fn(() => getOrderMeta()),

packages/stripe-integration/src/stripe-ocs/stripe-link-v2-button-strategy.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ describe('StripeLinkV2ButtonStrategy', () => {
135135
jest.spyOn(paymentIntegrationService.getState(), 'getPaymentMethodOrThrow').mockReturnValue(
136136
stripePaymentMethod,
137137
);
138-
jest.spyOn(paymentIntegrationService.getState(), 'getLocale').mockReturnValue('en');
138+
jest.spyOn(paymentIntegrationService.getState(), 'getCartLocale').mockReturnValue('en');
139139
jest.spyOn(stripeIntegrationService, 'isPaymentCompleted').mockReturnValue(
140140
Promise.resolve(false),
141141
);

packages/stripe-integration/src/stripe-ocs/stripe-link-v2-button-strategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export default class StripeLinkV2ButtonStrategy implements CheckoutButtonStrateg
9292
this._captureMethod = captureMethod;
9393
this._stripeClient = await this.scriptLoader.getStripeClient(
9494
initializationData,
95-
state.getLocale(),
95+
state.getCartLocale(),
9696
);
9797

9898
await this.paymentIntegrationService.loadDefaultCheckout();

packages/stripe-integration/src/stripe-ocs/stripe-link-v2-customer-strategy.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ describe('StripeLinkV2CustomerStrategy', () => {
135135
jest.spyOn(paymentIntegrationService.getState(), 'getPaymentMethodOrThrow').mockReturnValue(
136136
stripePaymentMethod,
137137
);
138-
jest.spyOn(paymentIntegrationService.getState(), 'getLocale').mockReturnValue('en');
138+
jest.spyOn(paymentIntegrationService.getState(), 'getCartLocale').mockReturnValue('en');
139139
jest.spyOn(stripeIntegrationService, 'isPaymentCompleted').mockReturnValue(
140140
Promise.resolve(false),
141141
);

0 commit comments

Comments
 (0)