paypal / ipn-code-samples

Other
562 stars 486 forks source link

Ipn invalid paypal #132

Closed KeteTheme closed 6 years ago

KeteTheme commented 6 years ago

problem with ipn invalid paypal, LOG:

[2018-05-08 23:14 UTC] HTTP respuesta a la validacion: HTTP/1.1 200 OK Date: Tue, 08 May 2018 23:14:21 GMT Server: Apache X-Frame-Options: SAMEORIGIN Set-Cookie: c9MWDuvPtT9GIMyPc3jwol1VSlO=ZuPnj4Ta_AbXSXWHufdVBYEtDGRp1Udz8VhvHGmvKAWbzHQIFg1HeYzeU4ZErWCT3xaGxsGNGk7UQKiMI1bSWpAS7GDdpWQOAaU80aznCuTAsUAHMn6Dh83NSe0v9Gsmzh7ESKl5CTCvXs5dKLAuSeG35k9A3DlBgxofpBD-WI4oGS1kV85W4I9amRFzPsUE79sIW6LyOKiKzxqN0ofW6pM8iRf5HtWDqkDo79bcTo3FWVCMNZdNpbOlJuvd68eHoB-eVTblwwdCI1c9uIxN_FeFiFJCgn5nDYdsuiT2zzBVkIb2707Whr_FFLu6WY7JlYPGFcgOaWXhEDgwyHjOcCNYgJb1t2NvXtxAZf9a_uSH0P3IHkTplkfK3NDsQLJ4cfwP_3QZINnIPtgjWtSEm3VWBmVX4b_eZguxLEx9xPx-Wvk7TgItkxD34; domain=.paypal.com; path=/; Secure; HttpOnly Set-Cookie: cookie_check=yes; expires=Fri, 05-May-2028 23:14:21 GMT; domain=.paypal.com; path=/; Secure; HttpOnly Set-Cookie: navcmd=_notify-validate; domain=.paypal.com; path=/; Secure; HttpOnly Set-Cookie: navlns=0.0; expires=Thu, 07-May-2020 23:14:21 GMT; domain=.paypal.com; path=/; Secure; HttpOnly Set-Cookie: Apache=10.72.108.11.1525821261529137; path=/; expires=Thu, 30-Apr-48 23:14:21 GMT Vary: Accept-Encoding,User-Agent Connection: close HTTP_X_PP_AZ_LOCATOR: sandbox.slc Paypal-Debug-Id: b71d05a27e019 Set-Cookie: X-PP-SILOVER=name%3DSANDBOX3.WEB.1%26silo_version%3D1880%26app%3Dappdispatcher%26TIME%3D1294987866%26HTTP_X_PP_AZ_LOCATOR%3Dsandbox.slc; Expires=Tue, 08 May 2018 23:44:21 GMT; domain=.paypal.com; path=/; Secure; HttpOnly Set-Cookie: X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT Transfer-Encoding: chunked Content-Type: text/html; charset=UTF-8 Strict-Transport-Security: max-age=63072000 INVALID [2018-05-08 23:14 UTC] IPN Invalido: cmd=_notify-validate&payment_type=instant&payment_date=Tue+May+08+2018+19%3A05%3A22+GMT-0400+%28Hora+est%E1ndar+oeste%2C+Sudam%E9rica%29&payment_status=Completed&address_status=confirmed&payer_status=verified&first_name=John&last_name=Smith&payer_email=buyer%40paypalsandbox.com&payer_id=TESTBUYERID01&address_name=John+Smith&address_country=United+States&address_country_code=US&address_zip=95131&address_state=CA&address_city=San+Jose&address_street=123+any+street&business=seller%40paypalsandbox.com&receiver_email=seller%40paypalsandbox.com&receiver_id=seller%40paypalsandbox.com&residence_country=US&item_name1=something&item_number1=AK-1234&tax=2.02&mc_currency=USD&mc_fee=0.44&mc_gross=12.34&mc_gross_1=12.34&mc_handling=2.06&mc_handling1=1.67&mc_shipping=3.02&mc_shipping1=1.02&txn_type=cart&txn_id=129468388&notify_version=2.1&custom=xyz123&invoice=abc1234&test_ipn=1&verify_sign=AYaolBZqBp3tKLKYhTxO5cxsAS4TAnllN8FNyHHAx1d2KMneB5Pd5woR

help me I have searched many parts and I have changed codes and nothing works for me, I have the problem on the date as you can see. Use sandbox, Thanks and regards. If you need more information, just tell me.

overint commented 6 years ago

I don't completely understand, are you having issues with this specific call or all of them?

Can you send the raw post from paypal, as well as your reply.

I assume you are using the PHP sample?

KeteTheme commented 6 years ago

Hello, thanks for answering. I have the problem with paypal ipn where I use IPN-SIMULATOR. Ok in that. Now when I use it, it gives me that log, I use this PHP code:

