split up where to show the credit cards

This commit is contained in:
David Remer 2020-04-30 16:30:23 +03:00
parent bc59efeb3c
commit 9938103edb
9 changed files with 115 additions and 36 deletions

View file

@ -20,7 +20,9 @@ class CartBootstrap {
}
shouldRender() {
return document.querySelector(this.gateway.button.wrapper) !== null;
return document.querySelector(this.gateway.button.wrapper) !==
null || document.querySelector(this.gateway.hosted_fields.wrapper) !==
null;
}
render() {

View file

@ -5,9 +5,15 @@ class MiniCartBootstap {
constructor(gateway, renderer) {
this.gateway = gateway;
this.renderer = renderer;
this.actionHandler = null;
}
init() {
this.actionHandler = new CartActionHandler(
PayPalCommerceGateway,
new ErrorHandler(),
);
this.render();
jQuery(document.body).on('wc_fragments_loaded wc_fragments_refreshed', () => {
@ -17,7 +23,8 @@ class MiniCartBootstap {
shouldRender() {
return document.querySelector(this.gateway.button.mini_cart_wrapper) !==
null;
null || document.querySelector(this.gateway.hosted_fields.mini_cart_wrapper) !==
null;
}
render() {
@ -25,15 +32,10 @@ class MiniCartBootstap {
return;
}
const actionHandler = new CartActionHandler(
PayPalCommerceGateway,
new ErrorHandler(),
);
this.renderer.render(
this.gateway.button.mini_cart_wrapper,
null,
actionHandler.configuration()
this.gateway.hosted_fields.mini_cart_wrapper,
this.actionHandler.configuration()
);
}
}

View file

@ -21,7 +21,7 @@ class SingleProductBootstap {
return false;
}
return document.querySelector(this.gateway.button.wrapper) !== null;
return true;
}
render() {

View file

@ -20,15 +20,15 @@ class CreditCardRenderer {
createOrder: contextConfig.createOrder,
fields: {
number: {
selector: '#ppcp-credit-card',
selector: wrapper + ' .ppcp-credit-card',
placeholder: this.defaultConfig.hosted_fields.labels.credit_card_number,
},
cvv: {
selector: '#ppcp-cvv',
selector: wrapper + ' .ppcp-cvv',
placeholder: this.defaultConfig.hosted_fields.labels.cvv,
},
expirationDate: {
selector: '#ppcp-expiration-date',
selector: wrapper + ' .ppcp-expiration-date',
placeholder: this.defaultConfig.hosted_fields.labels.mm_yyyy,
}
}

View file

@ -5,7 +5,13 @@ class Renderer {
}
render(wrapper, hostedFieldsWrapper, contextConfig) {
if (this.isAlreadyRendered(wrapper)) {
this.renderButtons(wrapper, contextConfig);
this.creditCardRenderer.render(hostedFieldsWrapper, contextConfig);
}
renderButtons(wrapper, contextConfig) {
if (! document.querySelector(wrapper) || this.isAlreadyRendered(wrapper)) {
return;
}
@ -14,9 +20,7 @@ class Renderer {
style,
...contextConfig,
}).render(wrapper);
this.creditCardRenderer.render(hostedFieldsWrapper, contextConfig);
}
}
isAlreadyRendered(wrapper) {
return document.querySelector(wrapper).hasChildNodes();