/** * Handle the event. * * @param SubscriptionPayment\FailedInsufficientFunds $event */ public function handle(SubscriptionPayment\FailedInsufficientFunds $event) { $user = $this->userRepository->getById($event->userId); $this->mailer->send('emails.sub-payment-failed', ['user' => $user], function ($m) use($user) { $m->to($user->email, $user->name)->subject('Your subscription payment failed'); }); }
/** * A sub charge has been rolled back as a payment failed * * @param integer $chargeId * @param integer $userId * @param Carbon $paymentDate * @param double $amount */ public function onPaymentFailure($chargeId, $userId, Carbon $paymentDate, $amount) { $paidUntil = MembershipPayments::lastUserPaymentExpires($userId); if ($paidUntil) { $user = $this->userRepository->getById($userId); /** @var $user \BB\Entities\User */ $user->extendMembership(null, $paidUntil); } else { \Log::info('Payment cancelled, expiry date rollback failed as there is no previous payment. User ID:' . $userId); } }
private function recordDoorKeyPaymentId($userId, $paymentId) { /* @TODO: Verify payment amount is valid - this could have been changed */ $user = $this->userRepository->getById($userId); $user->key_deposit_payment_id = $paymentId; $user->save(); }
/** * 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); }
/** * Update a payment * Change where the money goes by altering the original record or creating a secondary payment * * @param Request $request * @param int $paymentId * * @return Illuminate\Http\RedirectResponse * @throws NotImplementedException * @throws \BB\Exceptions\PaymentException */ public function update(Request $request, $paymentId) { $payment = $this->paymentRepository->getById($paymentId); switch ($request->get('change')) { case 'assign-unknown-to-user': $newUserId = $request->get('user_id'); try { $newUser = $this->userRepository->getById($newUserId); } catch (ModelNotFoundException $e) { \Notification::error('User not found'); break; } $this->paymentRepository->assignPaymentToUser($paymentId, $newUser->id); \Notification::success('Payment updated'); break; case 'refund-to-balance': $this->paymentRepository->refundPaymentToBalance($paymentId); \Notification::success('Payment updated'); break; default: throw new NotImplementedException('This hasn\'t been built yet'); } return \Redirect::back(); }
/** * Handle the event. * * @param SubscriptionChargePaid $event */ public function handle(SubscriptionChargePaid $event) { /** @var $user \BB\Entities\User */ $user = $this->userRepository->getById($event->subscriptionCharge->user_id); $user->extendMembership(null, $event->subscriptionCharge->payment_date->addMonth()); }
/** * @param mixed $userId */ public function setUserId($userId) { $this->userId = $userId; $this->user = $this->userRepository->getById($this->userId); }