getNinjaAccount() public method

public getNinjaAccount ( )
 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');
 }
 /**
  * @return \Illuminate\Http\RedirectResponse
  */
 public function changePlan()
 {
     $user = Auth::user();
     $account = $user->account;
     $company = $account->company;
     $plan = Input::get('plan');
     $term = Input::get('plan_term');
     $numUsers = Input::get('num_users');
     $planDetails = $account->getPlanDetails(false, false);
     $newPlan = ['plan' => $plan, 'term' => $term, 'num_users' => $numUsers];
     $newPlan['price'] = Utils::getPlanPrice($newPlan);
     $credit = 0;
     if (!empty($planDetails['started']) && $plan == PLAN_FREE) {
         // Downgrade
         $refund_deadline = clone $planDetails['started'];
         $refund_deadline->modify('+30 days');
         if ($plan == PLAN_FREE && $refund_deadline >= date_create()) {
             if ($payment = $account->company->payment) {
                 $ninjaAccount = $this->accountRepo->getNinjaAccount();
                 $paymentDriver = $ninjaAccount->paymentDriver();
                 $paymentDriver->refundPayment($payment);
                 Session::flash('message', trans('texts.plan_refunded'));
                 \Log::info("Refunded Plan Payment: {$account->name} - {$user->email}");
             } else {
                 Session::flash('message', trans('texts.updated_plan'));
             }
         }
     }
     if (!empty($planDetails['paid']) && $plan != PLAN_FREE) {
         $time_used = $planDetails['paid']->diff(date_create());
         $days_used = $time_used->days;
         if ($time_used->invert) {
             // They paid in advance
             $days_used *= -1;
         }
         $days_total = $planDetails['paid']->diff($planDetails['expires'])->days;
         $percent_used = $days_used / $days_total;
         $credit = $planDetails['plan_price'] * (1 - $percent_used);
     }
     if ($newPlan['price'] > $credit) {
         $invitation = $this->accountRepo->enablePlan($newPlan, $credit);
         return Redirect::to('view/' . $invitation->invitation_key);
     } else {
         if ($plan != PLAN_FREE) {
             $company->plan_term = $term;
             $company->plan_price = $newPlan['price'];
             $company->num_users = $numUsers;
             $company->plan_expires = date_create()->modify($term == PLAN_TERM_MONTHLY ? '+1 month' : '+1 year')->format('Y-m-d');
         }
         $company->plan = $plan;
         $company->save();
         return Redirect::to('settings/account_management');
     }
 }
Ejemplo n.º 3
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();
     }
 }