/**
  * Update the specified resource in storage.
  *
  * @param      $userId
  * @param  int $id
  * @throws \BB\Exceptions\NotImplementedException
  * @return \Illuminate\Http\RedirectResponse
  */
 public function update($userId, $id)
 {
     $induction = Induction::findOrFail($id);
     if (\Input::get('mark_trained', false)) {
         $induction->trained = \Carbon\Carbon::now();
         $induction->trainer_user_id = \Input::get('trainer_user_id', false);
         $induction->save();
     } elseif (\Input::get('is_trainer', false)) {
         $induction->is_trainer = true;
         $induction->save();
     } else {
         throw new \BB\Exceptions\NotImplementedException();
     }
     \Notification::success("Updated");
     return \Redirect::route('account.show', $userId);
 }
 /**
  * Store a manual payment
  *
  * @param $userId
  * @throws \BB\Exceptions\AuthenticationException
  * @throws \BB\Exceptions\FormValidationException
  * @throws \BB\Exceptions\NotImplementedException
  * @return Illuminate\Http\RedirectResponse
  * @deprecated
  */
 public function store($userId)
 {
     $user = User::findWithPermission($userId);
     if (!\Auth::user()->hasRole('admin') && !\Auth::user()->hasRole('finance')) {
         throw new \BB\Exceptions\AuthenticationException();
     }
     \Log::debug('Manual payment endpoint getting hit. account/{id}/payment. paymentController@store ' . json_encode(\Input::all()));
     $reason = \Input::get('reason');
     if ($reason == 'subscription') {
         $payment = new Payment(['reason' => $reason, 'source' => \Input::get('source'), 'source_id' => '', 'amount' => $user->monthly_subscription, 'amount_minus_fee' => $user->monthly_subscription, 'status' => 'paid']);
         $user->payments()->save($payment);
         $user->extendMembership(\Input::get('source'), \Carbon\Carbon::now()->addMonth());
     } elseif ($reason == 'induction') {
         if (\Input::get('source') == 'manual') {
             $ref = \Input::get('induction_key');
             ($item = $this->equipmentRepository->findBySlug($ref)) || App::abort(404);
             $payment = new Payment(['reason' => $reason, 'source' => 'manual', 'source_id' => '', 'amount' => $item->cost, 'amount_minus_fee' => $item->cost, 'status' => 'paid']);
             $payment = $user->payments()->save($payment);
             Induction::create(['user_id' => $user->id, 'key' => $ref, 'paid' => true, 'payment_id' => $payment->id]);
         } else {
             throw new \BB\Exceptions\NotImplementedException();
         }
     } elseif ($reason == 'door-key') {
         $payment = new Payment(['reason' => $reason, 'source' => \Input::get('source'), 'source_id' => '', 'amount' => 10, 'amount_minus_fee' => 10, 'status' => 'paid']);
         $user->payments()->save($payment);
         $user->key_deposit_payment_id = $payment->id;
         $user->save();
     } elseif ($reason == 'storage-box') {
         $payment = new Payment(['reason' => $reason, 'source' => \Input::get('source'), 'source_id' => '', 'amount' => 5, 'amount_minus_fee' => 5, 'status' => 'paid']);
         $user->payments()->save($payment);
         $user->storage_box_payment_id = $payment->id;
         $user->save();
     } elseif ($reason == 'balance') {
         $amount = \Input::get('amount') * 1;
         //convert the users amount into a number
         if (!is_numeric($amount)) {
             $exceptionErrors = new \Illuminate\Support\MessageBag(['amount' => 'Invalid amount']);
             throw new \BB\Exceptions\FormValidationException('Not a valid amount', $exceptionErrors);
         }
         $payment = new Payment(['reason' => 'balance', 'source' => \Input::get('source'), 'source_id' => '', 'amount' => $amount, 'amount_minus_fee' => $amount, 'status' => 'paid']);
         $user->payments()->save($payment);
         $memberCreditService = \App::make('\\BB\\Services\\Credit');
         $memberCreditService->setUserId($user->id);
         $memberCreditService->recalculate();
         //This needs to be improved
         \Notification::success('Payment recorded');
         return \Redirect::route('account.bbcredit.index', $user->id);
     } else {
         throw new \BB\Exceptions\NotImplementedException();
     }
     \Notification::success('Payment recorded');
     return \Redirect::route('account.show', [$user->id]);
 }
 private function createInductionRecord($userId, $ref, $paymentId)
 {
     /* @TODO: Replace with a repo */
     /* @TODO: Verify payment amount is valid - this could have been changed */
     Induction::create(['user_id' => $userId, 'key' => $ref, 'paid' => true, 'payment_id' => $paymentId]);
 }
 /**
  * Fetch an induction record by its associated payment
  * @param $paymentId
  * @return mixed
  */
 public function getByPaymentId($paymentId)
 {
     return $this->model->where('payment_id', $paymentId)->first();
 }