mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-31 06:52:50 +08:00
Handle payment errors in blocks
This commit is contained in:
parent
fe08c2d4f4
commit
2df970a74a
2 changed files with 21 additions and 3 deletions
|
@ -17,7 +17,7 @@ const PayPalComponent = ({
|
||||||
activePaymentMethod,
|
activePaymentMethod,
|
||||||
shippingData,
|
shippingData,
|
||||||
}) => {
|
}) => {
|
||||||
const {onPaymentSetup} = eventRegistration;
|
const {onPaymentSetup, onCheckoutAfterProcessingWithError} = eventRegistration;
|
||||||
const {responseTypes} = emitResponse;
|
const {responseTypes} = emitResponse;
|
||||||
|
|
||||||
const [paypalOrder, setPaypalOrder] = useState(null);
|
const [paypalOrder, setPaypalOrder] = useState(null);
|
||||||
|
@ -205,6 +205,23 @@ const PayPalComponent = ({
|
||||||
};
|
};
|
||||||
}, [onPaymentSetup, paypalOrder, activePaymentMethod]);
|
}, [onPaymentSetup, paypalOrder, activePaymentMethod]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const unsubscribe = onCheckoutAfterProcessingWithError(({ processingResponse }) => {
|
||||||
|
if (onClose) {
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
if (processingResponse?.paymentDetails?.errorMessage) {
|
||||||
|
return {
|
||||||
|
type: emitResponse.responseTypes.ERROR,
|
||||||
|
message: processingResponse.paymentDetails.errorMessage,
|
||||||
|
messageContext: config.scriptData.continuation ? emitResponse.noticeContexts.PAYMENTS : emitResponse.noticeContexts.EXPRESS_PAYMENTS,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
return unsubscribe;
|
||||||
|
}, [onCheckoutAfterProcessingWithError, onClose]);
|
||||||
|
|
||||||
if (config.scriptData.continuation) {
|
if (config.scriptData.continuation) {
|
||||||
return (
|
return (
|
||||||
<div dangerouslySetInnerHTML={{__html: config.scriptData.continuation.cancel.html}}>
|
<div dangerouslySetInnerHTML={{__html: config.scriptData.continuation.cancel.html}}>
|
||||||
|
|
|
@ -81,8 +81,9 @@ trait ProcessPaymentTrait {
|
||||||
wc_add_notice( $error->getMessage(), 'error' );
|
wc_add_notice( $error->getMessage(), 'error' );
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'result' => 'failure',
|
'result' => 'failure',
|
||||||
'redirect' => wc_get_checkout_url(),
|
'redirect' => wc_get_checkout_url(),
|
||||||
|
'errorMessage' => $error->getMessage(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue