From a8d148b0dcb984da24846b4ede06c4f2b06103fd Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 20 Jul 2021 09:30:12 +1000 Subject: [PATCH] Fixes for invoices which are not payable if archived --- app/PaymentDrivers/BaseDriver.php | 6 +++--- app/PaymentDrivers/BasePaymentDriver.php | 4 ++-- app/PaymentDrivers/BraintreePaymentDriver.php | 2 +- app/PaymentDrivers/CheckoutComPaymentDriver.php | 2 +- app/PaymentDrivers/CustomPaymentDriver.php | 2 +- app/PaymentDrivers/PayPalExpressPaymentDriver.php | 2 +- app/PaymentDrivers/Stripe/Charge.php | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index d7e2757f0794..ef59a3d0d82c 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -283,7 +283,7 @@ class BaseDriver extends AbstractPaymentDriver $fee_total = $this->payment_hash->fee_total; /*Hydrate invoices*/ - $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_invoices, 'invoice_id')))->get(); + $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_invoices, 'invoice_id')))->withTrashed()->get(); $invoices->each(function ($invoice) use ($fee_total) { if (collect($invoice->line_items)->contains('type_id', '3')) { @@ -303,7 +303,7 @@ class BaseDriver extends AbstractPaymentDriver */ public function unWindGatewayFees(PaymentHash $payment_hash) { - $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->get(); + $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->get(); $invoices->each(function ($invoice) { $invoice->service()->removeUnpaidGatewayFees(); @@ -384,7 +384,7 @@ class BaseDriver extends AbstractPaymentDriver $nmo->company = $gateway->client->company; $nmo->settings = $gateway->client->company->settings; - $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->get(); + $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get(); $invoices->each(function ($invoice){ diff --git a/app/PaymentDrivers/BasePaymentDriver.php b/app/PaymentDrivers/BasePaymentDriver.php index f309a3e8a0f3..3053a6b9e783 100644 --- a/app/PaymentDrivers/BasePaymentDriver.php +++ b/app/PaymentDrivers/BasePaymentDriver.php @@ -271,7 +271,7 @@ class BasePaymentDriver public function attachInvoices(Payment $payment, PaymentHash $payment_hash): Payment { $paid_invoices = $payment_hash->invoices(); - $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->get(); + $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->withTrashed()->get(); $payment->invoices()->sync($invoices); $payment->save(); @@ -300,7 +300,7 @@ class BasePaymentDriver // $invoice_totals = array_sum(array_column($payment_invoices,'amount')); /*Hydrate invoices*/ - $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_invoices, 'invoice_id')))->get(); + $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_invoices, 'invoice_id')))->withTrashed()->get(); $invoices->each(function ($invoice) use ($fee_total) { if (collect($invoice->line_items)->contains('type_id', '3')) { diff --git a/app/PaymentDrivers/BraintreePaymentDriver.php b/app/PaymentDrivers/BraintreePaymentDriver.php index dd1b1fbb207d..d36f11a23eba 100644 --- a/app/PaymentDrivers/BraintreePaymentDriver.php +++ b/app/PaymentDrivers/BraintreePaymentDriver.php @@ -149,7 +149,7 @@ class BraintreePaymentDriver extends BaseDriver { $amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total; - $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->first(); + $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first(); if ($invoice) { $description = "Invoice {$invoice->number} for {$amount} for client {$this->client->present()->name()}"; diff --git a/app/PaymentDrivers/CheckoutComPaymentDriver.php b/app/PaymentDrivers/CheckoutComPaymentDriver.php index 1d539c37613a..8012cfeba714 100644 --- a/app/PaymentDrivers/CheckoutComPaymentDriver.php +++ b/app/PaymentDrivers/CheckoutComPaymentDriver.php @@ -198,7 +198,7 @@ class CheckoutComPaymentDriver extends BaseDriver public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash) { $amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total; - $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->first(); + $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first(); if ($invoice) { $description = "Invoice {$invoice->number} for {$amount} for client {$this->client->present()->name()}"; diff --git a/app/PaymentDrivers/CustomPaymentDriver.php b/app/PaymentDrivers/CustomPaymentDriver.php index 7f297fa9f401..c4553b1eb4e9 100644 --- a/app/PaymentDrivers/CustomPaymentDriver.php +++ b/app/PaymentDrivers/CustomPaymentDriver.php @@ -61,7 +61,7 @@ class CustomPaymentDriver extends BaseDriver if (count($this->payment_hash->invoices()) > 0) { $invoice_id = $this->decodePrimaryKey($this->payment_hash->invoices()[0]->invoice_id); - $invoice = Invoice::findOrFail($invoice_id); + $invoice = Invoice::withTrashed()->find($invoice_id); $variables = (new HtmlEngine($invoice->invitations->first()))->generateLabelsAndValues(); } diff --git a/app/PaymentDrivers/PayPalExpressPaymentDriver.php b/app/PaymentDrivers/PayPalExpressPaymentDriver.php index ccf11ac5b4f0..88de81b4823a 100644 --- a/app/PaymentDrivers/PayPalExpressPaymentDriver.php +++ b/app/PaymentDrivers/PayPalExpressPaymentDriver.php @@ -199,7 +199,7 @@ class PayPalExpressPaymentDriver extends BaseDriver { $_invoice = collect($this->payment_hash->data->invoices)->first(); - $invoice = Invoice::findOrFail($this->decodePrimaryKey($_invoice->invoice_id)); + $invoice = Invoice::withTrashed()->find($this->decodePrimaryKey($_invoice->invoice_id)); $line_item = collect($invoice->line_items)->first(); diff --git a/app/PaymentDrivers/Stripe/Charge.php b/app/PaymentDrivers/Stripe/Charge.php index 4e6806544690..35cba7c7b5c7 100644 --- a/app/PaymentDrivers/Stripe/Charge.php +++ b/app/PaymentDrivers/Stripe/Charge.php @@ -52,7 +52,7 @@ class Charge public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash) { $amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total; - $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->first(); + $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first(); if ($invoice) { $description = "Invoice {$invoice->number} for {$amount} for client {$this->stripe->client->present()->name()}";