Fixes for Checkout authorization failure exception handling

This commit is contained in:
David Bomba 2022-12-20 12:41:34 +11:00
parent af0b459f94
commit 6f0f0a4ffa

View File

@ -124,18 +124,20 @@ class CreditCard implements MethodInterface
} }
} catch (CheckoutApiException $e) { } catch (CheckoutApiException $e) {
// API error // API error
$request_id = $e->request_id; $request_id = $e->request_id ?: '';
$http_status_code = $e->http_status_code; $http_status_code = $e->http_status_code ?: '';
$error_details = $e->error_details; $error_details = $e->error_details;
if(is_array($error_details)) { if(is_array($error_details)) {
$error_details = end($e->error_details['error_codes']); $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) { } catch (CheckoutArgumentException $e) {
// Bad arguments // Bad arguments
@ -145,9 +147,9 @@ class CreditCard implements MethodInterface
$error_details = end($e->error_details['error_codes']); $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) { } catch (CheckoutAuthorizationException $e) {
// Bad Invalid authorization // Bad Invalid authorization
@ -157,9 +159,9 @@ class CreditCard implements MethodInterface
$error_details = end($e->error_details['error_codes']); $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);
} }
} }