/** * This is a basic method for recording a payment transfer between two people * This should not exist and the normal balance payment controller should be used * If any more work is needed here please take the time and move it over! * * @param Request $request * @param integer $userId * * @return mixed * @throws ValidationException * @throws AuthenticationException */ public function recordTransfer(Request $request, $userId) { $user = User::findWithPermission($userId); $this->bbCredit->setUserId($user->id); $amount = $request->get('amount'); $targetUserId = $request->get('target_user_id'); $targetUser = $this->userRepository->getById($targetUserId); if ($targetUserId === $userId) { throw new ValidationException('Your\'e trying to send money to yourself, no!'); } //What is the users balance $userBalance = $this->bbCredit->getBalance(); //With this payment will the users balance go to low? if ($userBalance - $amount < 0) { \Notification::error("You don't have the money for this"); return \Redirect::route('account.balance.index', $user->id); } $this->paymentRepository->recordBalanceTransfer($user->id, $targetUser->id, $amount); \Notification::success("Transfer made"); return \Redirect::route('account.balance.index', $user->id); }