Automatic payment notification PagSeguro

0

Following the PagSeguro Documentation , I want to implement the notification when changing payment status. For this, I'm trying this way:

After the purchase, the information below appears in the sandbox:

WhenIchangetheStatusforPayment:

SystemStatusdoesnotchange.See:

ThecodeI'musingfollowsbelow:

Checkout

<?php//ColoqueioidPedidomanualmente//$pedido=preg_replace('/[^[:alnum:]-]/','',$_POST["idPedido"]);
  $data["token"] = 'XXXXXXX';
  $data["email"] = '[email protected]';
  $data['currency'] = 'BRL';
  $data['itemId1'] = '1';
  $data['itemQuantity1'] = '1';
  $data['itemDescription1'] = 'PEDIDO DE TESTE';
  $data['itemAmount1'] = '299.00';
  $data['reference'] = '1';
  $url = 'https://ws.sandbox.pagseguro.uol.com.br/v2/checkout';
  $data = http_build_query($data);
  $curl = curl_init($url);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($curl, CURLOPT_SSL_VERIFYFEER, false);
  //curl_setopt($curl, CURLOPT_URL, $url);
  curl_setopt($curl, CURLOPT_POST, true);
  curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  $xml = curl_exec($curl);
  curl_close($curl);
  $xml = simplexml_load_string($xml);
  echo $xml->code;
?>

Return page for notification

<?php
require_once("conexao.php");
//$noficationCode = preg_replace('/[^[:alnum:]-]/','',$_POST["notificationCode"]);
$noficationCode = $_POST['notificationCode'];
//$data["token"] = 'XXXXXXX';
//$data["email"] = '[email protected]';
//$data = http_build_query($data);
//$url = 'https://ws.pagseguro.uol.com.br/v3/transactions/notifications/'.$noficationCode.'?'.$data;
$url = "https://ws.pagseguro.uol.com.br/v2/transactions/notifications/".$notificationCode."[email protected]&token=XXXXXXXXXX";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
//curl_setopt($curl,CURLOPT_URL,$url);
$http = curl_getinfo($curl);
$xml = curl_exec($curl);
curl_close($curl);
$xml = simplexml_load_string($xml);
$reference = $xml->reference; // pedido
$status = $xml->status; // status da compra
//if($reference && $status){
  mysqli_query($conexao,"UPDATE pedidos SET StatusPagamentos = '".$status."' WHERE IdPedidos = '".$reference."';");
//}
?>

The commented codes have been the attempts I've made, it's running remotely and CURL is active on the server.

    
asked by anonymous 08.12.2018 / 13:04

0 answers