Payback Notification API does not run

2

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

But at the time of receiving notifications, the file is not being called. Even though you have set up the url within PagSeguro.

See the image:

Myfilepag_retorno.phpisthis:

<?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 and notice alert to see if the file was called at least, which is not happening. Would anyone know how to fix this?

Edited:

The same URL setting was also made within the SandBox environment.

    
asked by anonymous 16.12.2015 / 18:43

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");

Added at the opening of the PHP tag.

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

    
16.12.2015 / 19:52