Skip to content

Commit 9c60db0

Browse files
committed
fix(payment): PI-4290 google pay shipping address required fix
1 parent 45fa2f5 commit 9c60db0

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed

packages/google-pay-integration/src/gateways/google-pay-gateway.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from '@bigcommerce/checkout-sdk/payment-integration-api';
99
import {
1010
getBillingAddress,
11+
getCart,
1112
getConfig,
1213
getConsignment,
1314
getShippingOption,
@@ -33,6 +34,8 @@ describe('GooglePayGateway', () => {
3334
features: {
3435
...storeConfig.checkoutSettings.features,
3536
'PI-2875.googlepay_coupons_handling': true,
37+
// experiment name will be added after code freeze
38+
experiment_shouldRequestShipping: true,
3639
},
3740
},
3841
};
@@ -166,6 +169,31 @@ describe('GooglePayGateway', () => {
166169
});
167170
});
168171

172+
describe('#setShouldRequestShipping', () => {
173+
beforeEach(() => {
174+
jest.spyOn(paymentIntegrationService.getState(), 'getCartOrThrow').mockReturnValue(
175+
getCart(),
176+
);
177+
});
178+
179+
it('_isShippingAddressRequired should return false', async () => {
180+
await gateway.initialize(getGeneric);
181+
gateway.setShouldRequestShipping(false);
182+
183+
expect(gateway.getCallbackIntents()).toStrictEqual([CallbackIntentsType.OFFER]);
184+
});
185+
186+
it('_isShippingAddressRequired should be true by default', async () => {
187+
await gateway.initialize(getGeneric);
188+
189+
expect(gateway.getCallbackIntents()).toStrictEqual([
190+
CallbackIntentsType.OFFER,
191+
CallbackIntentsType.SHIPPING_ADDRESS,
192+
CallbackIntentsType.SHIPPING_OPTION,
193+
]);
194+
});
195+
});
196+
169197
describe('#getMerchantInfo', () => {
170198
it('should get merchant info', async () => {
171199
const expectedInfo = {

packages/google-pay-integration/src/gateways/google-pay-gateway.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
PaymentMethod,
1717
ShippingOption,
1818
} from '@bigcommerce/checkout-sdk/payment-integration-api';
19+
import { isExperimentEnabled } from '@bigcommerce/checkout-sdk/utility';
1920

2021
import isGooglePayCardNetworkKey from '../guards/is-google-pay-card-network-key';
2122
import {
@@ -44,6 +45,7 @@ import {
4445
export default class GooglePayGateway {
4546
private _getPaymentMethodFn?: () => PaymentMethod<GooglePayInitializationData>;
4647
private _isBuyNowFlow = false;
48+
private _shouldRequestShipping = true;
4749
private _currencyCode?: string;
4850
private _currencyService?: CurrencyService;
4951

@@ -423,6 +425,10 @@ export default class GooglePayGateway {
423425
}
424426
}
425427

428+
setShouldRequestShipping(isRequired: boolean): void {
429+
this._shouldRequestShipping = isRequired;
430+
}
431+
426432
protected getGooglePayInitializationData(): GooglePayInitializationData {
427433
return guard(
428434
this.getPaymentMethod().initializationData,
@@ -446,13 +452,26 @@ export default class GooglePayGateway {
446452
}
447453

448454
private _isShippingAddressRequired(): boolean {
449-
const { getCartOrThrow, getStoreConfig, getShippingAddress } =
455+
const { getCartOrThrow, getStoreConfigOrThrow, getShippingAddress } =
450456
this._paymentIntegrationService.getState();
457+
const storeConfig = getStoreConfigOrThrow();
458+
const features = storeConfig.checkoutSettings.features;
451459

452-
return (
453-
getShippingAddress() === undefined &&
454-
itemsRequireShipping(getCartOrThrow(), getStoreConfig())
460+
const checkWithExperiment = isExperimentEnabled(
461+
features,
462+
// experiment name will be added after code freeze
463+
'experiment_shouldRequestShipping',
455464
);
465+
466+
let shippingContextRequiresCheck: boolean;
467+
468+
if (checkWithExperiment) {
469+
shippingContextRequiresCheck = this._shouldRequestShipping;
470+
} else {
471+
shippingContextRequiresCheck = getShippingAddress() === undefined;
472+
}
473+
474+
return shippingContextRequiresCheck && itemsRequireShipping(getCartOrThrow(), storeConfig);
456475
}
457476

458477
private _mapToAddressRequestBody(

packages/google-pay-integration/src/google-pay-payment-processor.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ export default class GooglePayPaymentProcessor {
145145
return this._gateway.getCallbackTriggers();
146146
}
147147

148+
setShouldRequestShipping(isRequired: boolean): void {
149+
return this._gateway.setShouldRequestShipping(isRequired);
150+
}
151+
148152
async handleShippingAddressChange(
149153
shippingAddress: GooglePayFullBillingAddress,
150154
): Promise<ShippingOptionParameters | undefined> {

packages/google-pay-integration/src/google-pay-payment-strategy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export default class GooglePayPaymentStrategy implements PaymentStrategy {
152152

153153
// TODO: Dispatch Widget Actions
154154
try {
155+
this._googlePayPaymentProcessor.setShouldRequestShipping(false);
155156
await this._googlePayPaymentProcessor.initializeWidget();
156157
await this._interactWithPaymentSheet();
157158
} catch (error) {

0 commit comments

Comments
 (0)