mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
♻️ Match button-manager of GooglePay and ApplePay
This commit is contained in:
parent
c2d5c8f3c5
commit
060dedaae9
1 changed files with 10 additions and 26 deletions
|
@ -32,21 +32,11 @@ class GooglepayManager {
|
||||||
|
|
||||||
this.buttons.push( button );
|
this.buttons.push( button );
|
||||||
|
|
||||||
const initButton = () => {
|
// Ensure googlePayConfig and transactionInfo are loaded.
|
||||||
button.configure( this.googlePayConfig, this.transactionInfo );
|
await this.init();
|
||||||
button.init();
|
|
||||||
};
|
|
||||||
|
|
||||||
// Initialize button only if googlePayConfig and transactionInfo are already fetched.
|
button.configure( this.googlePayConfig, this.transactionInfo );
|
||||||
if ( this.googlePayConfig && this.transactionInfo ) {
|
button.init();
|
||||||
initButton();
|
|
||||||
} else {
|
|
||||||
await this.init();
|
|
||||||
|
|
||||||
if ( this.googlePayConfig && this.transactionInfo ) {
|
|
||||||
initButton();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,23 +45,17 @@ class GooglepayManager {
|
||||||
if ( ! this.googlePayConfig ) {
|
if ( ! this.googlePayConfig ) {
|
||||||
// Gets GooglePay configuration of the PayPal merchant.
|
// Gets GooglePay configuration of the PayPal merchant.
|
||||||
this.googlePayConfig = await paypal.Googlepay().config();
|
this.googlePayConfig = await paypal.Googlepay().config();
|
||||||
|
|
||||||
|
if ( ! this.googlePayConfig ) {
|
||||||
|
console.error( 'No GooglePayConfig received during init' );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! this.transactionInfo ) {
|
if ( ! this.transactionInfo ) {
|
||||||
this.transactionInfo = await this.fetchTransactionInfo();
|
this.transactionInfo = await this.fetchTransactionInfo();
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! this.googlePayConfig ) {
|
if ( ! this.transactionInfo ) {
|
||||||
console.error( 'No GooglePayConfig received during init' );
|
console.error( 'No transactionInfo found 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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch ( error ) {
|
} catch ( error ) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue