woocommerce-paypal-payments/modules.local/ppcp-button/resources/js/modules/ContextBootstrap/CartBootstap.js

40 lines
939 B
JavaScript
Raw Normal View History

2020-04-30 15:28:48 +03:00
import CartActionHandler from '../ActionHandler/CartActionHandler';
import ErrorHandler from '../ErrorHandler';
class CartBootstrap {
constructor(gateway, renderer) {
this.gateway = gateway;
2020-04-09 12:23:44 +03:00
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(),
);
2020-04-09 12:23:44 +03:00
this.renderer.render(
this.gateway.button.wrapper,
2020-04-30 15:28:48 +03:00
this.gateway.hosted_fields.wrapper,
actionHandler.configuration(),
2020-04-09 12:23:44 +03:00
);
}
}
export default CartBootstrap;