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');
|
const gateWayBox = document.querySelector('.payment_box.payment_method_ppcp-credit-card-gateway');
|
||||||
if(! gateWayBox) {
|
if (!gateWayBox) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const oldDisplayStyle = gateWayBox.style.display;
|
const oldDisplayStyle = gateWayBox.style.display;
|
||||||
|
@ -50,8 +50,8 @@ class CreditCardRenderer {
|
||||||
|
|
||||||
const stylesRaw = window.getComputedStyle(cardNumberField);
|
const stylesRaw = window.getComputedStyle(cardNumberField);
|
||||||
let styles = {};
|
let styles = {};
|
||||||
Object.values(stylesRaw).forEach( (prop) => {
|
Object.values(stylesRaw).forEach((prop) => {
|
||||||
if (! stylesRaw[prop]) {
|
if (!stylesRaw[prop]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
styles[prop] = '' + stylesRaw[prop];
|
styles[prop] = '' + stylesRaw[prop];
|
||||||
|
@ -105,7 +105,7 @@ class CreditCardRenderer {
|
||||||
this._submit(contextConfig);
|
this._submit(contextConfig);
|
||||||
});
|
});
|
||||||
hostedFields.on('cardTypeChange', (event) => {
|
hostedFields.on('cardTypeChange', (event) => {
|
||||||
if ( ! event.cards.length ) {
|
if (!event.cards.length) {
|
||||||
this.cardValid = false;
|
this.cardValid = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -160,17 +160,17 @@ class CreditCardRenderer {
|
||||||
const buttonSelector = wrapper + ' button';
|
const buttonSelector = wrapper + ' button';
|
||||||
|
|
||||||
const gateWayBox = document.querySelector('.payment_box.payment_method_ppcp-credit-card-gateway');
|
const gateWayBox = document.querySelector('.payment_box.payment_method_ppcp-credit-card-gateway');
|
||||||
if(! gateWayBox) {
|
if (!gateWayBox) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const oldDisplayStyle = gateWayBox.style.display;
|
const oldDisplayStyle = gateWayBox.style.display;
|
||||||
gateWayBox.style.display = 'block';
|
gateWayBox.style.display = 'block';
|
||||||
|
|
||||||
const hideDccGateway = document.querySelector('#ppcp-hide-dcc');
|
const hideDccGateway = document.querySelector('#ppcp-hide-dcc');
|
||||||
if (hideDccGateway) {
|
if (hideDccGateway) {
|
||||||
hideDccGateway.parentNode.removeChild(hideDccGateway);
|
hideDccGateway.parentNode.removeChild(hideDccGateway);
|
||||||
}
|
}
|
||||||
|
|
||||||
const cardField = paypal.CardFields({
|
const cardField = paypal.CardFields({
|
||||||
createOrder: contextConfig.createOrder,
|
createOrder: contextConfig.createOrder,
|
||||||
|
@ -179,6 +179,7 @@ class CreditCardRenderer {
|
||||||
},
|
},
|
||||||
onError: function (error) {
|
onError: function (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
this.spinner.unblock();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -205,7 +206,15 @@ class CreditCardRenderer {
|
||||||
|
|
||||||
document.querySelector(buttonSelector).addEventListener("click", (event) => {
|
document.querySelector(buttonSelector).addEventListener("click", (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
cardField.submit();
|
this.spinner.block();
|
||||||
|
this.errorHandler.clear();
|
||||||
|
|
||||||
|
cardField.submit()
|
||||||
|
.catch((error) => {
|
||||||
|
this.spinner.unblock();
|
||||||
|
console.error(error)
|
||||||
|
this.errorHandler.genericError();
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -325,4 +334,5 @@ class CreditCardRenderer {
|
||||||
element.setAttribute('class', newClassName);
|
element.setAttribute('class', newClassName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CreditCardRenderer;
|
export default CreditCardRenderer;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue