Skip to content

Commit 4baa5e6

Browse files
committed
feat(payment): PI-4492 google pay deinitialize block during paying
1 parent 45fa2f5 commit 4baa5e6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export default class GooglePayPaymentStrategy implements PaymentStrategy {
4242
private _paymentButton?: HTMLElement;
4343
private _clickListener?: (event: MouseEvent) => unknown;
4444
private _methodId?: keyof WithGooglePayPaymentInitializeOptions;
45+
private _isDeinitializationBlocked = false;
4546

4647
constructor(
4748
protected _paymentIntegrationService: PaymentIntegrationService,
@@ -112,6 +113,10 @@ export default class GooglePayPaymentStrategy implements PaymentStrategy {
112113
}
113114

114115
deinitialize(): Promise<void> {
116+
if (this._isDeinitializationBlocked) {
117+
return Promise.resolve();
118+
}
119+
115120
if (this._clickListener) {
116121
this._paymentButton?.removeEventListener('click', this._clickListener);
117122
}
@@ -174,6 +179,8 @@ export default class GooglePayPaymentStrategy implements PaymentStrategy {
174179
);
175180

176181
throw err;
182+
} finally {
183+
this._toggleBlockDeinitialization(false);
177184
}
178185

179186
onPaymentSelect?.();
@@ -183,6 +190,7 @@ export default class GooglePayPaymentStrategy implements PaymentStrategy {
183190
protected async _interactWithPaymentSheet(): Promise<void> {
184191
const response = await this._googlePayPaymentProcessor.showPaymentSheet();
185192

193+
this._toggleBlockDeinitialization(true);
186194
this._toggleLoadingIndicator(true);
187195

188196
const billingAddress =
@@ -197,6 +205,7 @@ export default class GooglePayPaymentStrategy implements PaymentStrategy {
197205
await this._paymentIntegrationService.loadCheckout();
198206
await this._paymentIntegrationService.loadPaymentMethod(this._getMethodId());
199207
this._toggleLoadingIndicator(false);
208+
this._toggleBlockDeinitialization(false);
200209
}
201210

202211
protected _getMethodId(): keyof WithGooglePayPaymentInitializeOptions {
@@ -315,6 +324,10 @@ export default class GooglePayPaymentStrategy implements PaymentStrategy {
315324
};
316325
}
317326

327+
private _toggleBlockDeinitialization(isBlocked: boolean) {
328+
this._isDeinitializationBlocked = isBlocked;
329+
}
330+
318331
private _toggleLoadingIndicator(isLoading: boolean): void {
319332
if (isLoading && this._loadingIndicatorContainer) {
320333
this._loadingIndicator.show(this._loadingIndicatorContainer);

0 commit comments

Comments
 (0)