From 403b784e170ebf40d93c96d8b914716d74ef6943 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 16 Apr 2017 17:22:07 +0300 Subject: [PATCH] Prevent duplicate billing --- app/Console/Commands/ChargeRenewalInvoices.php | 6 ++++++ app/Ninja/Repositories/AccountRepository.php | 3 +++ 2 files changed, 9 insertions(+) diff --git a/app/Console/Commands/ChargeRenewalInvoices.php b/app/Console/Commands/ChargeRenewalInvoices.php index 1cc4994284..870406a3af 100644 --- a/app/Console/Commands/ChargeRenewalInvoices.php +++ b/app/Console/Commands/ChargeRenewalInvoices.php @@ -8,6 +8,7 @@ use App\Ninja\Mailers\ContactMailer as Mailer; use App\Ninja\Repositories\AccountRepository; use App\Services\PaymentService; use Illuminate\Console\Command; +use Carbon; /** * Class ChargeRenewalInvoices. @@ -83,6 +84,11 @@ class ChargeRenewalInvoices extends Command continue; } + if (Carbon::parse($company->plan_expires)->isFuture()) { + $this->info('Skipping invoice ' . $invoice->invoice_number . ' [plan not expired]'); + continue; + } + $this->info("Charging invoice {$invoice->invoice_number}"); if (! $this->paymentService->autoBillInvoice($invoice)) { $this->info('Failed to auto-bill, emailing invoice'); diff --git a/app/Ninja/Repositories/AccountRepository.php b/app/Ninja/Repositories/AccountRepository.php index 9ff3d67bee..f64cd05566 100644 --- a/app/Ninja/Repositories/AccountRepository.php +++ b/app/Ninja/Repositories/AccountRepository.php @@ -356,6 +356,9 @@ class AccountRepository $account->company_id = $company->id; $account->save(); + $emailSettings = new AccountEmailSettings(); + $account->account_email_settings()->save($emailSettings); + $random = strtolower(str_random(RANDOM_KEY_LENGTH)); $user = new User(); $user->registered = true;