woocommerce-paypal-payments/modules.local/ppcp-button/resources/js/modules/CartBootstap.js
Mészáros Róbert 4e0a4b8edb Configure the button from the bootstrappers
This should give us the flexibility to overwrite default configuration option on context level
2020-04-10 11:10:17 +03:00

39 lines
No EOL
875 B
JavaScript

import CartActionHandler from './CartActionHandler';
import ErrorHandler from './ErrorHandler';
class CartBootstrap {
constructor(gateway, renderer) {
this.gateway = gateway;
this.renderer = renderer;
}
init() {
if (!this.shouldRender()) {
return;
}
this.render();
jQuery(document.body).on('updated_cart_totals updated_checkout', () => {
this.render();
});
}
shouldRender() {
return document.querySelector(this.gateway.button.wrapper) !== null;
}
render() {
const actionHandler = new CartActionHandler(
PayPalCommerceGateway,
new ErrorHandler(),
);
this.renderer.render(
this.gateway.button.wrapper,
actionHandler.configuration(),
);
}
}
export default CartBootstrap;