mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
add generic error message for button
This commit is contained in:
parent
c98e10d2a1
commit
1ea7d9968a
12 changed files with 25 additions and 12 deletions
|
@ -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;
|
||||
|
|
|
@ -35,7 +35,7 @@ class CartActionHandler {
|
|||
createOrder,
|
||||
onApprove: onApprove(this, this.errorHandler),
|
||||
onError: (error) => {
|
||||
this.errorHandler.message(error);
|
||||
this.errorHandler.genericError();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class CheckoutActionHandler {
|
|||
createOrder,
|
||||
onApprove:onApprove(this, this.errorHandler),
|
||||
onError: (error) => {
|
||||
this.errorHandler.message(error);
|
||||
this.errorHandler.genericError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ class SingleProductActionHandler {
|
|||
createOrder: this.createOrder(),
|
||||
onApprove: onApprove(this, this.errorHandler),
|
||||
onError: (error) => {
|
||||
this.errorHandler.message(error);
|
||||
this.errorHandler.genericError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ class CartBootstrap {
|
|||
render() {
|
||||
const actionHandler = new CartActionHandler(
|
||||
PayPalCommerceGateway,
|
||||
new ErrorHandler(),
|
||||
new ErrorHandler(this.gateway.labels.error.generic),
|
||||
);
|
||||
|
||||
this.renderer.render(
|
||||
|
|
|
@ -36,7 +36,7 @@ class CheckoutBootstap {
|
|||
render() {
|
||||
const actionHandler = new CheckoutActionHandler(
|
||||
PayPalCommerceGateway,
|
||||
new ErrorHandler(),
|
||||
new ErrorHandler(this.gateway.labels.error.generic),
|
||||
);
|
||||
|
||||
this.renderer.render(
|
||||
|
|
|
@ -12,7 +12,7 @@ class MiniCartBootstap {
|
|||
|
||||
this.actionHandler = new CartActionHandler(
|
||||
PayPalCommerceGateway,
|
||||
new ErrorHandler(),
|
||||
new ErrorHandler(this.gateway.labels.error.generic),
|
||||
);
|
||||
this.render();
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue