From ede64ef03d8d1532b90d8288b39764ac6a43479a Mon Sep 17 00:00:00 2001 From: = Date: Tue, 17 May 2022 14:46:03 +1000 Subject: [PATCH] Minor refactor for auto billing --- app/Models/Invoice.php | 3 +-- app/Services/Invoice/AutoBillInvoice.php | 9 ++------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index c9ab3ea72020..f2907f385ef8 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -90,8 +90,7 @@ class Invoice extends BaseModel 'subscription_id', 'auto_bill_enabled', 'uses_inclusive_taxes', - 'vendor_id', - 'auto_bill_tries' + 'vendor_id' ]; protected $casts = [ diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index a94a7e68f98d..6ae012e3282f 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -117,31 +117,26 @@ class AutoBillInvoice extends AbstractService $payment = false; - $number_of_retries = $this->invoice->auto_bill_tries; - try { $payment = $gateway_token->gateway ->driver($this->client) ->setPaymentHash($payment_hash) ->tokenBilling($gateway_token, $payment_hash); } catch (\Exception $e) { - //increase the counter $this->invoice->auto_bill_tries = $number_of_retries + 1; - $this->invoice->save(); - //disable auto bill if limit of 3 is reached + if ($this->invoice->auto_bill_tries == 3) { $this->invoice->auto_bill_enabled = false; + $this->invoice->auto_bill_tries = 0; //reset the counter here in case auto billing is turned on again in the future. $this->invoice->save(); } nlog("payment NOT captured for " . $this->invoice->number . " with error " . $e->getMessage()); - // $this->invoice->service()->removeUnpaidGatewayFees(); } if ($payment) { info("Auto Bill payment captured for " . $this->invoice->number); } - // return $this->invoice->fresh(); } /**