add generic error message for button

This commit is contained in:
David Remer 2020-07-28 08:05:18 +03:00
parent c98e10d2a1
commit 1ea7d9968a
12 changed files with 25 additions and 12 deletions

View file

@ -7,7 +7,7 @@ import ErrorHandler from './modules/ErrorHandler';
import CreditCardRenderer from "./modules/Renderer/CreditCardRenderer";
const bootstrap = () => {
const errorHandler = new ErrorHandler();
const errorHandler = new ErrorHandler(PayPalCommerceGateway.labels.error.generic);
const creditCardRenderer = new CreditCardRenderer(PayPalCommerceGateway, errorHandler);
const renderer = new Renderer(creditCardRenderer, PayPalCommerceGateway);
const context = PayPalCommerceGateway.context;

View file

@ -35,7 +35,7 @@ class CartActionHandler {
createOrder,
onApprove: onApprove(this, this.errorHandler),
onError: (error) => {
this.errorHandler.message(error);
this.errorHandler.genericError();
}
};
}

View file

@ -34,7 +34,7 @@ class CheckoutActionHandler {
createOrder,
onApprove:onApprove(this, this.errorHandler),
onError: (error) => {
this.errorHandler.message(error);
this.errorHandler.genericError();
}
}
}

View file

@ -37,7 +37,7 @@ class SingleProductActionHandler {
createOrder: this.createOrder(),
onApprove: onApprove(this, this.errorHandler),
onError: (error) => {
this.errorHandler.message(error);
this.errorHandler.genericError();
}
}
}

View file

@ -28,7 +28,7 @@ class CartBootstrap {
render() {
const actionHandler = new CartActionHandler(
PayPalCommerceGateway,
new ErrorHandler(),
new ErrorHandler(this.gateway.labels.error.generic),
);
this.renderer.render(

View file

@ -36,7 +36,7 @@ class CheckoutBootstap {
render() {
const actionHandler = new CheckoutActionHandler(
PayPalCommerceGateway,
new ErrorHandler(),
new ErrorHandler(this.gateway.labels.error.generic),
);
this.renderer.render(

View file

@ -12,7 +12,7 @@ class MiniCartBootstap {
this.actionHandler = new CartActionHandler(
PayPalCommerceGateway,
new ErrorHandler(),
new ErrorHandler(this.gateway.labels.error.generic),
);
this.render();

View file

@ -41,7 +41,7 @@ class SingleProductBootstap {
this.renderer.hideButtons(this.gateway.hosted_fields.wrapper);
},
document.querySelector('form.cart'),
new ErrorHandler(),
new ErrorHandler(this.gateway.labels.error.generic),
);
this.renderer.render(

View file

@ -1,10 +1,16 @@
class ErrorHandler {
constructor()
constructor(genericErrorText)
{
this.genericErrorText = genericErrorText;
this.wrapper = document.querySelector('.woocommerce-notices-wrapper');
}
genericError() {
this.clear();
this.message(this.genericErrorText)
}
message(text)
{
this.wrapper.classList.add('woocommerce-error');

View file

@ -10,8 +10,10 @@ const onApprove = (context, errorHandler) => {
return res.json();
}).then((data)=>{
if (!data.success) {
errorHandler.message(data.data);
return actions.restart();
errorHandler.genericError();
return actions.restart().catch(err => {
errorHandler.genericError();
});;
}
location.href = context.config.redirect;
});

View file

@ -10,7 +10,7 @@ const onApprove = (context, errorHandler) => {
return res.json();
}).then((data)=>{
if (!data.success) {
errorHandler.message(data.data);
errorHandler.genericError();
if (typeof actions.restart !== 'undefined') {
return actions.restart();
}

View file

@ -352,6 +352,11 @@ class SmartButton implements SmartButtonInterface
),
],
],
'labels' => [
'error' => [
'generic' => __('Something went wrong. Please try again or choose another payment source', 'woocommerce-paypal-commerce-gateway'),
]
]
];
$this->requestData->dequeueNonceFix();