diff --git a/app/Jobs/Mail/PaymentFailureMailer.php b/app/Jobs/Mail/PaymentFailureMailer.php index e51ebe468719..879d0184c9cd 100644 --- a/app/Jobs/Mail/PaymentFailureMailer.php +++ b/app/Jobs/Mail/PaymentFailureMailer.php @@ -35,7 +35,7 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue public $company; - public $amount; + public $payment_hash; public $settings; @@ -47,7 +47,7 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue * @param $company * @param $amount */ - public function __construct($client, $message, $company, $amount) + public function __construct($client, $message, $company, $payment_hash) { $this->company = $company; @@ -55,7 +55,7 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue $this->client = $client; - $this->amount = $amount; + $this->payment_hash = $payment_hash; $this->company = $company; diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 9b7dea308e3d..116676edd1bd 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -335,6 +335,8 @@ class BaseDriver extends AbstractPaymentDriver public function processInternallyFailedPayment($gateway, $e) { + $this->unWindGatewayFees($this->payment_hash); + if ($e instanceof CheckoutHttpException) { $error = $e->getBody(); } @@ -344,7 +346,7 @@ class BaseDriver extends AbstractPaymentDriver else $error = $e->getMessage(); - AutoBillingFailureMailer::dispatch( + PaymentFailureMailer::dispatch( $gateway->client, $error, $gateway->client->company, @@ -364,31 +366,7 @@ class BaseDriver extends AbstractPaymentDriver 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, - ); } diff --git a/app/PaymentDrivers/Stripe/Charge.php b/app/PaymentDrivers/Stripe/Charge.php index 44d6642f850a..e8ad3b5f006d 100644 --- a/app/PaymentDrivers/Stripe/Charge.php +++ b/app/PaymentDrivers/Stripe/Charge.php @@ -79,102 +79,47 @@ class Charge ]); SystemLogger::dispatch($response, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_STRIPE, $this->stripe->client); - } catch (CardException $e) { - // Since it's a decline, \Stripe\Exception\CardException will be caught + } catch (\Exception $e) { - $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); + $data =[ + 'status' => '', + 'error_type' => '', + 'error_code' => '', + 'param' => '', + 'message' => '', + ]; + + 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; + + default: + $data['message'] => $e->getMessage(); + break; + } + + + $this->stripe->processInternallyFailedPayment($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' => '', - 'error_type' => '', - 'error_code' => '', - 'param' => '', - 'message' => 'Too many requests made to the API too quickly', - ]; - - $this->stripe->tokenBillingFailed($this->stripe, $e); - - SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client); - } catch (InvalidRequestException $e) { - // Invalid parameters were supplied to Stripe's API - // - $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); - } 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); - } + } if (! $response) { return false;