Ejemplo n.º 1
0
 public function place()
 {
     if (!Session::has('cart')) {
         return false;
     }
     $cart = Session::get('cart');
     if ($cart->getTotal() > 0) {
         $order = $this->orderModel->create(['user_id' => Auth::user()->id, 'total' => $cart->getTotal()]);
         foreach ($cart->all() as $k => $item) {
             $order->items()->create(['product_id' => $k, 'price' => $item['price'], 'qtd' => $item['qtd']]);
         }
         $cart->clear();
         return view('store.checkout', compact('order'));
     }
     return view('store.checkout', ['cart' => 'empty']);
 }
 public function place(Order $orderModel, OrderItem $orderItem, CheckoutService $checkoutService, Factory $factory)
 {
     if (!Session::has('cart')) {
         return false;
     }
     $cart = Session::get('cart');
     if ($cart->getTotal() > 0) {
         $order = $orderModel->create(['user_id' => Auth::user()->id, 'total' => $cart->getTotal()]);
         // Criação da classe de checkout para integração com o pagseguro
         //$checkout = $checkoutService->createCheckoutBuilder();
         foreach ($cart->all() as $k => $item) {
             $order->items()->create(['product_id' => $k, 'price' => $item['price'], 'qtd' => $item['qtd']]);
             //$checkout->addItem(new Item($k, $item['name'], number_format($item['price'], 2, '.', ''), $item['qtd']));
         }
         $cart->clear();
         event(new CheckoutEvent(Auth::user(), $order));
         // Na verdade esse lugar não é exatamente o melhor lugar para se colocar o redirecionamento para
         // o pagseguro, porém por hora irá servir;
         //$response = $checkoutService->checkout($checkout->getCheckout());
         //return view('store.checkout', compact('order'));
         return view('store.checkout', ['order' => $order, 'cart' => 'vazio']);
         //return redirect($response->getRedirectionUrl());
     }
     return $factory->make('store.checkout', ['cart' => 'empty']);
     //return view('store.checkout', ['cart' => 'empty']);
 }
Ejemplo n.º 3
0
 public function place(Order $orderModel, OrderItem $ordemItem, CheckoutService $checkoutService)
 {
     if (!Session::has('cart')) {
         return "FALSE";
     }
     $cart = Session::get('cart');
     $categories = Category::all();
     if ($cart->getTotal() > 0) {
         $checkout = $checkoutService->createCheckoutBuilder();
         //pagseguro
         $order = $orderModel->create(['user_id' => Auth::user()->id, 'total' => $cart->getTotal()]);
         //inclui na tabela
         foreach ($cart->all() as $k => $item) {
             $checkout->addItem(new Item($k, $item['name'], number_format($item['price'], 2, ".", ""), $item['qtd']));
             //pagseguro
             $order->items()->create(['product_id' => $k, 'price' => $item['price'], 'qtd' => $item['qtd']]);
             //inclui na tabela
         }
         $cart->clear();
         event(new CheckoutEvent(Auth::user(), $order));
         $response = $checkoutService->checkout($checkout->getCheckout());
         //pagseguro
         return redirect($response->getRedirectionUrl());
         //pagseguro
         #return view('store.checkout', compact('cart', 'order', 'categories'));
     } else {
         return view('store.checkout', ['cart' => 'empty', 'categories' => $categories]);
     }
 }
