コード例 #1
0
 public function notification(Request $request)
 {
     try {
         $notificationCode = $request->get('notificationCode');
         $notificationType = $request->get('notificationType');
         if ($notificationType == 'transaction') {
             // Consultar detalhes da transação
             $transaction = $this->locator->getByNotification($notificationCode);
             // Pegar os detalhes
             $details = $transaction->getDetails();
             // Consultar a order através da referência passada no checkout
             $order = Order::find($details->getReference());
             // Atualizar o status da order para o status atual da transação
             $order->status = $details->getStatus();
             // Inserir o id da transação
             if (empty($order->transaction)) {
                 $order->transaction = $details->getCode();
             }
             // Salvar dados alterados
             $order->save();
             return response(null, 200);
         } else {
             throw new \Exception('Dados informados estão incorretos.');
         }
     } catch (\Exception $error) {
         return response($error->getMessage(), 500);
     }
 }
コード例 #2
0
 /**
  * @test
  */
 public function getByNotificationShouldDoAGetRequestAddingCredentialsData()
 {
     $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/notifications/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->getByNotification(1));
 }
コード例 #3
0
 public function status_change(Request $request, \PHPSC\PagSeguro\Purchases\Transactions\Locator $locator, Order $orderModel)
 {
     $notification_code = $request->get('notificationCode');
     $transaction = $locator->getByNotification($notification_code);
     $status = $transaction->getDetails()->getStatus();
     $code = $transaction->getDetails()->getCode();
     $order_id = $transaction->getDetails()->getReference();
     echo 'Notificação: ' . $notification_code . '<br>';
     echo 'Transação: ' . $code . '<br>';
     echo 'Order id: ' . $order_id . '<br>';
     echo 'Status: ' . $status . '<br>';
     $order = $orderModel->find($order_id);
     $order->update(['status' => $status, 'payment_code' => $code]);
 }