mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Refactor exception handling in stripe
This commit is contained in:
parent
df623275b8
commit
e9d0ac30e2
@ -35,7 +35,7 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue
|
|||||||
|
|
||||||
public $company;
|
public $company;
|
||||||
|
|
||||||
public $amount;
|
public $payment_hash;
|
||||||
|
|
||||||
public $settings;
|
public $settings;
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue
|
|||||||
* @param $company
|
* @param $company
|
||||||
* @param $amount
|
* @param $amount
|
||||||
*/
|
*/
|
||||||
public function __construct($client, $message, $company, $amount)
|
public function __construct($client, $message, $company, $payment_hash)
|
||||||
{
|
{
|
||||||
$this->company = $company;
|
$this->company = $company;
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue
|
|||||||
|
|
||||||
$this->client = $client;
|
$this->client = $client;
|
||||||
|
|
||||||
$this->amount = $amount;
|
$this->payment_hash = $payment_hash;
|
||||||
|
|
||||||
$this->company = $company;
|
$this->company = $company;
|
||||||
|
|
||||||
|
@ -335,6 +335,8 @@ class BaseDriver extends AbstractPaymentDriver
|
|||||||
public function processInternallyFailedPayment($gateway, $e)
|
public function processInternallyFailedPayment($gateway, $e)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
$this->unWindGatewayFees($this->payment_hash);
|
||||||
|
|
||||||
if ($e instanceof CheckoutHttpException) {
|
if ($e instanceof CheckoutHttpException) {
|
||||||
$error = $e->getBody();
|
$error = $e->getBody();
|
||||||
}
|
}
|
||||||
@ -344,7 +346,7 @@ class BaseDriver extends AbstractPaymentDriver
|
|||||||
else
|
else
|
||||||
$error = $e->getMessage();
|
$error = $e->getMessage();
|
||||||
|
|
||||||
AutoBillingFailureMailer::dispatch(
|
PaymentFailureMailer::dispatch(
|
||||||
$gateway->client,
|
$gateway->client,
|
||||||
$error,
|
$error,
|
||||||
$gateway->client->company,
|
$gateway->client->company,
|
||||||
@ -364,31 +366,7 @@ class BaseDriver extends AbstractPaymentDriver
|
|||||||
|
|
||||||
public function tokenBillingFailed($gateway, $e)
|
public function tokenBillingFailed($gateway, $e)
|
||||||
{
|
{
|
||||||
$this->unWindGatewayFees($this->payment_hash);
|
|
||||||
|
|
||||||
if ($e instanceof CheckoutHttpException) {
|
|
||||||
$error = $e->getBody();
|
|
||||||
}
|
|
||||||
else if ($e instanceof Exception) {
|
|
||||||
$error = $e->getMessage();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
$error = $e->getMessage();
|
|
||||||
|
|
||||||
AutoBillingFailureMailer::dispatch(
|
|
||||||
$gateway->client,
|
|
||||||
$error,
|
|
||||||
$gateway->client->company,
|
|
||||||
$this->payment_hash
|
|
||||||
);
|
|
||||||
|
|
||||||
SystemLogger::dispatch(
|
|
||||||
$gateway->payment_hash,
|
|
||||||
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
|
||||||
SystemLog::EVENT_GATEWAY_ERROR,
|
|
||||||
$gateway::SYSTEM_LOG_TYPE,
|
|
||||||
$gateway->client,
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,99 +79,44 @@ class Charge
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
SystemLogger::dispatch($response, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_STRIPE, $this->stripe->client);
|
SystemLogger::dispatch($response, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_STRIPE, $this->stripe->client);
|
||||||
} catch (CardException $e) {
|
} catch (\Exception $e) {
|
||||||
// Since it's a decline, \Stripe\Exception\CardException will be caught
|
|
||||||
|
|
||||||
$data = [
|
$data =[
|
||||||
'status' => $e->getHttpStatus(),
|
|
||||||
'error_type' => $e->getError()->type,
|
|
||||||
'error_code' => $e->getError()->code,
|
|
||||||
'param' => $e->getError()->param,
|
|
||||||
'message' => $e->getError()->message,
|
|
||||||
];
|
|
||||||
$this->stripe->tokenBillingFailed($this->stripe, $e);
|
|
||||||
|
|
||||||
SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client);
|
|
||||||
} catch (RateLimitException $e) {
|
|
||||||
// Too many requests made to the API too quickly
|
|
||||||
|
|
||||||
$data = [
|
|
||||||
'status' => '',
|
'status' => '',
|
||||||
'error_type' => '',
|
'error_type' => '',
|
||||||
'error_code' => '',
|
'error_code' => '',
|
||||||
'param' => '',
|
'param' => '',
|
||||||
'message' => 'Too many requests made to the API too quickly',
|
'message' => '',
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->stripe->tokenBillingFailed($this->stripe, $e);
|
switch ($e) {
|
||||||
|
case ($e instanceof CardException):
|
||||||
|
$data['status'] => $e->getHttpStatus();
|
||||||
|
$data['error_type'] => $e->getError()->type;
|
||||||
|
$data['error_code'] => $e->getError()->code;
|
||||||
|
$data['param'] => $e->getError()->param;
|
||||||
|
$data['message'] => $e->getError()->message;
|
||||||
|
break;
|
||||||
|
case ($e instanceof RateLimitException):
|
||||||
|
$data['message'] => 'Too many requests made to the API too quickly';
|
||||||
|
break;
|
||||||
|
case ($e instanceof InvalidRequestException):
|
||||||
|
$data['message'] => 'Invalid parameters were supplied to Stripe\'s API';
|
||||||
|
break;
|
||||||
|
case ($e instanceof AuthenticationException):
|
||||||
|
$data['message'] => 'Authentication with Stripe\'s API failed';
|
||||||
|
break;
|
||||||
|
case ($e instanceof ApiErrorException):
|
||||||
|
$data['message'] => 'Network communication with Stripe failed';
|
||||||
|
break;
|
||||||
|
|
||||||
SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client);
|
default:
|
||||||
} catch (InvalidRequestException $e) {
|
$data['message'] => $e->getMessage();
|
||||||
// Invalid parameters were supplied to Stripe's API
|
break;
|
||||||
//
|
}
|
||||||
$data = [
|
|
||||||
'status' => '',
|
|
||||||
'error_type' => '',
|
|
||||||
'error_code' => '',
|
|
||||||
'param' => '',
|
|
||||||
'message' => 'Invalid parameters were supplied to Stripe\'s API',
|
|
||||||
];
|
|
||||||
|
|
||||||
$this->stripe->tokenBillingFailed($this->stripe, $e);
|
|
||||||
|
|
||||||
SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client);
|
$this->stripe->processInternallyFailedPayment($this->stripe, $e);
|
||||||
} catch (AuthenticationException $e) {
|
|
||||||
// Authentication with Stripe's API failed
|
|
||||||
|
|
||||||
$data = [
|
|
||||||
'status' => '',
|
|
||||||
'error_type' => '',
|
|
||||||
'error_code' => '',
|
|
||||||
'param' => '',
|
|
||||||
'message' => 'Authentication with Stripe\'s API failed',
|
|
||||||
];
|
|
||||||
|
|
||||||
$this->stripe->tokenBillingFailed($this->stripe, $e);
|
|
||||||
|
|
||||||
SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client);
|
|
||||||
} catch (ApiConnectionException $e) {
|
|
||||||
// Network communication with Stripe failed
|
|
||||||
|
|
||||||
$data = [
|
|
||||||
'status' => '',
|
|
||||||
'error_type' => '',
|
|
||||||
'error_code' => '',
|
|
||||||
'param' => '',
|
|
||||||
'message' => 'Network communication with Stripe failed',
|
|
||||||
];
|
|
||||||
|
|
||||||
$this->stripe->tokenBillingFailed($this->stripe, $e);
|
|
||||||
|
|
||||||
SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client);
|
|
||||||
} catch (ApiErrorException $e) {
|
|
||||||
$data = [
|
|
||||||
'status' => '',
|
|
||||||
'error_type' => '',
|
|
||||||
'error_code' => '',
|
|
||||||
'param' => '',
|
|
||||||
'message' => 'API Error',
|
|
||||||
];
|
|
||||||
|
|
||||||
$this->stripe->tokenBillingFailed($this->stripe, $e);
|
|
||||||
|
|
||||||
SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
// Something else happened, completely unrelated to Stripe
|
|
||||||
//
|
|
||||||
$data = [
|
|
||||||
'status' => '',
|
|
||||||
'error_type' => '',
|
|
||||||
'error_code' => '',
|
|
||||||
'param' => '',
|
|
||||||
'message' => $e->getMessage(),
|
|
||||||
];
|
|
||||||
|
|
||||||
$this->stripe->tokenBillingFailed($this->stripe, $e);
|
|
||||||
|
|
||||||
SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client);
|
SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user