Ejemplo n.º 4
0
 public function place(Order $orderModel, OrderItem $orderItem)
 {
     //Método plcae order, quando acessar esse método ele ira acessar o carrinho de comprar e começar a executar
     //os pedidos
     if (!Session::has('cart')) {
         return false;
     }
     $cart = Session::get('cart');
     // recupera o carrinho de compras
     if ($cart->getTotal() > 0) {
         //Order retorna um id que será o código da ORDER
         $order = $orderModel->create(['user_id' => Auth::user()->id, 'total' => $cart->getTotal()]);
         /*Método all corresponde ao método da classe Cart*/
         foreach ($cart->all() as $k => $item) {
             //Toda vez que der o save tem que passar a instancia lá para dentro
             $order->itens()->create(['product_id' => $k, 'price' => $item['price'], 'qtd' => $item['qtd']]);
         }
         // Para limpar o carrinho de compras
         $cart->clear();
         // Evento Checkout
         // Precisa passar o usuario, nome, order itens do pedido
         event(new CheckoutEvent(Auth::user(), $order));
         //event(new CheckoutEvent());
         return view('store.checkout', compact('order', 'cart'));
     }
     $categories = Category::all();
     return view('store.checkout', ['cart' => 'empty', 'categories' => $categories]);
 }
 public function place(Order $orderModel, OrderItem $orderItem, CheckoutService $checkoutService)
 {
     if (!Session::has('cart')) {
         return false;
     }
     $cart = Session::get('cart');
     $categories = Category::all();
     if (count(Auth::user()->address) <= 0) {
         return redirect()->route('account_address')->with('address_exist', 'Você precisa ter um endereço de entrega antes de finalizar compra!');
     }
     if ($cart->getTotal() > 0) {
         $checkout = $checkoutService->createCheckoutBuilder();
         $order = $orderModel->create(['user_id' => Auth::user()->id, 'total' => $cart->getTotal()]);
         foreach ($cart->all() as $k => $item) {
             $checkout->addItem(new Item($k, $item['name'], number_format($item['price'], 2, '.', ''), $item['qtd']));
             $order->items()->create(['product_id' => $k, 'price' => $item['price'], 'qtd' => $item['qtd']]);
         }
         // VER CONFIGURAÇÃO DE EMAIL
         // dd(Config::get('mail'));
         $cart->clear();
         event(new CheckoutEvent(Auth::user(), $order));
         $response = $checkoutService->checkout($checkout->getCheckout());
         // retorna para pagina interna do codecommerce
         //return view('store.checkout', compact('order', 'categories'));
         // retorna para pagina do pagseguro
         return redirect($response->getRedirectionUrl());
     }
     return view('store.checkout', ['cart' => 'empty', 'categories' => $categories]);
 }
Ejemplo n.º 6
0
 public function place()
 {
     if (!Session::has('cart')) {
         return redirect()->route('cart');
     }
     $cart = Session::get('cart');
     if ($cart->all() > 0) {
         $order = $this->order->create(['user_id' => $this->user->id, 'total' => $cart->getTotal()]);
         $checkout = $this->checkoutService->createCheckoutBuilder();
         $checkout->setReference($order->id);
         foreach ($cart->all() as $k => $item) {
             $checkout->addItem(new Item($k, $item['name'], number_format($item['price'], 2, '.', ''), $item['qtd']));
             $order->items()->create(['product_id' => $k, 'price' => $item['price'], 'qtd' => $item['qtd']]);
         }
         Session::forget('cart');
         $response = $this->checkoutService->checkout($checkout->getCheckout());
         return redirect($response->getRedirectionUrl());
     }
     return redirect()->route('cart');
 }
Ejemplo n.º 7
0
 public function place(Order $orderModel, OrderItem $orderItem)
 {
     if (!Session::has('cart')) {
         return false;
     }
     $cart = Session::get('cart');
     if ($cart->getTotal() > 0) {
         $order = $orderModel->create(['user_id' => Auth::user()->id, 'total' => $cart->getTotal()]);
         foreach ($cart->all() as $k => $item) {
             $order->items()->create(['product_id' => $k, 'price' => $item['price'], 'qtd' => $item['qtd']]);
         }
         dd($order->items);
     }
 }
 public function place(Order $orderModel, OrderItem $orderItem)
 {
     if (!Session::has('cart')) {
         return 'false';
     }
     $cart = Session::get('cart');
     if ($cart->getTotal() > 0) {
         $order = $orderModel->create(['user_id' => Auth::user()->id, 'total' => $cart->getTotal()]);
         foreach ($cart->all() as $key => $item) {
             $order->items()->create(['product_id' => $key, 'price' => $item['price'], 'qtd' => $item['qtd']]);
         }
     }
     Session::remove('cart');
     return redirect()->route('store.index');
 }
 public function place(Order $orderModel, OrderItem $orderItem)
 {
     if (!Session::has('cart')) {
         return false;
     }
     $cart = Session::get('cart');
     if ($cart->getTotal() > 0) {
         $order = $orderModel->create(['user_id' => Auth::user()->id, 'total' => $cart->getTotal()]);
         foreach ($cart->all() as $k => $item) {
             $order->items()->create(['product_id' => $k, 'price' => $item['price'], 'qtd' => $item['qtd']]);
         }
         $cart->clear();
         event(new CheckoutEvent(Auth::user(), $order));
         return view('store.checkout', compact('order', 'cart'));
     }
     $categories = Category::all();
     return view('store.checkout', compact('order'), ['cart' => 'empty', 'categories' => $categories]);
 }
