mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Add error handling (WIP)
This commit is contained in:
parent
822485f782
commit
b2a8c607af
1 changed files with 22 additions and 12 deletions
|
@ -35,7 +35,7 @@ class CreditCardRenderer {
|
|||
}
|
||||
|
||||
const gateWayBox = document.querySelector('.payment_box.payment_method_ppcp-credit-card-gateway');
|
||||
if(! gateWayBox) {
|
||||
if (!gateWayBox) {
|
||||
return
|
||||
}
|
||||
const oldDisplayStyle = gateWayBox.style.display;
|
||||
|
@ -50,8 +50,8 @@ class CreditCardRenderer {
|
|||
|
||||
const stylesRaw = window.getComputedStyle(cardNumberField);
|
||||
let styles = {};
|
||||
Object.values(stylesRaw).forEach( (prop) => {
|
||||
if (! stylesRaw[prop]) {
|
||||
Object.values(stylesRaw).forEach((prop) => {
|
||||
if (!stylesRaw[prop]) {
|
||||
return;
|
||||
}
|
||||
styles[prop] = '' + stylesRaw[prop];
|
||||
|
@ -105,7 +105,7 @@ class CreditCardRenderer {
|
|||
this._submit(contextConfig);
|
||||
});
|
||||
hostedFields.on('cardTypeChange', (event) => {
|
||||
if ( ! event.cards.length ) {
|
||||
if (!event.cards.length) {
|
||||
this.cardValid = false;
|
||||
return;
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ class CreditCardRenderer {
|
|||
const buttonSelector = wrapper + ' button';
|
||||
|
||||
const gateWayBox = document.querySelector('.payment_box.payment_method_ppcp-credit-card-gateway');
|
||||
if(! gateWayBox) {
|
||||
if (!gateWayBox) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -179,6 +179,7 @@ class CreditCardRenderer {
|
|||
},
|
||||
onError: function (error) {
|
||||
console.error(error)
|
||||
this.spinner.unblock();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -205,7 +206,15 @@ class CreditCardRenderer {
|
|||
|
||||
document.querySelector(buttonSelector).addEventListener("click", (event) => {
|
||||
event.preventDefault();
|
||||
cardField.submit();
|
||||
this.spinner.block();
|
||||
this.errorHandler.clear();
|
||||
|
||||
cardField.submit()
|
||||
.catch((error) => {
|
||||
this.spinner.unblock();
|
||||
console.error(error)
|
||||
this.errorHandler.genericError();
|
||||
})
|
||||
});
|
||||
|
||||
return;
|
||||
|
@ -325,4 +334,5 @@ class CreditCardRenderer {
|
|||
element.setAttribute('class', newClassName);
|
||||
}
|
||||
}
|
||||
|
||||
export default CreditCardRenderer;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue