From e5e7a17d820f7b78ba7ac5c8c0254714a54ab933 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 2 Sep 2024 09:00:13 +1000 Subject: [PATCH] Fixes for confirming gateway feesg --- app/PaymentDrivers/BaseDriver.php | 6 +++++- app/Services/Invoice/AddGatewayFee.php | 8 ++------ app/Services/Invoice/AutoBillInvoice.php | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 4e6784575b42..3dca62962f52 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -400,8 +400,12 @@ class BaseDriver extends AbstractPaymentDriver $invoice = $this->payment_hash->fee_invoice; $fee_count = collect($invoice->line_items) + ->map(function ($item){ + $item->gross_line_total = round($item->gross_line_total, 2); + return $item; + }) ->whereIn('type_id', ['3','4']) - ->where('gross_line_total', $fee_total) + ->where('gross_line_total', round($fee_total,2)) ->count(); if($invoice && $fee_count == 0){ diff --git a/app/Services/Invoice/AddGatewayFee.php b/app/Services/Invoice/AddGatewayFee.php index fc1365e92337..386b8a8e05e7 100644 --- a/app/Services/Invoice/AddGatewayFee.php +++ b/app/Services/Invoice/AddGatewayFee.php @@ -92,6 +92,8 @@ class AddGatewayFee extends AbstractService /**Refresh Invoice values*/ $this->invoice = $this->invoice->calc()->getInvoice(); + nlog($this->invoice->line_items); + $new_balance = $this->invoice->balance; if (floatval($new_balance) - floatval($balance) != 0) { @@ -141,12 +143,6 @@ class AddGatewayFee extends AbstractService if (floatval($new_balance) - floatval($balance) != 0) { $adjustment = $new_balance - $balance; - // $this->invoice - // ->client - // ->service() - // ->updateBalance($adjustment * -1) - // ->save(); - $this->invoice ->ledger() ->updateInvoiceBalance($adjustment * -1, 'Adjustment for adding gateway DISCOUNT'); diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index cfb686dac5bd..3c7fc0bb9c75 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -148,9 +148,9 @@ class AutoBillInvoice extends AbstractService ]); nlog("Payment hash created => {$payment_hash->id}"); + $this->invoice->saveQuietly(); $payment = false; - try { $payment = $gateway_token->gateway ->driver($this->client) @@ -163,6 +163,7 @@ class AutoBillInvoice extends AbstractService } + $this->invoice = $this->invoice->fresh(); $this->invoice->auto_bill_tries += 1; if ($this->invoice->auto_bill_tries == 3) {