mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +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
|
contextHandler
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.init = this.init.bind( this );
|
||||||
this.onPaymentAuthorized = this.onPaymentAuthorized.bind( this );
|
this.onPaymentAuthorized = this.onPaymentAuthorized.bind( this );
|
||||||
this.onPaymentDataChanged = this.onPaymentDataChanged.bind( this );
|
this.onPaymentDataChanged = this.onPaymentDataChanged.bind( this );
|
||||||
this.onButtonClick = this.onButtonClick.bind( this );
|
this.onButtonClick = this.onButtonClick.bind( this );
|
||||||
|
@ -207,6 +208,17 @@ class GooglepayButton extends PaymentButton {
|
||||||
return this.#transactionInfo;
|
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()`.
|
* Configures the button instance. Must be called before the initial `init()`.
|
||||||
*
|
*
|
||||||
|
@ -257,14 +269,23 @@ class GooglepayButton extends PaymentButton {
|
||||||
this.isEligible = !! response.result;
|
this.isEligible = !! response.result;
|
||||||
} )
|
} )
|
||||||
.catch( ( err ) => {
|
.catch( ( err ) => {
|
||||||
console.error( err );
|
this.error( err );
|
||||||
this.isEligible = false;
|
this.isEligible = false;
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
reinit() {
|
reinit() {
|
||||||
super.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.
|
* correct wrapper.
|
||||||
*/
|
*/
|
||||||
addButton() {
|
addButton() {
|
||||||
if ( ! this.isInitialized || ! this.paymentsClient ) {
|
if ( ! this.paymentsClient ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -466,7 +487,7 @@ class GooglepayButton extends PaymentButton {
|
||||||
|
|
||||||
resolve( paymentDataRequestUpdate );
|
resolve( paymentDataRequestUpdate );
|
||||||
} catch ( error ) {
|
} catch ( error ) {
|
||||||
console.error( 'Error during onPaymentDataChanged:', error );
|
this.error( 'Error during onPaymentDataChanged:', error );
|
||||||
reject( error );
|
reject( error );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue