Pay Notification API not executed

Asked

Viewed 1,920 times

2

I am using Pagseguro to manage payments, I use the method lightbox, where I can do everything, including payment (all this in sandbox).

But when receiving notifications, the file is not being called. Even if you have set the url inside Pagseguro.

See the image:

inserir a descrição da imagem aqui

My pag_retorno.php file is this:

<?php
    $name = 'arquivo.txt';
    $text = "chegou".date("Y-m-d H:i:s");
    $file = fopen($name, 'a');
    fwrite($file, $text);
    fwrite($file, $status);
    fclose($file);

    if(isset($_POST['notificationType']) && $_POST['notificationType'] == 'transaction'){

        $name = 'arquivo.txt';
        $text = "chegou";
        $file = fopen($name, 'a');
        fwrite($file, $text);
        fwrite($file, $status);
        fclose($file);

        $email = '[email protected]'; //ja esta configurado
        $token = 'meutoken'; //ja esta configurado

        $url = 'https://ws.sandbox.pagseguro.uol.com.br/v2/transactions/notifications/' . $_POST['notificationCode'] . '?email=' . $email . '&token=' . $token;

        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        $transaction= curl_exec($curl);
        curl_close($curl);

        if($transaction == 'Unauthorized'){
            print_r("nao autorizado");
            exit;
        }
        $transaction = simplexml_load_string($transaction);

        $status = $transaction -> status;

        $name = 'arquivo.txt';
        $text = var_export($_POST, true);
        $file = fopen($name, 'a');
        fwrite($file, $text);
        fwrite($file, $status);
        fclose($file);

        print_r($status);
    }
?>

As you can see, I even put up a date inscription and warning to know if at least the file was called, which is not happening. Someone could guide me on how to solve this?


Edited:

The same URL configuration was also done within the Sandbox environment.

  • Using Cloudflare? If so, this could be the problem. Otherwise, if you’re in sandbox, remember that notifications are manual.

  • @Gabrielsantos Não Não.

  • In sandbox, you have to go to https://sandbox.pagseguro.uol.com.br and generate the notifications manually. And it even works on localhost.

  • Yes, I’m doing it. But for some reason it’s not. I’m trying with their library and also with a php of its own (the one quoted in the post). In 4 attempts, one of them was received, the others gave an authentication failure (even reached the file) but now it stopped receiving again. Strange.

  • Two things: use http instead of https. Another thing: if there is "Unauthorized" error, it means the e-mail or token is wrong. The production token is different from the sandbox token.

  • Yes yes. The unauthorized part I know how to proceed. The https do not know if it will be possible to remove at the time. I think the problem was the lack of this line: header("access-control-allow-origin: https://sandbox.pagseguro.uol.com.br"); At least with their library it worked. I’ll try with my file now.

Show 1 more comment

1 answer

1


After a lot of headache, what solved my problem was this code:

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

Logo added to the opening tag PHP.

Just be aware for url release according to the environment. Sandbox or production.

Browser other questions tagged

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