Ejemplo n.º 10
0
 public function place(Order $orderModel, OrderItem $cart)
 {
     if (!Session::has('cart')) {
         return false;
     }
     $cart = Session::get('cart');
     if ($cart->getTotal() > 0) {
         $order = $orderModel->create(['user_id' => Auth::user()->id, 'total' => $cart->getTotal(), 'status_id' => 2]);
         foreach ($cart->all() as $k => $item) {
             $item = ['product_id' => $k, 'price' => $item['price'], 'quantity' => $item['qtd']];
             $order->items()->create($item);
         }
         $cart->clear();
         event(new CheckoutEvent($order));
         return view('store.checkout', compact('order'));
     }
     return view('store.checkout');
 }
 public function end(\Illuminate\Http\Request $request, Locator $service, Order $orderModel)
 {
     if (!Session::has('cart')) {
         return "Não existe sessão";
     }
     $cart = Session::get('cart');
     $transaction_code = $request->get('transaction_id');
     $transaction = $service->getByCode($transaction_code);
     $status = $transaction->getDetails()->getStatus();
     $payment_type = $transaction->getPayment()->getPaymentMethod()->getType();
     $netAmount = $transaction->getPayment()->getNetAmount();
     $order = $orderModel->create(['user_id' => Auth::user()->id, 'total' => $cart->getTotal(), 'status_id' => $status, 'transaction_code' => $transaction_code, 'payment_type_id' => $payment_type, 'netAmount' => $netAmount]);
     foreach ($cart->all() as $k => $item) {
         $order->items()->create(['product_id' => $k, 'price' => $item['price'], 'qtd' => $item['qtd']]);
     }
     $cart->clear();
     return redirect()->route('account.orders');
 }
 public function place(\CodeCommerce\Order $orderModel, \CodeCommerce\OrderItem $ordemItem, \CodeCommerce\Category $category)
 {
     if (!Session::has('cart')) {
         return false;
     }
     $cart = Session::get('cart');
     if ($cart->getTotal() > 0) {
         $order = $orderModel->create(['user_id' => Auth::user()->id, 'total' => $cart->getTotal()]);
         foreach ($cart->all() as $k => $item) {
             $items = $ordemItem->create(['order_id' => $order->id, 'product_id' => $k, 'price' => $item['price'], 'qtd' => $item['qtd']]);
         }
         $cart->clear();
         event(new \CodeCommerce\Events\CheckoutEvent(Auth::user(), $order));
         return view('store.checkout', compact('order'));
     }
     $categories = $category->all();
     return view('store.checkout', ['cartEmpty' => true, 'categories' => $categories]);
 }
 public function end(Locator $locator, Request $request, Order $orderModel)
 {
     if (!Session::has('cart')) {
         return "Sessão inexistente";
     }
     $cart = Session::get('cart');
     $transaction_code = $request->get('id_pagseguro');
     $transaction = $locator->getByCode($transaction_code);
     $status = $transaction->getDetails()->getStatus();
     $payment_type = $transaction->getPayment()->getPaymentMethod()->getType();
     $netAmount = $transaction->getPayment()->getNetAmount();
     $order = $orderModel->create(['user_id' => Auth::user()->id, 'total' => $cart->getTotal(), 'status_id' => $status, 'transaction_code' => $transaction_code, 'payment_type_id' => $payment_type, 'netAmount' => $netAmount]);
     foreach ($cart->all() as $k => $item) {
         $order->items()->create(['product_id' => $k, 'price' => $item['price'], 'qtd' => $item['qtd']]);
     }
     $cart->clear();
     return redirect()->route('home');
 }
 public function place(Order $orderModel, OrderItem $orderItem, CheckoutService $checkoutService)
 {
     // se não existir carrinho na sessão
     if (!Session::has('cart')) {
         // retorna false
         return false;
     }
     // pega os valores gravados na sessão cart
     $cart = Session::get('cart');
     //carrego as categries para exibir na coluna lateral
     $categories = Category::all();
     // se o total de items for maior que 0
     if ($cart->getTotal() > 0) {
         // atribui a variavel $checkout o builder da API do pagseguro
         $checkout = $checkoutService->createCheckoutBuilder();
         // cria o pedido passando um array com os items
         // Auth::user()->id pega o id od usuário logado
         $order = $orderModel->create(['user_id' => Auth::user()->id, 'total' => $cart->getTotal()]);
         // adiciona todos os items dentro da nossa ordem
         foreach ($cart->all() as $k => $item) {
             // adiciona os items do cart ao builder do pagseguro
             $checkout->addItem(new Item($item['id'], $item['name'], number_format($item['price'], 2, ".", ""), $item['qtd'], number_format(20, 2, ".", ""), 10));
             // insere no bd os items do cart
             $order->items()->create(['product_id' => $item['name'], 'price' => $item['price'], 'qtd' => $item['qtd']]);
         }
         $Phone = new Phone(11, 999999999);
         $Address = new Address('SP', 'Indaiatuba', '13330120', 'Centro', '13 de Maio', '110', 'Apto. 45B');
         //$Credentials = new Credentials('*****@*****.**', 'FE12A9050B864656A57AD8A315651DAE', 'sandbox');
         $checkout->setCustomer(new Customer("*****@*****.**", "Nome do Cliente", $Phone, $Address))->setShipping(new Shipping(1, $Address, number_format(10, 2, ".", "")));
         // chamo o metodo clear do model Cart.php para limpar o cart.
         // caso contrário, ele iria criar um novo pedido a cada refresh da página.
         $cart->clear();
         // dispara o evento passando para o CheckoutEvent os dados do User e do Order
         Event(new \CodeCommerce\Events\CheckoutEvent(Auth::user(), $order));
         // atribui a variavel $response os valores do builder, finalizando o checkout do pagseguro
         $response = $checkoutService->checkout($checkout->getCheckout());
         // redireciono para a tela de pagamento do pagseguro, passando o $response que contém os dados para o checkout
         return redirect($response->getRedirectionUrl());
         // retorno a view checkout com a order e as categories
         //return view('store.checkout', ['order'=>$order, 'categories'=>$categories]);
     }
     // retorno a view checkou com as categories
     return view('store.checkout', ['categories' => $categories]);
 }
 public function place(Order $orderModel, CheckoutService $checkoutService)
 {
     if (!Session::has('cart')) {
         return false;
     }
     $cart = Session::get('cart');
     if ($cart->getTotal() > 0) {
         $checkout = $checkoutService->createCheckoutBuilder();
         $order = $orderModel->create(['user_id' => Auth::user()->id, 'total' => $cart->getTotal()]);
         foreach ($cart->all() as $k => $item) {
             $checkout->addItem(new Item($k, $item['name'], number_format($item['price'], 2, ".", ""), $item['qtd']));
             $order->items()->create(['product_id' => $k, 'price' => $item['price'], 'qtd' => $item['qtd']]);
         }
         $cart->clear();
         $response = $checkoutService->checkout($checkout->getCheckout());
         return redirect($response->getRedirectionUrl());
     } else {
         return redirect()->route('cart');
     }
 }
