mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 14:57:26 +08:00
Fix and refactor PayNow checkout UI too
Inherit PayNowBootstrap from CheckoutBootstap, they are almost the same
This commit is contained in:
parent
9c7859bf35
commit
ebe1e84907
1 changed files with 5 additions and 74 deletions
|
@ -1,86 +1,17 @@
|
||||||
import ErrorHandler from '../ErrorHandler';
|
import CheckoutBootstap from './CheckoutBootstap'
|
||||||
import CheckoutActionHandler from '../ActionHandler/CheckoutActionHandler';
|
|
||||||
|
|
||||||
class PayNowBootstrap {
|
class PayNowBootstrap extends CheckoutBootstap {
|
||||||
constructor(gateway, renderer, messages, spinner) {
|
constructor(gateway, renderer, messages, spinner) {
|
||||||
this.gateway = gateway;
|
super(gateway, renderer, messages, spinner)
|
||||||
this.renderer = renderer;
|
|
||||||
this.messages = messages;
|
|
||||||
this.spinner = spinner;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
updateUi() {
|
||||||
|
|
||||||
this.render();
|
|
||||||
|
|
||||||
jQuery(document.body).on('updated_checkout', () => {
|
|
||||||
this.render();
|
|
||||||
});
|
|
||||||
|
|
||||||
jQuery(document.body).
|
|
||||||
on('updated_checkout payment_method_selected', () => {
|
|
||||||
this.switchBetweenPayPalandOrderButton();
|
|
||||||
});
|
|
||||||
this.switchBetweenPayPalandOrderButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldRender() {
|
|
||||||
if (document.querySelector(this.gateway.button.cancel_wrapper)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return document.querySelector(this.gateway.button.wrapper) !== null || document.querySelector(this.gateway.hosted_fields.wrapper) !== null;
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
if (!this.shouldRender()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (document.querySelector(this.gateway.hosted_fields.wrapper + '>div')) {
|
|
||||||
document.querySelector(this.gateway.hosted_fields.wrapper + '>div').setAttribute('style', '');
|
|
||||||
}
|
|
||||||
const actionHandler = new CheckoutActionHandler(
|
|
||||||
PayPalCommerceGateway,
|
|
||||||
new ErrorHandler(this.gateway.labels.error.generic),
|
|
||||||
this.spinner
|
|
||||||
);
|
|
||||||
|
|
||||||
this.renderer.render(
|
|
||||||
this.gateway.button.wrapper,
|
|
||||||
this.gateway.hosted_fields.wrapper,
|
|
||||||
actionHandler.configuration(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
switchBetweenPayPalandOrderButton() {
|
|
||||||
const urlParams = new URLSearchParams(window.location.search)
|
const urlParams = new URLSearchParams(window.location.search)
|
||||||
if (urlParams.has('change_payment_method')) {
|
if (urlParams.has('change_payment_method')) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentPaymentMethod = jQuery(
|
super.updateUi();
|
||||||
'input[name="payment_method"]:checked').val();
|
|
||||||
|
|
||||||
if (currentPaymentMethod !== 'ppcp-gateway' && currentPaymentMethod !== 'ppcp-credit-card-gateway') {
|
|
||||||
this.renderer.hideButtons(this.gateway.button.wrapper);
|
|
||||||
this.renderer.hideButtons(this.gateway.messages.wrapper);
|
|
||||||
this.renderer.hideButtons(this.gateway.hosted_fields.wrapper);
|
|
||||||
jQuery('#place_order').show();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
jQuery('#place_order').hide();
|
|
||||||
if (currentPaymentMethod === 'ppcp-gateway') {
|
|
||||||
this.renderer.showButtons(this.gateway.button.wrapper);
|
|
||||||
this.renderer.showButtons(this.gateway.messages.wrapper);
|
|
||||||
this.messages.render();
|
|
||||||
this.renderer.hideButtons(this.gateway.hosted_fields.wrapper);
|
|
||||||
}
|
|
||||||
if (currentPaymentMethod === 'ppcp-credit-card-gateway') {
|
|
||||||
this.renderer.hideButtons(this.gateway.button.wrapper);
|
|
||||||
this.renderer.hideButtons(this.gateway.messages.wrapper);
|
|
||||||
this.renderer.showButtons(this.gateway.hosted_fields.wrapper);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue