From 95641177cc7648bfd88c1db7b06ab408cf2644ae Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 3 Sep 2021 12:25:41 +1000 Subject: [PATCH 1/4] minor fixes --- app/Jobs/Cron/RecurringInvoicesCron.php | 4 ++-- app/Models/Account.php | 4 ++-- app/PaymentDrivers/BaseDriver.php | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Jobs/Cron/RecurringInvoicesCron.php b/app/Jobs/Cron/RecurringInvoicesCron.php index 51b8bb874e86..14e9c1cfa56f 100644 --- a/app/Jobs/Cron/RecurringInvoicesCron.php +++ b/app/Jobs/Cron/RecurringInvoicesCron.php @@ -89,7 +89,7 @@ class RecurringInvoicesCron ->with('company') ->cursor(); - nlog(now()->format('Y-m-d') . ' Sending Recurring Invoices. Count = '.$recurring_invoices->count().' On Database # '.$db); + nlog(now()->format('Y-m-d') . ' Sending Recurring Invoices. Count = '.$recurring_invoices->count()); $recurring_invoices->each(function ($recurring_invoice, $key) { nlog("Current date = " . now()->format("Y-m-d") . " Recurring date = " .$recurring_invoice->next_send_date ." Recurring #id = ". $recurring_invoice->id); @@ -100,7 +100,7 @@ class RecurringInvoicesCron SendRecurring::dispatchNow($recurring_invoice, $recurring_invoice->company->db); } catch(\Exception $e){ - nlog("Unable to sending recurring invoice {$recurring_invoice->id} on db {$db}"); + nlog("Unable to sending recurring invoice {$recurring_invoice->id}"); } } }); diff --git a/app/Models/Account.php b/app/Models/Account.php index 5301d90cbd7d..d7a9f2d6ce08 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -358,11 +358,11 @@ class Account extends BaseModel if($this->isPaid()){ $limit = $this->paid_plan_email_quota; - $limit += Carbon::createFromTimestamp($this->created_at)->diffInMonths() * 50; + $limit += Carbon::createFromTimestamp($this->created_at)->diffInMonths() * 100; } else{ $limit = $this->free_plan_email_quota; - $limit += Carbon::createFromTimestamp($this->created_at)->diffInMonths() * 100; + $limit += Carbon::createFromTimestamp($this->created_at)->diffInMonths() * 50; } return min($limit, 5000); diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 5495cb885f91..dd8a5e570179 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -205,6 +205,7 @@ class BaseDriver extends AbstractPaymentDriver $invoices->each(function ($invoice) use ($payment) { event(new InvoiceWasPaid($invoice, $payment, $payment->company, Ninja::eventVars())); + $invoice->service()->workFlow(); }); return $payment->service()->applyNumber()->save(); From e084e85eebe7110a019b8a7d03c4a627f55ba0b1 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 3 Sep 2021 15:38:20 +1000 Subject: [PATCH 2/4] Additional logging for auto biller --- app/PaymentDrivers/Stripe/Charge.php | 4 ++++ app/Services/Invoice/AutoBillInvoice.php | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/PaymentDrivers/Stripe/Charge.php b/app/PaymentDrivers/Stripe/Charge.php index 2ae298a335e2..ce5a424de7b2 100644 --- a/app/PaymentDrivers/Stripe/Charge.php +++ b/app/PaymentDrivers/Stripe/Charge.php @@ -75,6 +75,10 @@ class Charge 'description' => $description, ]; + nlog("Stripe tokenBilling payload"); + + nlog($data); + $response = $this->stripe->createPaymentIntent($data, $this->stripe->stripe_connect_auth); // $response = $local_stripe->paymentIntents->create($data); diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 0926abf7b9e2..9505bf2e9349 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -51,12 +51,14 @@ class AutoBillInvoice extends AbstractService /* Mark the invoice as paid if there is no balance */ if ((int)$this->invoice->balance == 0) - return $this->invoice->service()->markPaid()->save(); + return $this->invoice->service()->markPaid()->workFlow()->save(); //if the credits cover the payments, we stop here, build the payment with credits and exit early if ($this->client->getSetting('use_credits_payment') != 'off') $this->applyCreditPayment(); + $amount = 0; + /* Determine $amount */ if ($this->invoice->partial > 0) { $is_partial = true; @@ -68,14 +70,16 @@ class AutoBillInvoice extends AbstractService return $this->invoice; } - info("balance remains to be paid!!"); + info("Auto Bill - balance remains to be paid!! - {$amount}"); /* Retrieve the Client Gateway Token */ $gateway_token = $this->getGateway($amount); /* Bail out if no payment methods available */ - if (! $gateway_token || ! $gateway_token->gateway->driver($this->client)->token_billing) + if (! $gateway_token || ! $gateway_token->gateway->driver($this->client)->token_billing){ + nlog("Bailing out - no suitable gateway token found."); return $this->invoice; + } /* $gateway fee */ //$fee = $gateway_token->gateway->calcGatewayFee($amount, $gateway_token->gateway_type_id, $this->invoice->uses_inclusive_taxes); From 592387874e6588b6a8863ce2513c3b0f0721e967 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 3 Sep 2021 19:28:04 +1000 Subject: [PATCH 3/4] Fixes for stripe --- app/Jobs/Cron/AutoBillCron.php | 9 +++++---- app/PaymentDrivers/Stripe/Charge.php | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/Jobs/Cron/AutoBillCron.php b/app/Jobs/Cron/AutoBillCron.php index ac74f307ebd9..6b105ca9e1cd 100644 --- a/app/Jobs/Cron/AutoBillCron.php +++ b/app/Jobs/Cron/AutoBillCron.php @@ -89,8 +89,8 @@ class AutoBillCron nlog($auto_bill_partial_invoices->count(). " partial invoices to auto bill db = {$db}"); - $auto_bill_partial_invoices->cursor()->each(function ($invoice){ - $this->runAutoBiller($invoice); + $auto_bill_partial_invoices->cursor()->each(function ($invoice)use($db){ + $this->runAutoBiller($invoice, $db); }); $auto_bill_invoices = Invoice::whereDate('due_date', '<=', now()) @@ -102,8 +102,8 @@ class AutoBillCron nlog($auto_bill_invoices->count(). " full invoices to auto bill db = {$db}"); - $auto_bill_invoices->cursor()->each(function ($invoice){ - $this->runAutoBiller($invoice); + $auto_bill_invoices->cursor()->each(function ($invoice) use($db){ + $this->runAutoBiller($invoice, $db); }); } @@ -115,6 +115,7 @@ class AutoBillCron info("Firing autobill for {$invoice->company_id} - {$invoice->number}"); try{ + MultiDB::setDB($db); $invoice->service()->autoBill()->save(); } catch(\Exception $e) { diff --git a/app/PaymentDrivers/Stripe/Charge.php b/app/PaymentDrivers/Stripe/Charge.php index ce5a424de7b2..6a238aa61f94 100644 --- a/app/PaymentDrivers/Stripe/Charge.php +++ b/app/PaymentDrivers/Stripe/Charge.php @@ -51,6 +51,7 @@ class Charge */ public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash) { + nlog(" DB = ".$this->stripe->client->company->db); $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')))->withTrashed()->first(); From 0f6af65f53fb12d1c6ad65396489b756cf8f7ef5 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 3 Sep 2021 19:30:44 +1000 Subject: [PATCH 4/4] Fixes for auto billing --- app/Jobs/Cron/AutoBillCron.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Jobs/Cron/AutoBillCron.php b/app/Jobs/Cron/AutoBillCron.php index 6b105ca9e1cd..f3918e9fffb2 100644 --- a/app/Jobs/Cron/AutoBillCron.php +++ b/app/Jobs/Cron/AutoBillCron.php @@ -56,8 +56,8 @@ class AutoBillCron nlog($auto_bill_partial_invoices->count(). " partial invoices to auto bill"); - $auto_bill_partial_invoices->cursor()->each(function ($invoice){ - $this->runAutoBiller($invoice); + $auto_bill_partial_invoices->cursor()->each(function ($invoice) use($db){ + $this->runAutoBiller($invoice, $db); }); $auto_bill_invoices = Invoice::whereDate('due_date', '<=', now()) @@ -69,8 +69,8 @@ class AutoBillCron nlog($auto_bill_invoices->count(). " full invoices to auto bill"); - $auto_bill_invoices->cursor()->each(function ($invoice){ - $this->runAutoBiller($invoice); + $auto_bill_invoices->cursor()->each(function ($invoice) use($db){ + $this->runAutoBiller($invoice, $db); }); @@ -89,7 +89,7 @@ class AutoBillCron nlog($auto_bill_partial_invoices->count(). " partial invoices to auto bill db = {$db}"); - $auto_bill_partial_invoices->cursor()->each(function ($invoice)use($db){ + $auto_bill_partial_invoices->cursor()->each(function ($invoice) use($db){ $this->runAutoBiller($invoice, $db); }); @@ -110,7 +110,7 @@ class AutoBillCron } } - private function runAutoBiller(Invoice $invoice) + private function runAutoBiller(Invoice $invoice, $db) { info("Firing autobill for {$invoice->company_id} - {$invoice->number}");