mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 14:14:31 -04:00
Improve error handling with Checkout Payment Gateway
This commit is contained in:
parent
f6ab1c0f0f
commit
e43d638d10
@ -130,13 +130,38 @@ class CreditCard implements MethodInterface
|
||||
$http_status_code = $e->http_status_code;
|
||||
$error_details = $e->error_details;
|
||||
|
||||
throw new PaymentFailed($e->getMessage());
|
||||
if(is_array($error_details)) {
|
||||
$error_details = end($e->error_details['error_codes']);
|
||||
}
|
||||
|
||||
$human_exception = $error_details ? new \Exception($error_details, 400) : $e;
|
||||
|
||||
|
||||
throw new PaymentFailed($human_exception);
|
||||
} catch (CheckoutArgumentException $e) {
|
||||
// Bad arguments
|
||||
throw new PaymentFailed($e->getMessage());
|
||||
|
||||
$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;
|
||||
|
||||
throw new PaymentFailed($human_exception);
|
||||
} catch (CheckoutAuthorizationException $e) {
|
||||
// Bad Invalid authorization
|
||||
throw new PaymentFailed($e->getMessage());
|
||||
|
||||
$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;
|
||||
|
||||
throw new PaymentFailed($human_exception);
|
||||
}
|
||||
}
|
||||
|
||||
@ -230,7 +255,6 @@ class CreditCard implements MethodInterface
|
||||
}
|
||||
|
||||
try {
|
||||
// $response = $this->checkout->gateway->payments()->request($payment);
|
||||
|
||||
$response = $this->checkout->gateway->getPaymentsClient()->requestPayment($paymentRequest);
|
||||
|
||||
@ -265,21 +289,71 @@ class CreditCard implements MethodInterface
|
||||
$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']);
|
||||
}
|
||||
|
||||
$this->checkout->unWindGatewayFees($this->checkout->payment_hash);
|
||||
|
||||
return $this->checkout->processInternallyFailedPayment($this->checkout, $e);
|
||||
$human_exception = $error_details ? new \Exception($error_details, 400) : $e;
|
||||
|
||||
SystemLogger::dispatch(
|
||||
$human_exception->getMessage(),
|
||||
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
||||
SystemLog::EVENT_GATEWAY_ERROR,
|
||||
SystemLog::TYPE_CHECKOUT,
|
||||
$this->checkout->client,
|
||||
$this->checkout->client->company,
|
||||
);
|
||||
|
||||
return $this->checkout->processInternallyFailedPayment($this->checkout, $human_exception);
|
||||
} catch (CheckoutArgumentException $e) {
|
||||
// Bad arguments
|
||||
|
||||
$error_details = $e->error_details;
|
||||
|
||||
if(is_array($error_details)) {
|
||||
$error_details = end($e->error_details['error_codes']);
|
||||
}
|
||||
|
||||
$this->checkout->unWindGatewayFees($this->checkout->payment_hash);
|
||||
|
||||
return $this->checkout->processInternallyFailedPayment($this->checkout, $e);
|
||||
$human_exception = $error_details ? new \Exception($error_details, 400) : $e;
|
||||
|
||||
SystemLogger::dispatch(
|
||||
$human_exception->getMessage(),
|
||||
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
||||
SystemLog::EVENT_GATEWAY_ERROR,
|
||||
SystemLog::TYPE_CHECKOUT,
|
||||
$this->checkout->client,
|
||||
$this->checkout->client->company,
|
||||
);
|
||||
|
||||
return $this->checkout->processInternallyFailedPayment($this->checkout, $human_exception);
|
||||
} catch (CheckoutAuthorizationException $e) {
|
||||
// Bad Invalid authorization
|
||||
|
||||
$error_details = $e->error_details;
|
||||
|
||||
if(is_array($error_details)) {
|
||||
$error_details = end($e->error_details['error_codes']);
|
||||
}
|
||||
|
||||
$this->checkout->unWindGatewayFees($this->checkout->payment_hash);
|
||||
|
||||
return $this->checkout->processInternallyFailedPayment($this->checkout, $e);
|
||||
$human_exception = $error_details ? new \Exception($error_details, 400) : $e;
|
||||
|
||||
|
||||
SystemLogger::dispatch(
|
||||
$human_exception->getMessage(),
|
||||
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
||||
SystemLog::EVENT_GATEWAY_ERROR,
|
||||
SystemLog::TYPE_CHECKOUT,
|
||||
$this->checkout->client,
|
||||
$this->checkout->client->company,
|
||||
);
|
||||
|
||||
return $this->checkout->processInternallyFailedPayment($this->checkout, $human_exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,10 +84,11 @@ trait Utilities
|
||||
|
||||
public function processUnsuccessfulPayment($_payment, $throw_exception = true)
|
||||
{
|
||||
|
||||
$error_message = '';
|
||||
|
||||
if (array_key_exists('response_summary', $_payment)) {
|
||||
$error_message = $_payment['response_summary'];
|
||||
if (array_key_exists('actions', $_payment) && array_key_exists('response_summary', end($_payment['actions']))) {
|
||||
$error_message = end($_payment['actions'])['response_summary'];
|
||||
} elseif (array_key_exists('status', $_payment)) {
|
||||
$error_message = $_payment['status'];
|
||||
}
|
||||
|
@ -401,8 +401,13 @@ class CheckoutComPaymentDriver extends BaseDriver
|
||||
$this->unWindGatewayFees($payment_hash);
|
||||
$message = $e->getMessage();
|
||||
|
||||
$error_details = '';
|
||||
|
||||
if(property_exists($e, 'error_details'))
|
||||
$error_details = $e->error_details;
|
||||
|
||||
$data = [
|
||||
'status' => '',
|
||||
'status' => $e->error_details,
|
||||
'error_type' => '',
|
||||
'error_code' => $e->getCode(),
|
||||
'param' => '',
|
||||
|
Loading…
x
Reference in New Issue
Block a user