From 38ceefc5369a2a558d513a214fc8b7472d39fe95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 27 Aug 2021 16:19:10 +0200 Subject: [PATCH] Fixes for `processInternallyFailedPayment` --- app/PaymentDrivers/BaseDriver.php | 43 +++++++++++++++---------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 65705fc19c9d..b984b2b41eaa 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -360,16 +360,15 @@ class BaseDriver extends AbstractPaymentDriver public function processInternallyFailedPayment($gateway, $e) { - - $this->unWindGatewayFees($this->payment_hash); + if (!is_null($this->payment_hash)) { + $this->unWindGatewayFees($this->payment_hash); + } if ($e instanceof CheckoutHttpException) { $error = $e->getBody(); - } - else if ($e instanceof Exception) { + } else if ($e instanceof Exception) { $error = $e->getMessage(); - } - else + } else $error = $e->getMessage(); PaymentFailureMailer::dispatch( @@ -379,29 +378,29 @@ class BaseDriver extends AbstractPaymentDriver $this->payment_hash ); - $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; + if (!is_null($this->payment_hash)) { - $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get(); + $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; - $invoices->each(function ($invoice){ + $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get(); - $invoice->service()->deletePdf(); + $invoices->each(function ($invoice) { - }); + $invoice->service()->deletePdf(); + }); - $invoices->first()->invitations->each(function ($invitation) use ($nmo){ + $invoices->first()->invitations->each(function ($invitation) use ($nmo) { - if ($invitation->contact->send_email && $invitation->contact->email) { + if ($invitation->contact->send_email && $invitation->contact->email) { - $nmo->to_user = $invitation->contact; - NinjaMailerJob::dispatch($nmo); - - } - - }); + $nmo->to_user = $invitation->contact; + NinjaMailerJob::dispatch($nmo); + } + }); + } SystemLogger::dispatch(