diff --git a/app/PaymentDrivers/CheckoutCom/CreditCard.php b/app/PaymentDrivers/CheckoutCom/CreditCard.php index 1ada04574b..8918f7eaee 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); } }