mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Update Pay Later amount on the cart page when cart total changes
This commit is contained in:
parent
74611528b5
commit
b6a85f0d13
3 changed files with 18 additions and 3 deletions
|
@ -154,6 +154,7 @@ const bootstrap = () => {
|
|||
const cartBootstrap = new CartBootstrap(
|
||||
PayPalCommerceGateway,
|
||||
renderer,
|
||||
messageRenderer,
|
||||
errorHandler,
|
||||
);
|
||||
|
||||
|
|
|
@ -2,10 +2,12 @@ import CartActionHandler from '../ActionHandler/CartActionHandler';
|
|||
import {setVisible} from "../Helper/Hiding";
|
||||
|
||||
class CartBootstrap {
|
||||
constructor(gateway, renderer, errorHandler) {
|
||||
constructor(gateway, renderer, messages, errorHandler) {
|
||||
this.gateway = gateway;
|
||||
this.renderer = renderer;
|
||||
this.messages = messages;
|
||||
this.errorHandler = errorHandler;
|
||||
this.lastAmount = this.gateway.messages.amount;
|
||||
}
|
||||
|
||||
init() {
|
||||
|
@ -31,11 +33,16 @@ class CartBootstrap {
|
|||
return;
|
||||
}
|
||||
|
||||
const newParams = result.data;
|
||||
const newParams = result.data.url_params;
|
||||
const reloadRequired = this.gateway.url_params.intent !== newParams.intent;
|
||||
|
||||
// TODO: should reload the script instead
|
||||
setVisible(this.gateway.button.wrapper, !reloadRequired)
|
||||
|
||||
if (this.lastAmount !== result.data.amount) {
|
||||
this.lastAmount = result.data.amount;
|
||||
this.messages.renderWithAmount(this.lastAmount);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -61,6 +68,8 @@ class CartBootstrap {
|
|||
this.renderer.render(
|
||||
actionHandler.configuration()
|
||||
);
|
||||
|
||||
this.messages.renderWithAmount(this.lastAmount);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,12 @@ class CartScriptParamsEndpoint implements EndpointInterface {
|
|||
try {
|
||||
$script_data = $this->smart_button->script_data();
|
||||
|
||||
wp_send_json_success( $script_data['url_params'] );
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'url_params' => $script_data['url_params'],
|
||||
'amount' => WC()->cart->get_total( 'raw' ),
|
||||
)
|
||||
);
|
||||
|
||||
return true;
|
||||
} catch ( Throwable $error ) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue