Inheritance: extends App\Ninja\Mailers\Mailer
 public function fire()
 {
     $this->info(date('Y-m-d') . ' Running SendRecurringInvoices...');
     $today = new DateTime();
     $invoices = Invoice::with('account.timezone', 'invoice_items', 'client', 'user')->whereRaw('is_deleted IS FALSE AND deleted_at IS NULL AND is_recurring IS TRUE AND frequency_id > 0 AND start_date <= ? AND (end_date IS NULL OR end_date >= ?)', [$today, $today])->orderBy('id', 'asc')->get();
     $this->info(count($invoices) . ' recurring invoice(s) found');
     foreach ($invoices as $recurInvoice) {
         $shouldSendToday = $recurInvoice->shouldSendToday();
         $this->info('Processing Invoice ' . $recurInvoice->id . ' - Should send ' . ($shouldSendToday ? 'YES' : 'NO'));
         if (!$shouldSendToday) {
             continue;
         }
         $recurInvoice->account->loadLocalizationSettings($recurInvoice->client);
         $invoice = $this->invoiceRepo->createRecurringInvoice($recurInvoice);
         if ($invoice && !$invoice->isPaid()) {
             $this->info('Sending Invoice');
             $this->mailer->sendInvoice($invoice);
         }
     }
     $delayedAutoBillInvoices = Invoice::with('account.timezone', 'recurring_invoice', 'invoice_items', 'client', 'user')->whereRaw('is_deleted IS FALSE AND deleted_at IS NULL AND is_recurring IS FALSE
         AND balance > 0 AND due_date = ? AND recurring_invoice_id IS NOT NULL', [$today->format('Y-m-d')])->orderBy('invoices.id', 'asc')->get();
     $this->info(count($delayedAutoBillInvoices) . ' due recurring invoice instance(s) found');
     /** @var Invoice $invoice */
     foreach ($delayedAutoBillInvoices as $invoice) {
         if ($invoice->isPaid()) {
             continue;
         }
         if ($invoice->getAutoBillEnabled() && $invoice->client->autoBillLater()) {
             $this->info('Processing Autobill-delayed Invoice ' . $invoice->id);
             $this->paymentService->autoBillInvoice($invoice);
         }
     }
     $this->info('Done');
 }
 /**
  * @param PaymentWasCreated $event
  */
 public function createdPayment(PaymentWasCreated $event)
 {
     // only send emails for online payments
     if (!$event->payment->account_gateway_id) {
         return;
     }
     $this->contactMailer->sendPaymentConfirmation($event->payment);
     $this->sendEmails($event->payment->invoice, 'paid', $event->payment);
     $this->pushService->sendNotification($event->payment->invoice, 'paid');
 }
 public function fire()
 {
     $this->info(date('Y-m-d') . ' Running SendRenewalInvoices...');
     // get all accounts with plans expiring in 10 days
     $companies = Company::whereRaw('datediff(plan_expires, curdate()) = 10')->orderBy('id')->get();
     $this->info(count($companies) . ' companies found renewing in 10 days');
     foreach ($companies as $company) {
         if (!count($company->accounts)) {
             continue;
         }
         $account = $company->accounts->sortBy('id')->first();
         $plan = [];
         $plan['plan'] = $company->plan;
         $plan['term'] = $company->plan_term;
         $plan['num_users'] = $company->num_users;
         $plan['price'] = min($company->plan_price, Utils::getPlanPrice($plan));
         if ($company->pending_plan) {
             $plan['plan'] = $company->pending_plan;
             $plan['term'] = $company->pending_term;
             $plan['num_users'] = $company->pending_num_users;
             $plan['price'] = min($company->pending_plan_price, Utils::getPlanPrice($plan));
         }
         if ($plan['plan'] == PLAN_FREE || !$plan['plan'] || !$plan['term'] || !$plan['price']) {
             continue;
         }
         $client = $this->accountRepo->getNinjaClient($account);
         $invitation = $this->accountRepo->createNinjaInvoice($client, $account, $plan, 0, false);
         // set the due date to 10 days from now
         $invoice = $invitation->invoice;
         $invoice->due_date = date('Y-m-d', strtotime('+ 10 days'));
         $invoice->save();
         $term = $plan['term'];
         $plan = $plan['plan'];
         if ($term == PLAN_TERM_YEARLY) {
             $this->mailer->sendInvoice($invoice);
             $this->info("Sent {$term}ly {$plan} invoice to {$client->getDisplayName()}");
         } else {
             $this->info("Created {$term}ly {$plan} invoice for {$client->getDisplayName()}");
         }
     }
     $this->info('Done');
 }
 public function fire()
 {
     $this->info(date('Y-m-d') . ' Running SendReminders...');
     $accounts = $this->accountRepo->findWithReminders();
     $this->info(count($accounts) . ' accounts found');
     /** @var \App\Models\Account $account */
     foreach ($accounts as $account) {
         if (!$account->hasFeature(FEATURE_EMAIL_TEMPLATES_REMINDERS)) {
             continue;
         }
         $invoices = $this->invoiceRepo->findNeedingReminding($account);
         $this->info($account->name . ': ' . count($invoices) . ' invoices found');
         /** @var Invoice $invoice */
         foreach ($invoices as $invoice) {
             if ($reminder = $account->getInvoiceReminder($invoice)) {
                 $this->info('Send to ' . $invoice->id);
                 $this->mailer->sendInvoice($invoice, $reminder);
             }
         }
     }
     $this->info('Done');
 }
 /**
  * @param CreatePaymentRequest $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function store(CreatePaymentRequest $request)
 {
     $input = $request->input();
     $input['invoice_id'] = Invoice::getPrivateId($input['invoice']);
     $input['client_id'] = Client::getPrivateId($input['client']);
     $payment = $this->paymentRepo->save($input);
     if (Input::get('email_receipt')) {
         $this->contactMailer->sendPaymentConfirmation($payment);
         Session::flash('message', trans('texts.created_payment_emailed_client'));
     } else {
         Session::flash('message', trans('texts.created_payment'));
     }
     return redirect()->to($payment->client->getRoute());
 }
 /**
  * @return \Illuminate\Contracts\View\View
  */
 public function do_license_payment()
 {
     $testMode = Session::get('test_mode') === 'true';
     $rules = ['first_name' => 'required', 'last_name' => 'required', 'email' => 'required', 'card_number' => 'required', 'expiration_month' => 'required', 'expiration_year' => 'required', 'cvv' => 'required', 'address1' => 'required', 'city' => 'required', 'state' => 'required', 'postal_code' => 'required', 'country_id' => 'required'];
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return redirect()->to('license')->withErrors($validator)->withInput();
     }
     $account = $this->accountRepo->getNinjaAccount();
     $account->load('account_gateways.gateway');
     $accountGateway = $account->getGatewayByType(GATEWAY_TYPE_CREDIT_CARD);
     try {
         $affiliate = Affiliate::find(Session::get('affiliate_id'));
         if ($testMode) {
             $ref = 'TEST_MODE';
         } else {
             $details = self::getLicensePaymentDetails(Input::all(), $affiliate);
             $gateway = Omnipay::create($accountGateway->gateway->provider);
             $gateway->initialize((array) $accountGateway->getConfig());
             $response = $gateway->purchase($details)->send();
             $ref = $response->getTransactionReference();
             if (!$response->isSuccessful() || !$ref) {
                 $this->error('License', $response->getMessage(), $accountGateway);
                 return redirect()->to('license')->withInput();
             }
         }
         $licenseKey = Utils::generateLicense();
         $license = new License();
         $license->first_name = Input::get('first_name');
         $license->last_name = Input::get('last_name');
         $license->email = Input::get('email');
         $license->transaction_reference = $ref;
         $license->license_key = $licenseKey;
         $license->affiliate_id = Session::get('affiliate_id');
         $license->product_id = Session::get('product_id');
         $license->save();
         $data = ['message' => $affiliate->payment_subtitle, 'license' => $licenseKey, 'hideHeader' => true, 'productId' => $license->product_id, 'price' => $affiliate->price];
         $name = "{$license->first_name} {$license->last_name}";
         $this->contactMailer->sendLicensePaymentConfirmation($name, $license->email, $affiliate->price, $license->license_key, $license->product_id);
         if (Session::has('return_url')) {
             $data['redirectTo'] = Session::get('return_url') . "?license_key={$license->license_key}&product_id=" . Session::get('product_id');
             $data['message'] = 'Redirecting to ' . Session::get('return_url');
         }
         return View::make('public.license', $data);
     } catch (\Exception $e) {
         $this->error('License-Uncaught', false, $accountGateway, $e);
         return redirect()->to('license')->withInput();
     }
 }