public function update($userId) { //Verify the user can access this user record - we don't need the record just the auth check $user = User::findWithPermission($userId); $input = \Input::all(); //Clear the profile photo field as this is handled separately below. unset($input['new_profile_photo']); if (empty($input['profile_photo_private'])) { $input['profile_photo_private'] = false; } //Trim all the data so some of the validation doesn't choke on spaces foreach ($input as $key => $value) { if (is_string($value)) { $input[$key] = trim($value); } } $this->profileValidator->validate($input, $userId); $this->profileRepo->update($userId, $input); if (\Input::file('new_profile_photo')) { try { $this->userImage->uploadPhoto($user->hash, \Input::file('new_profile_photo')->getRealPath(), true); $this->profileRepo->update($userId, ['new_profile_photo' => 1]); \Notification::success("Photo uploaded, it will be checked and appear shortly"); } catch (\Exception $e) { \Log::error($e); } } else { \Notification::success("Profile Updated"); } return \Redirect::route('members.show', $userId); }
/** * Start the creation of a new gocardless payment * Details get posted into this method and the redirected to gocardless * @param $userId * @throws \BB\Exceptions\AuthenticationException * @throws \BB\Exceptions\FormValidationException * @throws \BB\Exceptions\NotImplementedException */ public function store($userId) { User::findWithPermission($userId); $requestData = \Request::only(['reason', 'amount', 'return_path', 'stripeToken', 'ref']); $stripeToken = $requestData['stripeToken']; $amount = $requestData['amount']; $reason = $requestData['reason']; $returnPath = $requestData['return_path']; $ref = $requestData['ref']; try { $charge = Stripe_Charge::create(array("amount" => $amount, "currency" => "gbp", "card" => $stripeToken, "description" => $reason)); } catch (\Exception $e) { \Log::error($e); if (\Request::wantsJson()) { return \Response::json(['error' => 'There was an error confirming your payment'], 400); } \Notification::error("There was an error confirming your payment"); return \Redirect::to($returnPath); } //Replace the amount with the one from the charge, this prevents issues with variable tempering $amount = $charge->amount / 100; //Stripe don't provide us with the fee so this should be OK $fee = $amount * 0.024 + 0.2; $this->paymentRepository->recordPayment($reason, $userId, 'stripe', $charge->id, $amount, 'paid', $fee, $ref); if (\Request::wantsJson()) { return \Response::json(['message' => 'Payment made']); } \Notification::success("Payment made"); return \Redirect::to($returnPath); }
/** * Start the creation of a new balance payment * Details get posted into this method * @param $userId * @throws \BB\Exceptions\AuthenticationException * @throws \BB\Exceptions\FormValidationException * @throws \BB\Exceptions\NotImplementedException */ public function store($userId) { $user = User::findWithPermission($userId); $this->bbCredit->setUserId($user->id); $requestData = \Request::only(['reason', 'amount', 'return_path', 'ref']); $amount = $requestData['amount'] * 1 / 100; $reason = $requestData['reason']; $returnPath = $requestData['return_path']; $ref = $requestData['ref']; //Can the users balance go below 0 $minimumBalance = $this->bbCredit->acceptableNegativeBalance($reason); //What is the users balance $userBalance = $this->bbCredit->getBalance(); //With this payment will the users balance go to low? if ($userBalance - $amount < $minimumBalance) { if (\Request::wantsJson()) { return \Response::json(['error' => 'You don\'t have the money for this'], 400); } \Notification::error("You don't have the money for this"); return \Redirect::to($returnPath); } //Everything looks gooc, create the payment $this->paymentRepository->recordPayment($reason, $userId, 'balance', '', $amount, 'paid', 0, $ref); //Update the users cached balance $this->bbCredit->recalculate(); if (\Request::wantsJson()) { return \Response::json(['message' => 'Payment made']); } \Notification::success("Payment made"); return \Redirect::to($returnPath); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $user = User::findWithPermission($id); $input = $request->only('rules_agreed', 'induction_completed'); $this->inductionValidator->validate($input); $this->userRepository->recordInductionCompleted($id); return \Redirect::route('account.show', [$user->id]); }
public function index($userId) { //Verify the user can access this user record $user = User::findWithPermission($userId); $this->bbCredit->setUserId($user->id); $userBalance = $this->bbCredit->getBalanceFormatted(); $payments = $this->bbCredit->getBalancePaymentsPaginated(); return \View::make('account.bbcredit.index')->with('user', $user)->with('payments', $payments)->with('userBalance', $userBalance); }
/** * Remove cash from the users balance * * @param $userId * @return mixed * @throws \BB\Exceptions\AuthenticationException * @throws \BB\Exceptions\InvalidDataException */ public function destroy($userId) { $user = User::findWithPermission($userId); $this->bbCredit->setUserId($userId); $amount = \Request::get('amount'); $returnPath = \Request::get('return_path'); $ref = \Request::get('ref'); $minimumBalance = $this->bbCredit->acceptableNegativeBalance('withdrawal'); if ($user->cash_balance + $minimumBalance * 100 < $amount * 100) { \Notification::error("Not enough money"); return \Redirect::to($returnPath); } $this->paymentRepository->recordPayment('withdrawal', $userId, 'balance', '', $amount, 'paid', 0, $ref); $this->bbCredit->recalculate(); \Notification::success("Payment recorded"); return \Redirect::to($returnPath); }
/** * Processes the return for old gocardless payments * * @param $userId * @return \Illuminate\Http\RedirectResponse * @throws \BB\Exceptions\AuthenticationException */ public function handleManualReturn($userId) { $user = User::findWithPermission($userId); $confirm_params = array('resource_id' => $_GET['resource_id'], 'resource_type' => $_GET['resource_type'], 'resource_uri' => $_GET['resource_uri'], 'signature' => $_GET['signature']); // State is optional if (isset($_GET['state'])) { $confirm_params['state'] = $_GET['state']; } //Get the details, reason, reference and return url $details = explode(':', \Input::get('state')); $reason = 'unknown'; $ref = null; $returnPath = route('account.show', [$user->id], false); if (is_array($details)) { if (isset($details[0])) { $reason = $details[0]; } if (isset($details[1])) { $ref = $details[1]; } if (isset($details[2])) { $returnPath = $details[2]; } } //Confirm the resource try { $confirmed_resource = $this->goCardless->confirmResource($confirm_params); } catch (\Exception $e) { \Notification::error($e->getMessage()); return \Redirect::to($returnPath); } //Store the payment $fee = $confirmed_resource->amount - $confirmed_resource->amount_minus_fees; $paymentSourceId = $confirmed_resource->id; $amount = $confirmed_resource->amount; $status = $confirmed_resource->status; //The record payment process will make the necessary record updates $this->paymentRepository->recordPayment($reason, $userId, 'gocardless', $paymentSourceId, $amount, $status, $fee, $ref); \Notification::success("Payment made"); return \Redirect::to($returnPath); }
/** * 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); }
/** * Remove the specified resource from storage. * * @param int $id * @return Illuminate\Http\RedirectResponse */ public function destroy($userId, $id = null) { /** * TODO: Check for and cancel pending sub charges */ $user = User::findWithPermission($userId); if ($user->payment_method == 'gocardless') { try { $subscription = $this->goCardless->cancelSubscription($user->subscription_id); if ($subscription->status == 'cancelled') { $user->cancelSubscription(); \Notification::success('Your subscription has been cancelled'); return \Redirect::back(); } } catch (\GoCardless_ApiException $e) { if ($e->getCode() == 404) { $user->cancelSubscription(); \Notification::success('Your subscription has been cancelled'); return \Redirect::back(); } } } elseif ($user->payment_method == 'gocardless-variable') { $status = $this->goCardless->cancelPreAuth($user->subscription_id); if ($status) { $user->subscription_id = null; $user->payment_method = ''; $user->save(); $user->setLeaving(); $this->subscriptionChargeRepository->cancelOutstandingCharges($userId); \Notification::success('Your direct debit has been cancelled'); return \Redirect::back(); } } \Notification::error('Sorry, we were unable to cancel your subscription, please get in contact'); return \Redirect::back(); }
public function updateSubscriptionAmount($id) { $amount = \Input::get('monthly_subscription'); if ($amount < 5) { throw new ValidationException('The minimum subscription is 5 GBP'); } elseif (!\Auth::user()->isAdmin() && $amount < 15) { throw new ValidationException('The minimum subscription is 15 GBP, please contact the trustees for a lower amount. trustees@buildbrighton.com'); } $user = User::findWithPermission($id); $user->updateSubAmount(\Input::get('monthly_subscription')); \Notification::success('Details Updated'); return \Redirect::route('account.show', [$user->id]); }
/** * 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]); }
public function updateSubscriptionAmount($id) { $amount = \Input::get('monthly_subscription'); if ($amount < 5) { throw new ValidationException('The minimum subscription is 5 GBP'); } $user = User::findWithPermission($id); $user->updateSubAmount(\Input::get('monthly_subscription')); \Notification::success('Details Updated'); return \Redirect::route('account.show', [$user->id]); }