mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +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,
|
||||
shippingData,
|
||||
}) => {
|
||||
const {onPaymentSetup} = eventRegistration;
|
||||
const {onPaymentSetup, onCheckoutAfterProcessingWithError} = eventRegistration;
|
||||
const {responseTypes} = emitResponse;
|
||||
|
||||
const [paypalOrder, setPaypalOrder] = useState(null);
|
||||
|
@ -205,6 +205,23 @@ const PayPalComponent = ({
|
|||
};
|
||||
}, [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) {
|
||||
return (
|
||||
<div dangerouslySetInnerHTML={{__html: config.scriptData.continuation.cancel.html}}>
|
||||
|
|
|
@ -81,8 +81,9 @@ trait ProcessPaymentTrait {
|
|||
wc_add_notice( $error->getMessage(), 'error' );
|
||||
|
||||
return array(
|
||||
'result' => 'failure',
|
||||
'redirect' => wc_get_checkout_url(),
|
||||
'result' => 'failure',
|
||||
'redirect' => wc_get_checkout_url(),
|
||||
'errorMessage' => $error->getMessage(),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue