From 58970fab99bcd4f661e2e9a70d7ba1ef6b1d430f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 1 Feb 2021 23:41:11 +1100 Subject: [PATCH] payment failure emails --- app/PaymentDrivers/BaseDriver.php | 32 +++++++++++++++++-- app/PaymentDrivers/Stripe/Charge.php | 16 +++++----- .../Traits/Notifications/UserNotifies.php | 1 - 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 11ff29606185..9b7dea308e3d 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -344,8 +344,6 @@ class BaseDriver extends AbstractPaymentDriver else $error = $e->getMessage(); - $amount = optional($this->payment_hash->data)->value ?? optional($this->payment_hash->data)->amount; - AutoBillingFailureMailer::dispatch( $gateway->client, $error, @@ -364,6 +362,36 @@ class BaseDriver extends AbstractPaymentDriver throw new PaymentFailed($error, $e->getCode()); } + 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, + ); + + } + /** * Wrapper method for checking if resource is good. * diff --git a/app/PaymentDrivers/Stripe/Charge.php b/app/PaymentDrivers/Stripe/Charge.php index 373773d3eef9..44d6642f850a 100644 --- a/app/PaymentDrivers/Stripe/Charge.php +++ b/app/PaymentDrivers/Stripe/Charge.php @@ -77,7 +77,7 @@ class Charge 'confirm' => true, 'description' => $description, ]); -info("attempting token billing"); + 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 @@ -89,7 +89,7 @@ info("attempting token billing"); 'param' => $e->getError()->param, 'message' => $e->getError()->message, ]; - $this->stripe->processInternallyFailedPayment($this->stripe, $e); + $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) { @@ -103,7 +103,7 @@ info("attempting token billing"); 'message' => 'Too many requests made to the API too quickly', ]; - $this->stripe->processInternallyFailedPayment($this->stripe, $e); + $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) { @@ -117,7 +117,7 @@ info("attempting token billing"); 'message' => 'Invalid parameters were supplied to Stripe\'s API', ]; - $this->stripe->processInternallyFailedPayment($this->stripe, $e); + $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) { @@ -131,7 +131,7 @@ info("attempting token billing"); 'message' => 'Authentication with Stripe\'s API failed', ]; - $this->stripe->processInternallyFailedPayment($this->stripe, $e); + $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) { @@ -145,7 +145,7 @@ info("attempting token billing"); 'message' => 'Network communication with Stripe failed', ]; - $this->stripe->processInternallyFailedPayment($this->stripe, $e); + $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) { @@ -157,7 +157,7 @@ info("attempting token billing"); 'message' => 'API Error', ]; - $this->stripe->processInternallyFailedPayment($this->stripe, $e); + $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) { @@ -171,7 +171,7 @@ info("attempting token billing"); 'message' => $e->getMessage(), ]; - $this->stripe->processInternallyFailedPayment($this->stripe, $e); + $this->stripe->tokenBillingFailed($this->stripe, $e); SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client); } diff --git a/app/Utils/Traits/Notifications/UserNotifies.php b/app/Utils/Traits/Notifications/UserNotifies.php index e05689359ee1..8b38541c800d 100644 --- a/app/Utils/Traits/Notifications/UserNotifies.php +++ b/app/Utils/Traits/Notifications/UserNotifies.php @@ -66,7 +66,6 @@ trait UserNotifies public function findCompanyUserNotificationType($company_user, $required_permissions) :array { - nlog("find company user notification type"); if ($company_user->company->is_disabled) { return [];