I don’t get POST sandbox in my Pagseguro (PHP) notifications URL

Asked

Viewed 668 times

1

In the TOTAL absence of any return in the community of pagseguro dev I am here to see if any good soul has any suggestions. I can’t receive the notifications sent by Sandbox from pagseguro, actually sandbox (apparently) or send. There are no request attempts in my URL from my server logs.

There is, of course, the possibility of the problem being the sandbox. But I would like to eliminate all possible problems to be sure.

By entering the code of the GET notification or by doing the ARC POST test the script runs right. That’s it:

<?php
header("access-control-allow-origin: https://sandbox.pagseguro.uol.com.br");

$notificationCode = preg_replace('/[^[:alnum:]-]/','',$_GET["notificationCode"]);

$data = array(
    'email' => ' ',
    'token' => ' '
);

$data = http_build_query($data);

$url = 'https://ws.sandbox.pagseguro.uol.com.br/v3/transactions/notifications/'.$notificationCode.'?'.$data;

$curl = curl_init($url);
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
        curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);

$retorno = curl_exec($curl);

curl_close($curl);

$retorno = simplexml_load_string($retorno);

$codigoTransacao = $retorno->code;

$fp = fopen("logNotifications.txt", "a");
$escreve = fwrite($fp, "\n CÓDIGO DA TRANSAÇÃO PRA TESTE: {$codigoTransacao}");
fclose($fp);

?>

I have tried to change the CURL parameters by removing the CURLOPT_HTTP_VERSION and CURLLOPT_SLVERSION, changing the CURLOPT_SSL_VERIFYPEER to false... nothing solves.

I read that Sandbox only operates on SSL and TLS version 1.2, my notification URL is https:// and my server data is:

OS: Linux
PHP version: 5.6.36
curl version: 7.59.0
SSL version: OpenSSL/1.0.2o
SSL version number: 0
OPENSSL_VERSION_NUMBER: 100020ff
TLS test (default): TLS 1.2
TLS test (TLS_v1): TLS 1.2
TLS test (TLS_v1_2): TLS 1.2

I already tried sending the notification url during the purchase to pay by code, and without sending. The notification url is configured in the sandbox integration profiles both in the seller and in the application and is hopeless. The return is always that when I try to send:

inserir a descrição da imagem aqui

If I clear the notification field right there in the transaction details, it generates a log stating that the notification URL is invalid. This made me wonder if there is a problem with my receiving URL.

I already tested to see if there was any block on the server related to pagseguro URL, nothing.

# ping ws.sandbox.pagseguro.uol.com.br
PING ws.sandbox.pagseguro.uol.com.br (186.234.51.18) 56(84) bytes of data.
64 bytes from 186.234.51.18 (186.234.51.18): icmp_seq=1 ttl=245 time=2.26 ms
64 bytes from 186.234.51.18 (186.234.51.18): icmp_seq=2 ttl=245 time=1.34 ms
^C
--- ws.sandbox.pagseguro.uol.com.br ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 1.349/1.806/2.263/0.457 ms

I believe it is not port problem also pq the server operates on 80 and 443(https) and by the documentation of pagseguro, that’s right.

I’ve tried the suggestion too here but the topic is old and according to Pagseguro community links, now TLS 1.2 is used. By Conscience Awakening I also tried to force in CURL TLS 1.0 and 1.1: nothing.

There’s something I’m missing?

  • What is the address of your receiving URL?

  • https:// [...].com.br/pagseguro/receive-notifications.php

1 answer

2

In case I can help someone one day, I put together a piece of code that worked for me. Follow below.

if(isset($_POST)){
   $notificationCode=$_POST["notificationCode"];
   $notificationType=$_POST["notificationType"];
   $email="e-mail da conta Pagseguro";
   $token="token da sandbox";

   $requisicao="https://ws.sandbox.pagseguro.uol.com.br/v2/transactions/notifications/".$notificationCode."?email=".$email."&token=".$token;

   $curl=curl_init($requisicao);
   curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
   curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
   $response=curl_exec($curl);
   curl_close($curl);
   if($response=='Unauthorized'){
     error_log((string)$response);
   }else{
     $response=simplexml_load_string($response);
     if(count($response->error)>0){
        error_log((string)$response);
     }else{
        error_log($response->code);
        error_log($response->status);
     }
}}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.