Prevent charging downgraded accounts

This commit is contained in:
Hillel Coren 2016-07-16 23:19:43 +03:00
parent 56f89ef3a0
commit e41d47eb0d
2 changed files with 12 additions and 3 deletions

View File

@ -5,6 +5,7 @@ use App\Ninja\Mailers\ContactMailer as Mailer;
use App\Ninja\Repositories\AccountRepository;
use App\Services\PaymentService;
use App\Models\Invoice;
use App\Models\Account;
/**
* Class ChargeRenewalInvoices
@ -55,8 +56,8 @@ class ChargeRenewalInvoices extends Command
{
$this->info(date('Y-m-d').' ChargeRenewalInvoices...');
$account = $this->accountRepo->getNinjaAccount();
$invoices = Invoice::whereAccountId($account->id)
$ninjaAccount = $this->accountRepo->getNinjaAccount();
$invoices = Invoice::whereAccountId($ninjaAccount->id)
->whereDueDate(date('Y-m-d'))
->with('client')
->orderBy('id')
@ -65,6 +66,14 @@ class ChargeRenewalInvoices extends Command
$this->info(count($invoices).' invoices found');
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->paymentService->autoBillInvoice($invoice);
}

View File

@ -1240,7 +1240,7 @@ class Account extends Eloquent
$price = $this->company->plan_price;
$trial_plan = $this->company->trial_plan;
if(!$plan && (!$trial_plan || !$include_trial)) {
if((!$plan || $plan == PLAN_FREE) && (!$trial_plan || !$include_trial)) {
return null;
}