public function fire()
 {
     $this->info(date('Y-m-d') . ' ChargeRenewalInvoices...');
     $ninjaAccount = $this->accountRepo->getNinjaAccount();
     $invoices = Invoice::whereAccountId($ninjaAccount->id)->whereDueDate(date('Y-m-d'))->where('balance', '>', 0)->with('client')->orderBy('id')->get();
     $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);
         if (!$account) {
             continue;
         }
         $company = $account->company;
         if (!$company->plan || $company->plan == PLAN_FREE) {
             continue;
         }
         try {
             $this->info("Charging invoice {$invoice->invoice_number}");
             $this->paymentService->autoBillInvoice($invoice);
         } catch (Exception $exception) {
             $this->info('Error: ' . $exception->getMessage());
         }
     }
     $this->info('Done');
 }
 /**
  * Handle the event.
  *
  * @param  UserSignedUp $event
  *
  * @return void
  */
 public function handle(UserSignedUp $event)
 {
     $user = Auth::user();
     if (Utils::isNinjaProd()) {
         $this->userMailer->sendConfirmation($user);
     } elseif (Utils::isNinjaDev()) {
         // do nothing
     } else {
         $this->accountRepo->registerNinjaUser($user);
     }
     session([SESSION_COUNTER => -1]);
 }
 /**
  * @return \Illuminate\Http\RedirectResponse
  */
 public function cancelAccount()
 {
     if ($reason = trim(Input::get('reason'))) {
         $email = Auth::user()->email;
         $name = Auth::user()->getDisplayName();
         $data = ['text' => $reason];
         $subject = 'Invoice Ninja - Canceled Account';
         $this->userMailer->sendTo(CONTACT_EMAIL, $email, $name, $subject, 'contact', $data);
     }
     $user = Auth::user();
     $account = Auth::user()->account;
     \Log::info("Canceled Account: {$account->name} - {$user->email}");
     Document::scope()->each(function ($item, $key) {
         $item->delete();
     });
     $this->accountRepo->unlinkAccount($account);
     if ($account->company->accounts->count() == 1) {
         $account->company->forceDelete();
     } else {
         $account->forceDelete();
     }
     Auth::logout();
     Session::flush();
     return Redirect::to('/')->with('clearGuestKey', true);
 }
 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');
 }
 /**
  * Handle the event.
  *
  * @param  UserLoggedIn  $event
  *
  * @return void
  */
 public function handle(UserLoggedIn $event)
 {
     $account = Auth::user()->account;
     if (empty($account->last_login)) {
         event(new UserSignedUp());
     }
     $account->last_login = Carbon::now()->toDateTimeString();
     $account->save();
     $users = $this->accountRepo->loadAccounts(Auth::user()->id);
     Session::put(SESSION_USER_ACCOUNTS, $users);
     HistoryUtils::loadHistory($users ?: Auth::user()->id);
     $account->loadLocalizationSettings();
     // if they're using Stripe make sure they're using Stripe.js
     $accountGateway = $account->getGatewayConfig(GATEWAY_STRIPE);
     if ($accountGateway && !$accountGateway->getPublishableStripeKey()) {
         Session::flash('warning', trans('texts.missing_publishable_key'));
     } elseif ($account->isLogoTooLarge()) {
         Session::flash('warning', trans('texts.logo_too_large', ['size' => $account->getLogoSize() . 'KB']));
     }
 }
Ejemplo n.º 6
0
 /**
  * @return \Illuminate\Http\Response
  */
 public function getLogoutWrapper()
 {
     if (Auth::check() && !Auth::user()->registered) {
         $account = Auth::user()->account;
         $this->accountRepo->unlinkAccount($account);
         if ($account->company->accounts->count() == 1) {
             $account->company->forceDelete();
         }
         $account->forceDelete();
     }
     $response = self::getLogout();
     Session::flush();
     return $response;
 }
Ejemplo n.º 7
0
 /**
  * @param $provider
  * @param $hasCode
  * @return \Illuminate\Http\RedirectResponse
  */
 public function execute($provider, $hasCode)
 {
     if (!$hasCode) {
         return $this->getAuthorization($provider);
     }
     $socialiteUser = Socialite::driver($provider)->user();
     $providerId = AuthService::getProviderId($provider);
     if (Auth::check()) {
         $user = Auth::user();
         $isRegistered = $user->registered;
         $email = $socialiteUser->email;
         $oauthUserId = $socialiteUser->id;
         $name = Utils::splitName($socialiteUser->name);
         $result = $this->accountRepo->updateUserFromOauth($user, $name[0], $name[1], $email, $providerId, $oauthUserId);
         if ($result === true) {
             if (!$isRegistered) {
                 Session::flash('warning', trans('texts.success_message'));
                 Session::flash('onReady', 'handleSignedUp();');
             } else {
                 Session::flash('message', trans('texts.updated_settings'));
                 return redirect()->to('/settings/' . ACCOUNT_USER_DETAILS);
             }
         } else {
             Session::flash('error', $result);
         }
     } else {
         if ($user = $this->accountRepo->findUserByOauth($providerId, $socialiteUser->id)) {
             Auth::login($user, true);
             event(new UserLoggedIn());
         } else {
             Session::flash('error', trans('texts.invalid_credentials'));
             return redirect()->to('login');
         }
     }
     $redirectTo = Input::get('redirect_to') ?: 'dashboard';
     return redirect()->to($redirectTo);
 }
Ejemplo n.º 8
0
 /**
  * @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();
     }
 }