<?php
//Permite crear un archivo LOG cada vez que se ejecuta este script, 0 para desactivarlo
define("DEBUG", 1);
// 1 para usarlo con el simulador de paypal (https://developer.paypal.com/developer/ipnSimulator/), 0 para usarlo con pagos reales
define("USE_SANDBOX", 1);
// este es el archivo LOG no importa si no existe este lo crea automaticamente
define("LOG_FILE", "resultadopaypal.txt");

// permite verificar si los datos son recibidos desde paypal y no otra pagina diferente
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();

        foreach ($raw_post_array as $keyval) {
            $keyval = explode('=', $keyval);
            if (count($keyval) == 2) {
                // Since we do not want the plus in the datetime string to be encoded to a space, we manually encode it.
                if ($keyval[0] === 'payment_date') {
                    if (substr_count($keyval[1], '+') === 1) {
                        $keyval[1] = str_replace('+', '%2B', $keyval[1]);
                    }
                }
                $myPost[$keyval[0]] = urldecode($keyval[1]);
            }
        }

        $req = 'cmd=_notify-validate';
        $get_magic_quotes_exists = false;
        if (function_exists('get_magic_quotes_gpc')) {
            $get_magic_quotes_exists = true;
        }
        foreach ($myPost as $key => $value) {
            if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
                $value = urlencode(stripslashes($value));
            } else {
                $value = urlencode($value);
            }
            $req .= "&$key=$value";
        }

if(USE_SANDBOX == true) {
    $paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
} else {
    $paypal_url = "https://www.paypal.com/cgi-bin/webscr";
}

$ch = curl_init($paypal_url);

if ($ch == FALSE) {
    return FALSE;
}

curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);

if(DEBUG == true) {
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
}

//si depronto se usa proxy eliminar los //
//curl_setopt($ch, CURLOPT_PROXY, $proxy);
//curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);

//se coloca el tiempo maximo que se demora este script
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));

$res = curl_exec($ch);

if (curl_errno($ch) != 0) // cURL error
    {
    if(DEBUG == true) { 
        error_log(date('[Y-m-d H:i e] '). "No se puede conectar a PayPal para validar el IPN: " . curl_error($ch) . PHP_EOL, 3, LOG_FILE);
    }
    curl_close($ch);
    exit;
} else {
        // Log son las respuestas de error que se escribiran en el LOG
        if(DEBUG == true) {
            error_log(date('[Y-m-d H:i e] '). "HTTP respuesta:". curl_getinfo($ch, CURLINFO_HEADER_OUT) ." para IPN: $req" . PHP_EOL, 3, LOG_FILE);
            error_log(date('[Y-m-d H:i e] '). "HTTP respuesta a la validacion: $res" . PHP_EOL, 3, LOG_FILE);
        }
        curl_close($ch);
}

$tokens = explode("\r\n\r\n", trim($res));
$res = trim(end($tokens));

if (strcmp ($res, "VERIFIED") == 0) {

    //aqui se colocan las instrucciones php si el pago fue hecho es decir COMPLETED
    //estas son las variables recibidas desde paypal que se pueden usar

    //$item_name = $_POST['item_name'];
    //$item_number = $_POST['item_number'];
    //$payment_status = $_POST['payment_status'];
    //$payment_amount = $_POST['mc_gross'];
    //$payment_currency = $_POST['mc_currency'];
    //$txn_id = $_POST['txn_id'];
    //$receiver_email = $_POST['receiver_email'];
    //$payer_email = $_POST['payer_email'];

    //Crea un archivo TXT cada vez que se recibe un pago desde paypal
    //con todos los datos que nos envia
    $txt = fopen("paypalpagos.txt", "a+");

    ob_start();
    var_dump($_POST);
    $result = ob_get_clean();

    fputs($txt, $result);
    @fclose($fp);
    //fin

    // crea el LOG
    if(DEBUG == true) {
        error_log(date('[Y-m-d H:i e] '). "IPN Verificado: $req ". PHP_EOL, 3, LOG_FILE);
    }
} else if (strcmp ($res, "INVALID") == 0) {
    if(DEBUG == true) {
        error_log(date('[Y-m-d H:i e] '). "IPN Invalido: $req" . PHP_EOL, 3, LOG_FILE);
    }
}
?>

Now if I using ipn simulator I delete the option of the date everything works fine. What can I do in this case? What do you recommend?

PD: sorry for my bad English, I'm more of Spanish. Greetings and thanks

overint commented 6 years ago

Can you please use the IPN sample provided in this repository and let us know if it works?

https://github.com/paypal/ipn-code-samples/tree/master/php

spivack1212-zz commented 6 years ago

The IPN Simulator always returns INVALID for verification requests. I was able to take my code that is getting INVALID in IPN simulator, and it works fine in production.

ghost commented 6 years ago

I have the same issue. I used the latest code example from github, and it always returns INVALID. I am trying already since 3 days to find a solution, and cant figure out whats wrong. I did not change the github example, except adding my email address. I get also an email, with INVALID.