mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Prevent charging downgraded accounts
This commit is contained in:
parent
56f89ef3a0
commit
e41d47eb0d
@ -5,6 +5,7 @@ use App\Ninja\Mailers\ContactMailer as Mailer;
|
|||||||
use App\Ninja\Repositories\AccountRepository;
|
use App\Ninja\Repositories\AccountRepository;
|
||||||
use App\Services\PaymentService;
|
use App\Services\PaymentService;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
|
use App\Models\Account;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ChargeRenewalInvoices
|
* Class ChargeRenewalInvoices
|
||||||
@ -55,8 +56,8 @@ class ChargeRenewalInvoices extends Command
|
|||||||
{
|
{
|
||||||
$this->info(date('Y-m-d').' ChargeRenewalInvoices...');
|
$this->info(date('Y-m-d').' ChargeRenewalInvoices...');
|
||||||
|
|
||||||
$account = $this->accountRepo->getNinjaAccount();
|
$ninjaAccount = $this->accountRepo->getNinjaAccount();
|
||||||
$invoices = Invoice::whereAccountId($account->id)
|
$invoices = Invoice::whereAccountId($ninjaAccount->id)
|
||||||
->whereDueDate(date('Y-m-d'))
|
->whereDueDate(date('Y-m-d'))
|
||||||
->with('client')
|
->with('client')
|
||||||
->orderBy('id')
|
->orderBy('id')
|
||||||
@ -65,6 +66,14 @@ class ChargeRenewalInvoices extends Command
|
|||||||
$this->info(count($invoices).' invoices found');
|
$this->info(count($invoices).' invoices found');
|
||||||
|
|
||||||
foreach ($invoices as $invoice) {
|
foreach ($invoices as $invoice) {
|
||||||
|
|
||||||
|
// check if account has switched to free since the invoice was created
|
||||||
|
$account = Account::find($invoice->client->public_id);
|
||||||
|
$company = $account->company;
|
||||||
|
if ( ! $company->plan || $company->plan == PLAN_FREE) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$this->info("Charging invoice {$invoice->invoice_number}");
|
$this->info("Charging invoice {$invoice->invoice_number}");
|
||||||
$this->paymentService->autoBillInvoice($invoice);
|
$this->paymentService->autoBillInvoice($invoice);
|
||||||
}
|
}
|
||||||
|
@ -1240,7 +1240,7 @@ class Account extends Eloquent
|
|||||||
$price = $this->company->plan_price;
|
$price = $this->company->plan_price;
|
||||||
$trial_plan = $this->company->trial_plan;
|
$trial_plan = $this->company->trial_plan;
|
||||||
|
|
||||||
if(!$plan && (!$trial_plan || !$include_trial)) {
|
if((!$plan || $plan == PLAN_FREE) && (!$trial_plan || !$include_trial)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user