From 6f0f0a4ffaf025b995a10ed245823fed7bb18cfb Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 20 Dec 2022 12:41:34 +1100 Subject: [PATCH] Fixes for Checkout authorization failure exception handling --- app/PaymentDrivers/CheckoutCom/CreditCard.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/PaymentDrivers/CheckoutCom/CreditCard.php b/app/PaymentDrivers/CheckoutCom/CreditCard.php index 1ada04574b5e..8918f7eaee53 100644 --- a/app/PaymentDrivers/CheckoutCom/CreditCard.php +++ b/app/PaymentDrivers/CheckoutCom/CreditCard.php @@ -124,18 +124,20 @@ class CreditCard implements MethodInterface } } catch (CheckoutApiException $e) { // API error - $request_id = $e->request_id; - $http_status_code = $e->http_status_code; + $request_id = $e->request_id ?: ''; + $http_status_code = $e->http_status_code ?: ''; $error_details = $e->error_details; if(is_array($error_details)) { $error_details = end($e->error_details['error_codes']); } - $human_exception = $error_details ? new \Exception($error_details, 400) : $e; + $human_exception = $error_details ? $error_details : $e->getMessage(); + $human_exception = "{$human_exception} - Request ID: {$request_id}"; + + throw new PaymentFailed($human_exception, $http_status_code); - throw new PaymentFailed($human_exception); } catch (CheckoutArgumentException $e) { // Bad arguments @@ -145,9 +147,9 @@ class CreditCard implements MethodInterface $error_details = end($e->error_details['error_codes']); } - $human_exception = $error_details ? new \Exception($error_details, 400) : $e; + $human_exception = $error_details ? $error_details : $e->getMessage(); - throw new PaymentFailed($human_exception); + throw new PaymentFailed($human_exception, 422); } catch (CheckoutAuthorizationException $e) { // Bad Invalid authorization @@ -157,9 +159,9 @@ class CreditCard implements MethodInterface $error_details = end($e->error_details['error_codes']); } - $human_exception = $error_details ? new \Exception($error_details, 400) : $e; + $human_exception = $error_details ? $error_details : $e->getMessage(); - throw new PaymentFailed($human_exception); + throw new PaymentFailed($human_exception, 401); } }