From f454c602921a3f4042da36f0d243a268cd9a59fe Mon Sep 17 00:00:00 2001 From: dinamiko Date: Fri, 28 Jan 2022 17:40:44 +0100 Subject: [PATCH] Display PayPal exception issues (WIP) --- .../ppcp-api-client/src/Exception/PayPalApiException.php | 4 ++++ modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/modules/ppcp-api-client/src/Exception/PayPalApiException.php b/modules/ppcp-api-client/src/Exception/PayPalApiException.php index 6f227d001..fca6f08c3 100644 --- a/modules/ppcp-api-client/src/Exception/PayPalApiException.php +++ b/modules/ppcp-api-client/src/Exception/PayPalApiException.php @@ -110,4 +110,8 @@ class PayPalApiException extends RuntimeException { } return false; } + + public function issues(): array { + return $this->response->issues ?? array(); + } } diff --git a/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php b/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php index adb0cd6f5..c8f88461f 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php +++ b/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php @@ -298,6 +298,12 @@ trait ProcessPaymentTrait { ); } + $error_message = $error->getMessage(); + if($error->issues()) { + $error_message = $error->issues()[0]->issue . ' ' . $error->issues()[0]->description; + } + wc_add_notice($error_message, 'error'); + $this->session_handler->destroy_session_data(); } catch ( RuntimeException $error ) { $this->handle_failure( $wc_order, $error );