Teardown hosted fields on re-render

This commit is contained in:
Alex P 2021-09-07 17:55:39 +03:00
parent 93f0667075
commit 10d7574e22

View file

@ -8,6 +8,7 @@ class CreditCardRenderer {
this.spinner = spinner;
this.cardValid = false;
this.formValid = false;
this.currentHostedFieldsInstance = null;
}
render(wrapper, contextConfig) {
@ -31,6 +32,12 @@ class CreditCardRenderer {
return;
}
if (this.currentHostedFieldsInstance) {
this.currentHostedFieldsInstance.teardown()
.catch(err => console.error(`Hosted fields teardown error: ${err}`));
this.currentHostedFieldsInstance = null;
}
const gateWayBox = document.querySelector('.payment_box.payment_method_ppcp-credit-card-gateway');
const oldDisplayStyle = gateWayBox.style.display;
gateWayBox.style.display = 'block';
@ -92,6 +99,7 @@ class CreditCardRenderer {
}
}
}).then(hostedFields => {
this.currentHostedFieldsInstance = hostedFields;
const submitEvent = (event) => {
this.spinner.block();
if (event) {