mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-03 08:37:53 +08:00
🐛 Refresh total price when checkout form changes
Applies the selected shipping costs to the Google Payment button
This commit is contained in:
parent
c382b5cee1
commit
7106413f87
1 changed files with 25 additions and 4 deletions
|
@ -128,6 +128,7 @@ class GooglepayButton extends PaymentButton {
|
|||
contextHandler
|
||||
);
|
||||
|
||||
this.init = this.init.bind( this );
|
||||
this.onPaymentAuthorized = this.onPaymentAuthorized.bind( this );
|
||||
this.onPaymentDataChanged = this.onPaymentDataChanged.bind( this );
|
||||
this.onButtonClick = this.onButtonClick.bind( this );
|
||||
|
@ -207,6 +208,17 @@ class GooglepayButton extends PaymentButton {
|
|||
return this.#transactionInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign the new transaction details to the payment button.
|
||||
*
|
||||
* @param {TransactionInfo} newTransactionInfo - Transaction details.
|
||||
*/
|
||||
set transactionInfo( newTransactionInfo ) {
|
||||
this.#transactionInfo = newTransactionInfo;
|
||||
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the button instance. Must be called before the initial `init()`.
|
||||
*
|
||||
|
@ -257,14 +269,23 @@ class GooglepayButton extends PaymentButton {
|
|||
this.isEligible = !! response.result;
|
||||
} )
|
||||
.catch( ( err ) => {
|
||||
console.error( err );
|
||||
this.error( err );
|
||||
this.isEligible = false;
|
||||
} );
|
||||
}
|
||||
|
||||
reinit() {
|
||||
super.reinit();
|
||||
this.init();
|
||||
|
||||
if ( this.contextHandler?.transactionInfo ) {
|
||||
// If possible, fetch the current transaction details from the checkout form.
|
||||
this.contextHandler.transactionInfo().then( ( transactionInfo ) => {
|
||||
this.transactionInfo = transactionInfo;
|
||||
this.init();
|
||||
} );
|
||||
} else {
|
||||
this.init();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -320,7 +341,7 @@ class GooglepayButton extends PaymentButton {
|
|||
* correct wrapper.
|
||||
*/
|
||||
addButton() {
|
||||
if ( ! this.isInitialized || ! this.paymentsClient ) {
|
||||
if ( ! this.paymentsClient ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -466,7 +487,7 @@ class GooglepayButton extends PaymentButton {
|
|||
|
||||
resolve( paymentDataRequestUpdate );
|
||||
} catch ( error ) {
|
||||
console.error( 'Error during onPaymentDataChanged:', error );
|
||||
this.error( 'Error during onPaymentDataChanged:', error );
|
||||
reject( error );
|
||||
}
|
||||
} );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue