mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Merge branch 'master' into issue-39-missing-spinning-wheel
This commit is contained in:
commit
8eb91d9f3f
17 changed files with 376 additions and 464 deletions
|
@ -12,7 +12,11 @@ const onApprove = (context, errorHandler, spinner) => {
|
|||
}).then((data)=>{
|
||||
spinner.unblock();
|
||||
if (!data.success) {
|
||||
errorHandler.genericError();
|
||||
if (data.data.code === 100) {
|
||||
errorHandler.message(data.data.message);
|
||||
} else {
|
||||
errorHandler.genericError();
|
||||
}
|
||||
if (typeof actions.restart !== 'undefined') {
|
||||
return actions.restart();
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ class CreditCardRenderer {
|
|||
this.defaultConfig = defaultConfig;
|
||||
this.errorHandler = errorHandler;
|
||||
this.spinner = spinner;
|
||||
this.cardValid = false;
|
||||
}
|
||||
|
||||
render(wrapper, contextConfig) {
|
||||
|
@ -29,7 +30,11 @@ class CreditCardRenderer {
|
|||
const gateWayBox = document.querySelector('.payment_box.payment_method_ppcp-credit-card-gateway');
|
||||
const oldDisplayStyle = gateWayBox.style.display;
|
||||
gateWayBox.style.display = 'block';
|
||||
document.querySelector('#ppcp-hide-dcc').parentNode.removeChild(document.querySelector('#ppcp-hide-dcc'));
|
||||
|
||||
const hideDccGateway = document.querySelector('#ppcp-hide-dcc');
|
||||
if (hideDccGateway) {
|
||||
hideDccGateway.parentNode.removeChild(hideDccGateway);
|
||||
}
|
||||
|
||||
const cardNumberField = document.querySelector('#ppcp-credit-card-gateway-card-number');
|
||||
|
||||
|
@ -94,7 +99,7 @@ class CreditCardRenderer {
|
|||
return state.fields[key].isValid;
|
||||
});
|
||||
|
||||
if (formValid) {
|
||||
if (formValid && this.cardValid) {
|
||||
|
||||
let vault = document.querySelector(wrapper + ' .ppcp-credit-card-vault') ?
|
||||
document.querySelector(wrapper + ' .ppcp-credit-card-vault').checked : false;
|
||||
|
@ -110,12 +115,21 @@ class CreditCardRenderer {
|
|||
});
|
||||
} else {
|
||||
this.spinner.unblock();
|
||||
this.errorHandler.message(this.defaultConfig.hosted_fields.labels.fields_not_valid);
|
||||
const message = ! this.cardValid ? this.defaultConfig.hosted_fields.labels.card_not_supported : this.defaultConfig.hosted_fields.labels.fields_not_valid;
|
||||
this.errorHandler.message(message);
|
||||
}
|
||||
}
|
||||
hostedFields.on('inputSubmitRequest', function () {
|
||||
submitEvent(null);
|
||||
});
|
||||
hostedFields.on('cardTypeChange', (event) => {
|
||||
if ( ! event.cards.length ) {
|
||||
this.cardValid = false;
|
||||
return;
|
||||
}
|
||||
const validCards = this.defaultConfig.hosted_fields.valid_cards;
|
||||
this.cardValid = validCards.indexOf(event.cards[0].type) !== -1;
|
||||
})
|
||||
document.querySelector(wrapper + ' button').addEventListener(
|
||||
'click',
|
||||
submitEvent
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue