/** * Execute the job. * * @return void */ public function handle(UserRepositoryInterface $userRepo, BookingRepositoryInterface $bookingRepo, BillingGateway $gateway) { $user = $userRepo->find($this->user_id); $user->cardName = $this->cardName; $user->cardBrand = $this->cardBrand; $user->cardLastFour = $this->cardLastFour; $user->cardExpiryMonth = $this->cardExpiryMonth; $user->cardExpiryYear = $this->cardExpiryYear; $user->save(); $booking = $bookingRepo->findByReference($this->booking_reference); $bookedPackages = $booking->packages; $total = calculateTotalAmount($bookedPackages); $transaction = $gateway->charge($user, $total, $this->token); if ($transaction) { $bookingRepo->update($booking->id, ['booking_reference' => bookingReference($transaction), 'paid' => $transaction->paid, 'status' => $transaction->status, 'comments' => '']); event(new UserPaidTheBooking($user, $this->booking_reference)); } else { event(new UserPurchaseWasNotSuccessful($user)); /** * If payment is not successful, delete the user to avoid duplicating his/her * record on the "users" table */ //$userRepository->delete($user->id); } }
/** * Execute the job. * * @return void */ public function handle(UserRepositoryInterface $userRepo, BookingRepositoryInterface $bookingRepo, BillingGateway $gateway) { $user = $userRepo->find($this->user_id); $booking = $bookingRepo->findByReference($this->booking_reference); $bookedPackages = $booking->packages; $total = calculateTotalAmount($bookedPackages); $chargeWasSuccessful = $gateway->charge($user, $total, $this->token); if ($chargeWasSuccessful) { $bookingRepo->update($booking->id, ['status' => 1]); //event( new UserPaidTheBooking($user) ); } else { //event( new UserPurchaseWasNotSuccessful($user) ); /** * If payment is not successful, delete the user to avoid duplicating his/her * record on the "users" table */ //$userRepository->delete($user->id); } }