mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 10:55:00 +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 );
|
||||
|
||||
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 ) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue