2020-04-08 18:50:29 +03:00
|
|
|
import Renderer from './Renderer';
|
|
|
|
|
|
|
|
class CheckoutBootstap {
|
|
|
|
constructor(configurator) {
|
|
|
|
this.configurator = configurator;
|
|
|
|
}
|
|
|
|
|
|
|
|
init() {
|
2020-04-09 10:49:37 +03:00
|
|
|
if (!this.shouldRender()) {
|
2020-04-08 19:43:52 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-09 10:49:37 +03:00
|
|
|
const renderer = new Renderer(PayPalCommerceGateway.button.wrapper);
|
2020-04-09 11:54:19 +03:00
|
|
|
const toggleButtons = () => {
|
2020-04-08 18:50:29 +03:00
|
|
|
const currentPaymentMethod = jQuery(
|
|
|
|
'input[name="payment_method"]:checked').val();
|
|
|
|
|
|
|
|
if (currentPaymentMethod !== 'ppcp-gateway') {
|
2020-04-09 11:49:24 +03:00
|
|
|
renderer.hideButtons();
|
2020-04-08 18:50:29 +03:00
|
|
|
jQuery('#place_order').show();
|
|
|
|
}
|
|
|
|
else {
|
2020-04-09 11:49:24 +03:00
|
|
|
renderer.showButtons();
|
2020-04-08 18:50:29 +03:00
|
|
|
jQuery('#place_order').hide();
|
|
|
|
}
|
2020-04-09 11:54:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
jQuery(document.body).on('updated_checkout', () => {
|
|
|
|
renderer.render(this.configurator.configuration());
|
|
|
|
toggleButtons();
|
|
|
|
});
|
|
|
|
|
|
|
|
jQuery(document.body).on('payment_method_selected', () => {
|
|
|
|
toggleButtons();
|
2020-04-08 18:50:29 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
renderer.render(this.configurator.configuration());
|
|
|
|
}
|
2020-04-09 10:49:37 +03:00
|
|
|
|
|
|
|
shouldRender() {
|
2020-04-09 11:54:19 +03:00
|
|
|
if (document.querySelector(
|
|
|
|
PayPalCommerceGateway.button.cancel_wrapper)) {
|
2020-04-09 10:49:37 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return document.querySelector(PayPalCommerceGateway.button.wrapper);
|
|
|
|
}
|
2020-04-08 18:50:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export default CheckoutBootstap;
|