From d0cb751d03cbb7d42c2467923bb25121275727f9 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 13 Oct 2021 20:24:15 +1100 Subject: [PATCH] CLient payment failure mailer --- app/PaymentDrivers/BaseDriver.php | 34 ++++++++++++------- app/PaymentDrivers/CheckoutCom/CreditCard.php | 2 ++ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index f6ed9c223bec..0e31981497c9 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -378,12 +378,30 @@ class BaseDriver extends AbstractPaymentDriver $this->payment_hash ); + SystemLogger::dispatch( + $gateway->payment_hash, + SystemLog::CATEGORY_GATEWAY_RESPONSE, + SystemLog::EVENT_GATEWAY_ERROR, + $gateway::SYSTEM_LOG_TYPE, + $gateway->client, + $gateway->client->company, + ); + + throw new PaymentFailed($error, $e->getCode()); + } + + public function clientPaymentFailureMailer($error) + { +nlog("outside"); + if ($this->payment_hash && is_array($this->payment_hash->invoices())) { +nlog("inside"); + $nmo = new NinjaMailerObject; - $nmo->mailable = new NinjaMailer((new ClientPaymentFailureObject($gateway->client, $error, $gateway->client->company, $this->payment_hash))->build()); - $nmo->company = $gateway->client->company; - $nmo->settings = $gateway->client->company->settings; + $nmo->mailable = new NinjaMailer((new ClientPaymentFailureObject($this->client, $error, $this->client->company, $this->payment_hash))->build()); + $nmo->company = $this->client->company; + $nmo->settings = $this->client->company->settings; $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get(); @@ -405,16 +423,6 @@ class BaseDriver extends AbstractPaymentDriver } - SystemLogger::dispatch( - $gateway->payment_hash, - SystemLog::CATEGORY_GATEWAY_RESPONSE, - SystemLog::EVENT_GATEWAY_ERROR, - $gateway::SYSTEM_LOG_TYPE, - $gateway->client, - $gateway->client->company, - ); - - throw new PaymentFailed($error, $e->getCode()); } /** diff --git a/app/PaymentDrivers/CheckoutCom/CreditCard.php b/app/PaymentDrivers/CheckoutCom/CreditCard.php index fd09cf1ce4f6..0a76f483750a 100644 --- a/app/PaymentDrivers/CheckoutCom/CreditCard.php +++ b/app/PaymentDrivers/CheckoutCom/CreditCard.php @@ -176,6 +176,8 @@ class CreditCard PaymentFailureMailer::dispatch($this->checkout->client, $response->response_summary, $this->checkout->client->company, $this->checkout->payment_hash->data->value); + $this->checkout->clientPaymentFailureMailer($response->status); + return $this->processUnsuccessfulPayment($response); } } catch (CheckoutHttpException $e) {