Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(payment): STRIPE-660 Disable state code mapping for Spain in Stripe Link Address component #2797

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -48,5 +48,18 @@ export default interface StripeUPEShippingInitializeOptions {
* @param country
* @param state
*/
getStripeState(country: string, state: string): string;
getStripeState(
country: string,
state: string,
isStripeStateMappingDisabledForES?: boolean,
): string;

/**
* Set the Stripe experiments to be used in checkout-js components;
* Stripe specific experiments broadcasts to SDK from payment provider configs request.
*
* @param experiments
* @returns void
*/
setStripeExperiments?(experiments: Record<string, boolean>): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { getFlatRateOption } from '../../internal-shipping-options.mock';
import { getShippingAddress } from '../../shipping-addresses.mock';
import { ShippingInitializeOptions } from '../../shipping-request-options';

import StripeUPEShippingInitializeOptions from './stripe-upe-shipping-initialize-options';
import StripeUPEShippingStrategy from './stripe-upe-shipping-strategy';

// TODO: CHECKOUT-7766
Expand Down Expand Up @@ -408,6 +409,42 @@ describe('StripeUPEShippingStrategy', () => {

await expect(promise).rejects.toBeInstanceOf(MissingDataError);
});

it('Set experiments from initialization data and get state mapping with experiment', async () => {
const setStripeExperimentsMock = jest.fn();
const stripeUPEMock = getStripeUPE();
const shippingAddressMock = getShippingAddress();

jest.spyOn(store.getState().paymentMethods, 'getPaymentMethodOrThrow').mockReturnValue({
...stripeUPEMock,
initializationData: {
...stripeUPEMock.initializationData,
isStripeStateMappingDisabledForES: true,
},
});
jest.spyOn(store.getState().shippingAddress, 'getShippingAddress').mockReturnValue(
shippingAddressMock,
);

await expect(
strategy.initialize({
...shippingInitialization,
stripeupe: {
...shippingInitialization.stripeupe,
setStripeExperiments: setStripeExperimentsMock,
} as StripeUPEShippingInitializeOptions,
}),
).resolves.toBe(store.getState());

expect(setStripeExperimentsMock).toHaveBeenCalledWith({
isStripeStateMappingDisabledForES: true,
});
expect(shippingInitialization.stripeupe?.getStripeState).toHaveBeenCalledWith(
shippingAddressMock.countryCode,
shippingAddressMock.stateOrProvinceCode,
true,
);
});
});

describe('#deinitialize()', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default class StripeUPEShippingStrategy implements ShippingStrategy {
getStyles,
availableCountries,
getStripeState,
setStripeExperiments,
} = options.stripeupe;

Object.entries(options.stripeupe).forEach(([key, value]) => {
Expand All @@ -81,7 +82,11 @@ export default class StripeUPEShippingStrategy implements ShippingStrategy {
);
const paymentMethod = state.paymentMethods.getPaymentMethodOrThrow(methodId, gatewayId);
const {
initializationData: { stripePublishableKey, stripeConnectedAccount },
initializationData: {
stripePublishableKey,
stripeConnectedAccount,
isStripeStateMappingDisabledForES,
},
} = paymentMethod;

if (
Expand All @@ -92,6 +97,10 @@ export default class StripeUPEShippingStrategy implements ShippingStrategy {
throw new MissingDataError(MissingDataErrorType.MissingPaymentMethod);
}

setStripeExperiments?.({
isStripeStateMappingDisabledForES,
});

this._stripeUPEClient = await this._stripeUPEScriptLoader.getStripeClient(
stripePublishableKey,
stripeConnectedAccount,
Expand Down Expand Up @@ -174,7 +183,11 @@ export default class StripeUPEShippingStrategy implements ShippingStrategy {
} = shipping;
const stripeState =
stateOrProvinceCode && countryCode
? getStripeState(countryCode, stateOrProvinceCode)
? getStripeState(
countryCode,
stateOrProvinceCode,
isStripeStateMappingDisabledForES,
)
: stateOrProvinceCode;

option = {
Expand Down
1 change: 1 addition & 0 deletions packages/stripe-integration/src/stripe-upe/stripe-upe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ export interface StripeUPEInitializationData {
stripePublishableKey: string;
stripeConnectedAccount: string;
shopperLanguage: string;
isStripeStateMappingDisabledForES?: boolean;
}

export interface StripeElementUpdateOptions {
Expand Down