From 060dedaae91bd4097dfc8e71e2b05e97289ce7a4 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Mon, 7 Oct 2024 12:29:12 +0200
Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Match=20button-manager=20o?=
=?UTF-8?q?f=20GooglePay=20and=20ApplePay?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/js/GooglepayManager.js | 36 ++++++-------------
1 file changed, 10 insertions(+), 26 deletions(-)
diff --git a/modules/ppcp-googlepay/resources/js/GooglepayManager.js b/modules/ppcp-googlepay/resources/js/GooglepayManager.js
index a6bae6c58..eb10ee90a 100644
--- a/modules/ppcp-googlepay/resources/js/GooglepayManager.js
+++ b/modules/ppcp-googlepay/resources/js/GooglepayManager.js
@@ -32,21 +32,11 @@ class GooglepayManager {
this.buttons.push( button );
- const initButton = () => {
- button.configure( this.googlePayConfig, this.transactionInfo );
- button.init();
- };
+ // Ensure googlePayConfig and transactionInfo are loaded.
+ await this.init();
- // Initialize button only if googlePayConfig and transactionInfo are already fetched.
- if ( this.googlePayConfig && this.transactionInfo ) {
- initButton();
- } else {
- await this.init();
-
- if ( this.googlePayConfig && this.transactionInfo ) {
- initButton();
- }
- }
+ button.configure( this.googlePayConfig, this.transactionInfo );
+ button.init();
} );
}
@@ -55,23 +45,17 @@ class GooglepayManager {
if ( ! this.googlePayConfig ) {
// Gets GooglePay configuration of the PayPal merchant.
this.googlePayConfig = await paypal.Googlepay().config();
+
+ if ( ! this.googlePayConfig ) {
+ console.error( 'No GooglePayConfig received during init' );
+ }
}
if ( ! this.transactionInfo ) {
this.transactionInfo = await this.fetchTransactionInfo();
- }
- if ( ! this.googlePayConfig ) {
- console.error( 'No GooglePayConfig received during init' );
- } else if ( ! this.transactionInfo ) {
- console.error( 'No transactionInfo found during init' );
- } else {
- for ( const button of this.buttons ) {
- button.configure(
- this.googlePayConfig,
- this.transactionInfo
- );
- button.init();
+ if ( ! this.transactionInfo ) {
+ console.error( 'No transactionInfo found during init' );
}
}
} catch ( error ) {