From 2b20d079ba7875b3f36388d90c9fee290a659ec2 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 13 Oct 2021 17:29:23 +1100 Subject: [PATCH 1/3] Fixes for statements --- app/Services/Client/Statement.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/Services/Client/Statement.php b/app/Services/Client/Statement.php index 53aa575fce..4bd2131182 100644 --- a/app/Services/Client/Statement.php +++ b/app/Services/Client/Statement.php @@ -219,7 +219,9 @@ class Statement */ protected function getInvoices(): Collection { - return Invoice::where('company_id', $this->client->company_id) + return Invoice::withTrashed() + ->where('is_deleted', false) + ->where('company_id', $this->client->company_id) ->where('client_id', $this->client->id) ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL, Invoice::STATUS_PAID]) ->whereBetween('date', [$this->options['start_date'], $this->options['end_date']]) @@ -234,7 +236,9 @@ class Statement */ protected function getPayments(): Collection { - return Payment::with('client.country','invoices') + return Payment::withTrashed() + ->with('client.country','invoices') + ->where('is_deleted', false) ->where('company_id', $this->client->company_id) ->where('client_id', $this->client->id) ->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED]) @@ -286,7 +290,8 @@ class Statement $from = $ranges[0]; $to = $ranges[1]; - $amount = Invoice::where('client_id', $this->client->id) + $amount = Invoice::withTrashed() + ->where('client_id', $this->client->id) ->where('company_id', $this->client->company_id) ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) ->where('balance', '>', 0) From fc276970a05295d167ab8dee86bfc5b9118620a2 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 13 Oct 2021 18:56:10 +1100 Subject: [PATCH 2/3] Payment Failure --- app/Mail/Admin/ClientPaymentFailureObject.php | 2 +- app/PaymentDrivers/BaseDriver.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Mail/Admin/ClientPaymentFailureObject.php b/app/Mail/Admin/ClientPaymentFailureObject.php index 3489274ba1..c18101b2ed 100644 --- a/app/Mail/Admin/ClientPaymentFailureObject.php +++ b/app/Mail/Admin/ClientPaymentFailureObject.php @@ -62,7 +62,7 @@ class ClientPaymentFailureObject /* Init a new copy of the translator*/ $t = app('translator'); /* Set the locale*/ - App::setLocale($this->company->getLocale()); + App::setLocale($this->client->locale()); /* Set customized translations _NOW_ */ $t->replace(Ninja::transformTranslations($this->company->settings)); diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index ecb74e416a..f6ed9c223b 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -378,7 +378,7 @@ class BaseDriver extends AbstractPaymentDriver $this->payment_hash ); - if (!is_null($this->payment_hash)) { + if ($this->payment_hash && is_array($this->payment_hash->invoices())) { $nmo = new NinjaMailerObject; $nmo->mailable = new NinjaMailer((new ClientPaymentFailureObject($gateway->client, $error, $gateway->client->company, $this->payment_hash))->build()); From d0cb751d03cbb7d42c2467923bb25121275727f9 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 13 Oct 2021 20:24:15 +1100 Subject: [PATCH 3/3] 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 f6ed9c223b..0e31981497 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 fd09cf1ce4..0a76f48375 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) {