Skip to content

Commit e6b5be3

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

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ describe('GooglePayGateway', () => {
3333
features: {
3434
...storeConfig.checkoutSettings.features,
3535
'PI-2875.googlepay_coupons_handling': true,
36+
// experiment name will be added after code freeze
37+
'experiment_shouldRequestShipping': true,
3638
},
3739
},
3840
};

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ export default class GooglePayGateway {
110110
});
111111
}
112112

113-
async getRequiredData(): Promise<GooglePayRequiredPaymentData> {
113+
async getRequiredData(shouldRequestShipping = true): Promise<GooglePayRequiredPaymentData> {
114114
const data: GooglePayRequiredPaymentData = { emailRequired: true };
115115

116-
if (!this._isShippingAddressRequired()) {
116+
if (!this._isShippingAddressRequired(shouldRequestShipping)) {
117117
return data;
118118
}
119119

@@ -131,8 +131,8 @@ export default class GooglePayGateway {
131131
};
132132
}
133133

134-
getCallbackIntents(): CallbackIntentsType[] {
135-
if (this._isShippingAddressRequired()) {
134+
getCallbackIntents(shouldRequestShipping = true): CallbackIntentsType[] {
135+
if (this._isShippingAddressRequired(shouldRequestShipping)) {
136136
return [
137137
CallbackIntentsType.OFFER,
138138
CallbackIntentsType.SHIPPING_ADDRESS,
@@ -445,13 +445,24 @@ export default class GooglePayGateway {
445445
this._gatewayIdentifier = gateway || this.getGatewayIdentifier();
446446
}
447447

448-
private _isShippingAddressRequired(): boolean {
448+
private _isShippingAddressRequired(shouldRequestShipping = true): boolean {
449449
const { getCartOrThrow, getStoreConfig, getShippingAddress } =
450450
this._paymentIntegrationService.getState();
451451

452+
// experiment name will be added after code freeze
453+
const useNewLogic = getStoreConfig()?.checkoutSettings.features['experiment_shouldRequestShipping'] || false;
454+
455+
console.log('useNewLogic', useNewLogic);
456+
let shippingContextRequiresCheck: boolean;
457+
458+
if (useNewLogic) {
459+
shippingContextRequiresCheck = shouldRequestShipping;
460+
} else {
461+
shippingContextRequiresCheck = getShippingAddress() === undefined;
462+
}
463+
452464
return (
453-
getShippingAddress() === undefined &&
454-
itemsRequireShipping(getCartOrThrow(), getStoreConfig())
465+
shippingContextRequiresCheck && itemsRequireShipping(getCartOrThrow(), getStoreConfig())
455466
);
456467
}
457468

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ export default class GooglePayPaymentProcessor {
6464
this._buildButtonPayloads();
6565
}
6666

67-
async initializeWidget() {
68-
await this._buildWidgetPayloads();
67+
async initializeWidget(shouldRequestShipping = true) {
68+
await this._buildWidgetPayloads(shouldRequestShipping);
6969

7070
await this._determineReadinessToPay();
7171

@@ -236,7 +236,7 @@ export default class GooglePayPaymentProcessor {
236236
};
237237
}
238238

239-
private async _buildWidgetPayloads(): Promise<void> {
239+
private async _buildWidgetPayloads(shouldRequestShipping = true): Promise<void> {
240240
const baseCardPaymentMethod = this._getBaseCardPaymentMethod();
241241

242242
this._cardPaymentMethod = {
@@ -251,8 +251,8 @@ export default class GooglePayPaymentProcessor {
251251
allowedPaymentMethods: [this._cardPaymentMethod],
252252
transactionInfo: this._gateway.getTransactionInfo(),
253253
merchantInfo: this._gateway.getMerchantInfo(),
254-
...(await this._gateway.getRequiredData()),
255-
callbackIntents: this._gateway.getCallbackIntents(),
254+
...(await this._gateway.getRequiredData(shouldRequestShipping)),
255+
callbackIntents: this._gateway.getCallbackIntents(shouldRequestShipping),
256256
offerInfo: this._gateway.getAppliedCoupons(),
257257
};
258258
this._isReadyToPayRequest = {

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

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

153153
// TODO: Dispatch Widget Actions
154154
try {
155-
await this._googlePayPaymentProcessor.initializeWidget();
155+
await this._googlePayPaymentProcessor.initializeWidget(false);
156156
await this._interactWithPaymentSheet();
157157
} catch (error) {
158158
let err: unknown = error;

0 commit comments

Comments
 (0)