public function checkOut(Request $request)
 {
     $address = \StringHelper::filterString($request->input('address'));
     $name = \StringHelper::filterString($request->input('name'));
     $content = \StringHelper::filterString($request->input('comments'));
     $phone = \StringHelper::filterString($request->input('phone'));
     $count = Cart::count();
     if ($phone != "" && $name != "" && $content != "" && $count > 0) {
         $order = new Order();
         $order->order_name = $name;
         $order->status = 1;
         $order->active = 1;
         $order->order_comment = $content;
         $order->order_address = $address;
         $order->order_phone = $phone;
         $order->save();
         $cart = Cart::content();
         foreach ($cart as $item) {
             $order_detail = new OrderDetail();
             $order_detail->dish_id = $item->id;
             $order_detail->dish_number = $item->qty;
             $order_detail->order_id = $order->id;
             $order_detail->save();
         }
         Cart::destroy();
         return Redirect::to(url('menu'))->with('message', 'Order Success !. You can continue buy now !');
     } else {
         return Redirect::to(url('checkout'))->with('message', 'Order Fail !. Something Wrong !');
     }
 }
 /**
  * Finaliza o pedido recebendo a mesa como parametro da requisicao
  * abre o pedido, salva, e salva os itens no pedido.
  * @param Request $request
  */
 public function finalizarCarrinho(Request $request)
 {
     $itens = Cart::content();
     $pedido = new Pedido();
     $pedido->mesa = $request->mesa;
     $pedido->total = Cart::total();
     if (Cart::count() != 0) {
         $pedido->save();
     } else {
         Flash::success("Por favor, adicione algum item no pedido!");
     }
     Log::info($pedido);
     //por enquanto vai ser assim, mas pense numa maneira melhor
     //de retornar o pedido criado.
     $pedidoAtual = Pedido::orderBy('id', 'desc')->first();
     $itensPedidos = array();
     foreach ($itens as $iten) {
         $itemPedido = new ItemPedido();
         $itemPedido->nome = $iten->name;
         $itemPedido->preco = $iten->price;
         $itemPedido->quantidade = $iten->qty;
         $itensPedidos[] = $itemPedido;
     }
     if (Cart::count() != 0) {
         $pedidoAtual->itens()->saveMany($itensPedidos);
         $pedidoAtual->save();
         Cart::destroy();
         Flash::success("Pedido finalizado!");
     } else {
         Flash::error("Por favor, adicione algum item no pedido!");
     }
     return redirect()->back();
 }
 public function __construct()
 {
     View::share('pros', Product::take(8)->Where('status', 1)->orderBy('created_at', 'DESC')->get());
     View::share('customs', Product::take(8)->Where('type', 0)->orderBy('created_at', 'DESC')->get());
     View::share('products', Product::take(8)->Where('status', 1)->orderBy('created_at', 'DESC')->get());
     View::share('cus', Product::take(8)->Where('status', 1)->orderBy('created_at', 'ASC')->get());
     View::share('categories', Category::all());
     View::share('cart_content', Cart::content());
     View::share('count', Cart::count());
     View::share('total', Cart::total());
     View::share('set', Setting::find(1));
     View::share('tos', Cart::tos());
     View::share('transactions', Transaction::orderBy('created_at', 'desc')->paginate(10));
     View::share('settings', Setting::find(1));
     View::share('caty', Category::take(5)->orderBy('created_at', 'DESC')->get());
     View::share('payments', Payment::Where('status', 1)->get());
     View::share('customers', Customer::all());
     View::share('orders', Order::all());
     View::share('cat', Category::all());
     View::share('db', Product::take(6)->Where('status', 1)->orderBy('created_at', 'ASC')->get());
 }
 public function count()
 {
     return Cart::count(false);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store()
 {
     if (Cart::count() < 1) {
         return redirect('/');
         exit(1);
     }
     $subtotal = (double) Cart::total();
     $shipping = 5.0;
     $payer = Paypalpayment::Payer();
     $payer->setPaymentMethod('paypal');
     // ### Items
     // These repersent the items in the cart
     $itemsArray = array();
     $cartItems = Cart::content()->toArray();
     foreach ($cartItems as $cartItem) {
         $item = Paypalpayment::Item();
         $item->setCurrency('EUR');
         $item->setName($cartItem['name']);
         $item->setPrice($cartItem['price']);
         $item->setQuantity((string) $cartItem['qty']);
         $item->setSku($cartItem['id']);
         $itemsArray[] = $item;
     }
     // add item to list
     $item_list = Paypalpayment::ItemList();
     $item_list->setItems($itemsArray);
     $details = Paypalpayment::Details();
     $details->setShipping($shipping)->setSubtotal($subtotal);
     // ### Amount
     // Lets you specify a payment amount.
     // You can also specify additional details
     // such as shipping, tax.
     $amount = Paypalpayment::Amount();
     $amount->setCurrency("EUR");
     $amount->setTotal($subtotal + $shipping);
     $amount->setDetails($details);
     $transaction = Paypalpayment::Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Your transaction description');
     $redirect_urls = Paypalpayment::RedirectUrls();
     $redirect_urls->setReturnUrl(url('payment/ExecutePayment/?success=true'))->setCancelUrl(url('payment/ExecutePayment/?success=false'));
     $payment = Paypalpayment::Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     Log::info("cool ->" . var_export($payment->toArray(), true));
     try {
         $payment->create($this->_apiContext);
     } catch (Exception $e) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $e->getMessage() . PHP_EOL;
             $err_data = json_decode($e->getData(), true);
             exit;
         } else {
             die('Some error occur, sorry for inconvenient');
         }
     }
     // add payment ID to session
     // Session::put('paypal_payment_id', $payment->getId());
     // Session::put('bookId', $request->bookId);
     if (isset($redirect_url)) {
         // redirect to paypald
         return redirect($redirect_url);
     }
     // ### Get redirect url
     // The API response provides the url that you must redirect
     // the buyer to. Retrieve the url from the $payment->getLinks()
     // method
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirectUrl = $link->getHref();
             break;
         }
     }
     // ### Redirect buyer to PayPal website
     // Save the payment id so that you can 'complete' the payment
     // once the buyer approves the payment and is redirected
     // back to your website.
     //
     // It is not a great idea to store the payment id
     // in the session. In a real world app, you may want to
     // store the payment id in a database.
     $pay_id = $payment->getId();
     // store the payment_id
     $log = PayPalLog::firstOrNew(array("payment_id" => $pay_id));
     $log->save();
     Session::put('log_id', $log->id);
     if (isset($redirectUrl)) {
         return redirect($redirectUrl);
         exit;
     }
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     //adiciona o total de itens para que seja disponvel em toda as requisiçes.
     view()->share('totalItens', Cart::count());
     return $next($request);
 }