diff --git a/app/Jobs/Cron/AutoBillCron.php b/app/Jobs/Cron/AutoBillCron.php index ac74f307ebd9..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,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,19 +102,20 @@ 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); }); } } } - private function runAutoBiller(Invoice $invoice) + private function runAutoBiller(Invoice $invoice, $db) { info("Firing autobill for {$invoice->company_id} - {$invoice->number}"); try{ + MultiDB::setDB($db); $invoice->service()->autoBill()->save(); } catch(\Exception $e) { 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(); diff --git a/app/PaymentDrivers/Stripe/Charge.php b/app/PaymentDrivers/Stripe/Charge.php index 2ae298a335e2..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(); @@ -75,6 +76,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);