diff --git a/modules/ppcp-blocks/resources/js/checkout-block.js b/modules/ppcp-blocks/resources/js/checkout-block.js index c6013d255..a3fa34bce 100644 --- a/modules/ppcp-blocks/resources/js/checkout-block.js +++ b/modules/ppcp-blocks/resources/js/checkout-block.js @@ -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 (