Ejemplo n.º 16
0
 public function place(Order $orderModel, OrderItem $orderItem, CheckoutService $checkoutService)
 {
     if (!Session::has('cart')) {
         return false;
     }
     $checkout = $checkoutService->createCheckoutBuilder();
     $cart = Session::get('cart');
     $categories = Category::all();
     if ($cart->getTotal() > 0) {
         $order = $orderModel->create(['user_id' => Auth::user()->id, 'total' => $cart->getTotal(), 'status_id' => 1]);
         foreach ($cart->all() as $k => $item) {
             $checkout->addItem(new Item($k, $item['name'], number_format($item['price'], 2, ".", ""), $item['qtd']));
             $order->items()->create(['product_id' => $k, 'price' => $item['price'], 'qtd' => $item['qtd']]);
         }
         $cart->clear();
         event(new CheckoutEvent());
         $response = $checkoutService->checkout($checkout->getCheckout());
         return redirect($response->getRedirectionUrl());
         // return redirect()->route('account.orders');
     }
     return view('store.checkout', ['cart' => 'empty'], compact('categories'));
 }
Ejemplo n.º 17
0
 public function place(Order $orderModel)
 {
     if (!$this->session->has('cart')) {
         return false;
     }
     $cart = $this->session->get('cart');
     if ($cart->getTotal() > 0) {
         $userId = Auth::user()->id;
         $order = $orderModel->create(['user_id' => $userId, 'total' => $cart->getTotal(), 'status_id' => 1]);
         foreach ($cart->all() as $k => $item) {
             $order->items()->create(['product_id' => $k, 'price' => $item['price'], 'qtd' => $item['qtd']]);
         }
         $this->session->set('orderId', $order->id);
         $cart->clear();
         /**
          * Dispara evento:
          */
         //event(new CheckoutEvent(Auth::user(),$order));
         return view('store.checkout', compact('order'))->with(['cart' => '']);
     }
     return view('store.checkout', ['cart' => 'empty']);
 }
 public function retornoPagSeguro(\Illuminate\Http\Request $request, Locator $service, Order $orderModel)
 {
     if (!Session::has('cart')) {
         flash('carrinho vazio');
         return redirect()->route('store.index');
         return false;
     }
     $cart = Session::get('cart');
     $transactionCode = $request->get('transaction_id');
     $transaction = $service->getByCode($transactionCode);
     $status = $transaction->getDetails()->getStatus();
     $paymentType = $transaction->getPayment()->getPaymentMethod()->getType();
     $netAmount = $transaction->getPayment()->getNetAmount();
     // pedido gravar
     $order = $orderModel->create(['user_id' => Auth::user()->id, 'total' => $cart->getTotal(), 'status' => $status, 'status_pg' => $status, 'transaction_code' => $transactionCode, 'payment_type_id' => $paymentType, 'netAmount' => $netAmount]);
     foreach ($cart->all() as $k => $item) {
         //itens de pedido
         $order->items()->create(['product_id' => $k, 'price' => $item['price'], 'qtd' => $item['qtd']]);
     }
     $cart->clear();
     //limpar carrinho
     return redirect()->route('store.account.orders');
 }
 public function place(Order $orderModel, OrderItem $orderItem, \PHPSC\PagSeguro\Requests\Checkout\CheckoutService $checkoutService)
 {
     if (!Session::has('cart')) {
         return false;
     }
     if (Auth::check()) {
         $cart = Session::get('cart');
         if ($cart->getTotal() > 0) {
             $checkout = $checkoutService->createCheckoutBuilder();
             $order = $orderModel->create(['user_id' => Auth::User()->id, 'total' => $cart->getTotal()]);
             foreach ($cart->all() as $k => $item) {
                 $checkout->addItem(new Item($k, $item['name'], number_format($item['price'], 2, ".", ""), $item['qtd']));
                 $order->items()->create(['product_id' => $k, 'price' => $item['price'], 'qtd' => $item['qtd'], 'order_id' => $order]);
             }
             $cart->clear();
             event(new CheckoutEvent(Auth::User()->id, $order));
             $response = $checkoutService->checkout($checkout->getCheckout());
             return redirect($response->getRedirectionUrl());
             //return view('store.checkout', compact('order', 'cart'));
         }
     }
     $categories = Category::all();
     return view('store.checkout', ['cart' => 'empty', 'categories' => $categories]);
 }
Ejemplo n.º 20
0
 public function place(Order $orderModel, OrderItem $orderItem)
 {
     if (!Session::has('cart')) {
         return false;
     }
     $cart = Session::get('cart');
     if ($cart->getTotal() > 0) {
         $order = $orderModel->create(['user_id' => Auth::User()->id, 'total' => $cart->getTotal()]);
         foreach ($cart->all() as $key => $eachItem) {
             $order->items()->create(['product_id' => $key, 'price' => $eachItem['price'], 'qtd' => $eachItem['qtd'], 'total' => $eachItem['price'] * $eachItem['qtd']]);
         }
         /**
          * Clean cart.
          */
         $cart->clean();
         /**
          * Trigger Checkout Event.
          */
         event(new CheckoutEvent(Auth::user(), $order));
     } else {
         $order = null;
     }
     return view('store.checkout', compact('order'));
 }