/**
  * 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, BillingGateway $gateway, ShoppingCart $cart)
 {
     $data = ['name' => $this->name, 'email' => $this->email, 'phone' => $this->phone, 'address1' => $this->address1, 'address2' => $this->address2, 'city' => $this->city, 'state' => $this->state, 'country' => $this->country, 'cardName' => $this->cardName, 'cardBrand' => $this->cardBrand, 'cardLastFour' => $this->cardLastFour, 'cardExpiryMonth' => $this->cardExpiryMonth, 'cardExpiryYear' => $this->cardExpiryYear];
     $user = $userRepo->store($data);
     $transaction = $gateway->charge($user, $cart->total(), $this->token);
     if (!$transaction) {
         event(new UserPurchaseWasNotSuccessful($user));
         /**
          * If payment is not successful, delete the user to avoid duplicating his/her
          * record on the "users" table
          */
         $userRepo->delete($user->id);
         flash()->error(companyName(), 'Your card was declined.');
         return redirect()->back();
     }
     /**
      * Save the data to "bookings" table
      */
     $booking = $user->bookings()->create(['booking_reference' => bookingReference($transaction), 'paid' => $transaction->paid, 'status' => $transaction->status, 'comments' => '']);
     foreach ($cart->content() as $item) {
         $packageId = $item->options->selectedPackage->id;
         $adult_quantity = $item->qty;
         $child_quantity = $item->options->child_quantity;
         /**
          * Save the data to "booking_details" table
          */
         $booking->packages()->attach($packageId, ['adult_quantity' => $adult_quantity, 'child_quantity' => $child_quantity, 'date' => $item->options->date, 'date_submit' => $item->options->date_submit, 'time' => $item->options->time, 'ticket' => $item->options->ticket]);
     }
     $cart->destroy();
     event(new UserPurchasedAPackage($user, $booking->booking_reference));
 }
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle(UserRepositoryInterface $userRepository, BillingGateway $gateway, ShoppingCart $cart)
 {
     $data = ['name' => $this->name, 'email' => $this->email, 'phone' => $this->phone, 'address1' => $this->address1, 'address2' => $this->address2, 'city' => $this->city, 'state' => $this->state, 'country' => $this->country];
     $user = $userRepository->store($data);
     $chargeWasSuccessful = $gateway->charge($user, $cart->total(), $this->token);
     if ($chargeWasSuccessful) {
         /**
          * Save the data to "bookings" table
          */
         $booking = $user->bookings()->create(['booking_reference' => bookingReference($chargeWasSuccessful), 'status' => 1, 'comments' => '']);
         foreach ($cart->content() as $item) {
             $packageId = $item->options->package->id;
             $adult_quantity = $item->qty;
             $child_quantity = $item->options->child_quantity;
             /**
              * Save the data to "booking_details" table
              */
             $booking->packages()->attach($packageId, ['adult_quantity' => $adult_quantity, 'child_quantity' => $child_quantity, 'date' => $item->options->date, 'date_submit' => $item->options->date_submit, 'time' => $item->options->time]);
         }
         $cart->destroy();
         event(new UserPurchasedAPackage($user, $booking->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);
     }
 }