2020-04-08 18:50:29 +03:00
|
|
|
class CheckoutBootstap {
|
2020-04-09 12:56:05 +03:00
|
|
|
constructor(gateway, renderer, configurator) {
|
|
|
|
this.gateway = gateway;
|
2020-04-09 12:23:44 +03:00
|
|
|
this.renderer = renderer;
|
2020-04-08 18:50:29 +03:00
|
|
|
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 12:56:05 +03:00
|
|
|
const buttonWrapper = this.gateway.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 12:56:05 +03:00
|
|
|
this.renderer.hideButtons(buttonWrapper);
|
2020-04-08 18:50:29 +03:00
|
|
|
jQuery('#place_order').show();
|
|
|
|
}
|
|
|
|
else {
|
2020-04-09 12:56:05 +03:00
|
|
|
this.renderer.showButtons(buttonWrapper);
|
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', () => {
|
2020-04-09 12:23:44 +03:00
|
|
|
this.renderer.render(
|
2020-04-09 12:56:05 +03:00
|
|
|
buttonWrapper,
|
2020-04-09 12:23:44 +03:00
|
|
|
this.configurator.configuration(),
|
|
|
|
);
|
2020-04-09 11:54:19 +03:00
|
|
|
toggleButtons();
|
|
|
|
});
|
|
|
|
|
|
|
|
jQuery(document.body).on('payment_method_selected', () => {
|
|
|
|
toggleButtons();
|
2020-04-08 18:50:29 +03:00
|
|
|
});
|
|
|
|
|
2020-04-09 12:23:44 +03:00
|
|
|
this.renderer.render(
|
2020-04-09 12:56:05 +03:00
|
|
|
buttonWrapper,
|
2020-04-09 12:23:44 +03:00
|
|
|
this.configurator.configuration(),
|
|
|
|
);
|
2020-04-08 18:50:29 +03:00
|
|
|
}
|
2020-04-09 10:49:37 +03:00
|
|
|
|
|
|
|
shouldRender() {
|
2020-04-09 12:56:05 +03:00
|
|
|
if (document.querySelector(this.gateway.button.cancel_wrapper)) {
|
2020-04-09 10:49:37 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-09 12:56:05 +03:00
|
|
|
return document.querySelector(this.gateway.button.wrapper);
|
2020-04-09 10:49:37 +03:00
|
|
|
}
|
2020-04-08 18:50:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export default CheckoutBootstap;
|