/**
  * 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));
 }
 public function onCheckout(CartCheckoutRequest $request)
 {
     $userInput = ['name' => $request->name, 'email' => $request->email, 'phone' => $request->phone, 'address1' => $request->address1, 'address2' => $request->address2, 'city' => $request->city, 'state' => $request->state, 'country' => $request->country, 'cardName' => $request->cardName, 'cardBrand' => $request->cardBrand, 'cardLastFour' => $request->cardLastFour, 'cardExpiryMonth' => $request->cardExpiryMonth, 'cardExpiryYear' => $request->cardExpiryYear];
     $user = $this->user->store($userInput);
     $transaction = $this->gateway->charge($user, ShoppingCart::total(), $request->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
          */
         $this->user->delete($user->id);
         flash()->error('Your card was declined. Please try again.');
         return redirect()->back()->withInput();
     }
     $bookingData = ['booking_reference' => bookingReference($transaction), 'paid' => $transaction->paid, 'status' => $transaction->status, 'comments' => ''];
     $booking = $this->booking->createBooking($user, $bookingData);
     /**
      * Attach the selected packages on the bookings table
      */
     $this->booking->attachPackages($booking, ShoppingCart::content());
     /**
      * Delete the Booked items
      */
     ShoppingCart::destroy();
     /**
      * Fire off an event
      */
     event(new UserPurchasedAPackage($user, $booking->booking_reference));
     flash()->overlay('You have successfully booked the Package(s).');
     return redirect()->route('cart.checkout.success');
 }
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle(PackageRepositoryInterface $package, TicketRepositoryInterface $ticketOption)
 {
     $selectedPackage = $package->find($this->package_id);
     $adultPrice = $selectedPackage->adult_price;
     $ticketId = $this->ticket;
     if ($selectedPackage->has_ticket_option) {
         $ticket = $ticketOption->find($this->ticket);
         $duration = $ticket->duration;
         $adultPrice = $ticket->adultPrice;
         $ticketId = $ticket->id;
     }
     $data = ['id' => $selectedPackage->id, 'name' => $selectedPackage->name, 'qty' => (int) $this->quantity, 'price' => $adultPrice, 'options' => ['child_quantity' => $this->child_quantity, 'date' => $this->date, 'date_submit' => $this->date_submit, 'time' => $this->time, 'ticket' => $ticketId, 'selectedPackage' => $selectedPackage]];
     ShoppingCart::add($data);
     event(new ItemWasAddedOnTheCart($data));
     return $data;
 }
 private function addNewItem()
 {
     $package = factory(App\Package::class)->create();
     $item = ['id' => $package->id, 'name' => $package->name, 'qty' => 2, 'price' => $package->adult_price, 'options' => ['child_quantity' => 1, 'date' => 'February 11, 2016', 'date_submit' => '', 'selectedPackage' => $package]];
     return ShoppingCart::add($item);
 }
 public function total()
 {
     return ShoppingCart::total();
 }