Beispiel #1
0
 public function payment(Request $request)
 {
     try {
         $idTransaction = $request->get('id');
         // Consultar detalhes da transação
         $transaction = $this->locator->getByCode($idTransaction);
         if ($transaction) {
             // Pegar os detalhes
             $details = $transaction->getDetails();
             // Consultar a order através da referência passada no checkout
             $order = Order::find($details->getReference());
             // Inserir o status atual da transação
             $order->status = $details->getStatus();
             // Inserir o id da transação
             $order->transaction = $idTransaction;
             // Salvar dados
             $order->save();
             Session::set('checkout', $order);
             // Notificar cliente sobre seu novo pedido realizado
             event(new CheckoutEvent(Auth::user(), $order));
             return redirect()->route('checkout');
         } else {
             throw new \Exception('Dados informados estão incorretos.');
         }
     } catch (\Exception $error) {
         return redirect('/');
     }
 }
 public function retorno(Request $request, Locator $service, Order $orderModel)
 {
     $transactionId = $request->get('transaction_id');
     $transaction = $service->getByCode($transactionId);
     $orderId = $transaction->getDetails()->getReference();
     return view('store.retorno', compact('orderId'));
 }
 /**
  * @test
  */
 public function getByCodeShouldDoAGetRequestAddingCredentialsData()
 {
     $xml = simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?><data />');
     $this->client->expects($this->once())->method('get')->with('https://ws.test.com/v2/transactions/1?email=a%40a.com&token=t')->willReturn($xml);
     $this->decoder->expects($this->once())->method('decode')->with($xml)->willReturn($this->transaction);
     $service = new Locator($this->credentials, $this->client, $this->decoder);
     $this->assertSame($this->transaction, $service->getByCode(1));
 }
 public function retorno(Request $request, \PHPSC\PagSeguro\Purchases\Transactions\Locator $locator, Order $orderModel)
 {
     $transaction_code = $request->get('transaction_id');
     $transaction = $locator->getByCode($transaction_code);
     $status = $transaction->getDetails()->getStatus();
     $code = $transaction->getDetails()->getCode();
     $order_id = $transaction->getDetails()->getReference();
     $order = $orderModel->find($order_id);
     $order->update(['status' => $status, 'payment_code' => $code]);
     return redirect()->route('account.orders');
 }
 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 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 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');
 }