Esempio n. 1
0
 public function testevent()
 {
     $data = ['name' => 'uu', 'year' => '23'];
     //$data="ppp";
     //$response =\Event::fire(new \App\Events\sendmsgforcourse($data));
     //var_dump($response);
     // Event(new \App\Events\userlogin($data));
     Event("App\\Events\\userlogin", $data, true);
 }
 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]);
 }
Esempio n. 3
0
<?php

/* Route example */
$route = new Route('example', 'Index');
// Creating a route with a controller, the model will be extracted by the getModel method
$route->add(array('', 'index.html'), function () {
    // When the url is index.html -> call Closure
    echo 'Hello world';
});
$route->add(array('article-{id}.html', 'id' => '[0-9]+'), Query('getArticle', Get('id')), Action('showArticle'));
// Calling model method getArticle and giving result to controller method showArticle
$route->add(array('articles.html/{page?}', 'page' => '[0-9]+'), Query('getArticles', array(Get('page'), QUERY_ELSE => 0)), Action('showArticles'));
// Then feeding the result to showArticles method
$route->add('article-create', Permission(), Event('getFormEvent', array(Query('newArticle', Get('name')), Action('showArticle'), EVENT_ELSE => Action('writeArticle'))));
// // If the form isn't completed, show the writeArticle form
return $route;