public function place_order(Order $orderModel, OrderItems $orderItems, CheckoutService $checkoutService)
 {
     if (!Session::has('cart')) {
         return false;
     }
     $cart = Session::get('cart');
     $categories = Category::all();
     if ($cart->getTotal() > 0) {
         $order = $orderModel::create(['user_id' => Auth::User()->id, 'total' => $cart->getTotal(), 'status' => '0']);
         foreach ($cart->all() as $id => $item) {
             $order->items()->create(['order_id' => $order->id, 'product_id' => $id, 'price' => $item['price'], 'qtd' => $item['qtd']]);
         }
         $checkout = $checkoutService->createCheckoutBuilder();
         $checkout->setReference($order->id);
         foreach ($order->items as $order_item) {
             $checkout->addItem(new Item($order_item->product_id, $order_item->product->name, $order_item->price));
         }
         $response = $checkoutService->checkout($checkout->getCheckout());
         $order->update(['payment_code' => $response->getCode()]);
         event(new CheckoutEvent($order, Auth::user()));
         $cart->clear();
         return redirect($response->getRedirectionUrl());
         //return view('checkout.place_order', ['order'=>$order, 'cart'=>'saved', 'categories'=>$categories]);
     }
     return view('checkout.place_order', ['cart' => 'empty', 'categories' => $categories]);
 }
 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]);
     }
 }
 public function payOrder($orderId, Order $orderModel, CheckoutService $checkoutService)
 {
     $order = $orderModel->find($orderId);
     $this->session->set('orderId', $orderId);
     if ($order) {
         if ($order->user_id == Auth::user()->id) {
             $checkout = $checkoutService->createCheckoutBuilder();
             foreach ($order->items as $item) {
                 $checkout->addItem(new Item($item->product_id, $item->product->name, $item->price));
             }
             $response = $checkoutService->checkout($checkout->getCheckout());
             return redirect($response->getRedirectionUrl());
         }
     }
     return view("errors.noorders");
 }
 public function place(CheckoutService $checkoutService, Order $orderModel, OrderItem $orderItem)
 {
     if (!Session::has('cart')) {
         return false;
     }
     $categories = Category::all();
     $cart = Session::get('cart');
     if ($cart->getTotal() > 0) {
         $checkout = $checkoutService->createCheckoutBuilder();
         foreach ($cart->all() as $k => $item) {
             $checkout->addItem(new Item($k, $item['name'], number_format($item['price'], 2, '.', ','), $item['qtd']));
         }
         event(new \CodeCommerce\Events\CheckoutEvent(Auth::user()));
         $response = $checkoutService->checkout($checkout->getCheckout());
         return redirect($response->getRedirectionUrl());
     }
     return view('store.checkout', ['cart' => 'empty', 'categories' => $categories]);
 }
 public function place(Order $orderModel, CheckoutService $checkoutService)
 {
     if (!Session::has('cart')) {
         return "Não existe sessão";
     }
     $cart = Session::get('cart');
     if ($cart->getTotal() > 0) {
         $checkout = $checkoutService->createCheckoutBuilder();
         foreach ($cart->all() as $k => $item) {
             $checkout->addItem(new Item($k, $item['name'], number_format($item['price'], 2, ".", ""), $item['qtd']));
         }
         event(new CheckoutEvent());
         $response = $checkoutService->checkout($checkout->getCheckout());
         return redirect($response->getRedirectionUrl());
     }
     $categories = Category::all();
     return view('store.checkout', ['cart' => 'empty', 'categories' => $categories]);
 }
 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]);
 }
Beispiel #7
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');
 }
 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');
     }
 }
 public function place(Order $orderModel, OrderItem $ordemItemMobel, CheckoutService $checkoutService)
 {
     $categories = Category::all();
     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(), 'status_id' => 1]);
         $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']]);
         }
         $cart->clear();
         event(new CheckoutEvent(Auth::user(), $order));
         $response = $checkoutService->checkout($checkout->getCheckout());
         return redirect($response->getRedirectionUrl());
     }
     return view('store.checkout', ['order' => 'empty', 'categories' => $categories]);
 }
 public function place(Order $orderModel, OrderItem $orderItem, 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();
         $categories = Category::all();
         //Auth::user() traz as infos do usuario
         //event(new CheckoutEvent(Auth::user(),$order));
         $response = $checkoutService->checkout($checkout->getCheckout());
         return redirect($response->getRedirectionUrl());
     }
     $categories = Category::all();
     return view('store.checkout', ['cart' => 'empty', 'categories' => $categories]);
 }
 public function place(Order $order, OrderItem $orderItem, CheckoutService $checkoutService)
 {
     if (!Session::has('cart')) {
         return false;
     }
     $cart = Session::get('cart');
     if ($cart->getTotal() > 0) {
         $checkout = $checkoutService->createCheckoutBuilder();
         $transactionReference = md5(Auth::user()->id . "_" . date("Ymd His") . "_" . $cart->getTotal());
         $order = $order->create(['user_id' => Auth::user()->id, 'total' => $cart->getTotal(), 'status' => 1, 'payment_transaction_reference' => $transactionReference]);
         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));
         $checkout->setReference($transactionReference);
         $checkout->setRedirectTo(route('transaction.return', ['transaction_reference' => $transactionReference]));
         $response = $checkoutService->checkout($checkout->getCheckout());
         return redirect($response->getRedirectionUrl());
     } else {
         return redirect()->route('cart');
     }
 }
 public function test(CheckoutService $checkoutService)
 {
     $checkout = $checkoutService->createCheckoutBuilder()->addItem(new Item(1, 'Televisão LED 500', 8999.99))->addItem(new Item(2, 'Video-game mega ultra blaster', 799.99))->getCheckout();
     $response = $checkoutService->checkout($checkout);
     return redirect($response->getRedirectionUrl());
 }
 /**
  * @test
  */
 public function createCheckoutBuilderShouldReturnANewBuilderInstance()
 {
     $service = new CheckoutService($this->credentials, $this->client, $this->serializer);
     $this->assertInstanceOf('PHPSC\\PagSeguro\\Requests\\CheckoutBuilder', $service->createCheckoutBuilder());
 }
 /**
  * @test
  */
 public function createCheckoutBuilderShouldReturnANewBuilderInstance()
 {
     $service = new CheckoutService($this->credentials, $this->client, $this->serializer);
     $this->assertInstanceOf(CheckoutBuilder::class, $service->createCheckoutBuilder());
 }