1
votes

I set up paypal IPN in the sandbox. I use this sctipt https://github.com/paypal/ipn-code-samples/blob/master/paypal_ipn.php

But always I get INVALID responce.

I used this tips https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNTesting/#invalid

but still an invalid response what am I doing wrong?

[2016-03-22 16:53 Europe/Moscow] HTTP request of validation request:POST /cgi-bin/webscr HTTP/1.1 Host: www.sandbox.paypal.com Accept: / Connection: Close Content-Length: 970 Content-Type: application/x-www-form-urlencoded

for IPN payload: cmd=_notify-validate&payment_type=instant&payment_date=Tue+Mar+22+2016+16%3A47%3A09+GMT%2B0300+%28RTZ+2+%28%C3%90%C2%B7%C3%90%C2%B8%C3%90%C2%BC%C3%90%C2%B0%29%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=901876583&notify_version=2.1&custom=xyz123&invoice=abc1234&test_ipn=1&verify_sign=A2AotZPiNfH-.cRF2fDADaP45z4xAMRyJ2i2LYn0-bIrKScsGQzjL1bU [2016-03-22 16:53 Europe/Moscow] HTTP response of validation request: HTTP/1.1 200 OK Date: Tue, 22 Mar 2016 13:53:57 GMT Server: Apache X-Frame-Options: SAMEORIGIN Set-Cookie: c9MWDuvPtT9GIMyPc3jwol1VSlO=8YEulQPoVmljEzDjxqb2Eja5QkTvSSIHAnS6YQAcTx1q_LuQEbsn-_3B66X5sfKSbDLoRnK3Ry41yaTByrW98ADgx2oXvvGL_3Ip0w4UjbUAoWMw4czFk1LULFI1VqQqjvwTuLSm21iNcQvYl8U4h0oOhwZ8CJVVpogcyR3HjUweHmCjUhDzqGKS6jFMsbkUu9wyC85KmvldFXiXjFvokwlUTUmnH3e4Vt26dgA0jnaRK_vKMNX-aYV9uicgZf2DBUvz0f3kP329HR1IWGErDb8Wgtpf6jQMho8B0noW_vYfA6IPQpBAG927oZVlU3iSxa6zj53u-NGEr11Z1qE2wLmqO9vWbgOsbGcJG2F3au0FGuLQdy-7mdQpFEriGbBF9FknFI_5YTzKo4uFQudUT9Sr4i-LSapRj_4758BPSTEiJ2oHpY-6m1lWuOi; domain=.paypal.com; path=/; Secure; HttpOnly Set-Cookie: cookie_check=yes; expires=Fri, 20-Mar-2026 13:53:58 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, 22-Mar-2018 13:53:58 GMT; domain=.paypal.com; path=/; Secure; HttpOnly Set-Cookie: Apache=10.72.108.11.1458654837796174; path=/; expires=Thu, 15-Mar-46 13:53:57 GMT Vary: Accept-Encoding,User-Agent Connection: close HTTP_X_PP_AZ_LOCATOR: sandbox.slc Paypal-Debug-Id: 8023af87be966 Set-Cookie: X-PP-SILOVER=name%3DSANDBOX3.WEB.1%26silo_version%3D1880%26app%3Dappdispatcher%26TIME%3D1968107862; domain=.paypal.com; path=/; Secure; HttpOnly Set-Cookie: X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT Strict-Transport-Security: max-age=14400 Transfer-Encoding: chunked Content-Type: text/html; charset=UTF-8

INVALID [2016-03-22 16:53 Europe/Moscow] Invalid IPN: cmd=_notify-validate&payment_type=instant&payment_date=Tue+Mar+22+2016+16%3A47%3A09+GMT%2B0300+%28RTZ+2+%28%C3%90%C2%B7%C3%90%C2%B8%C3%90%C2%BC%C3%90%C2%B0%29%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=901876583&notify_version=2.1&custom=xyz123&invoice=abc1234&test_ipn=1&verify_sign=A2AotZPiNfH-.cRF2fDADaP45z4xAMRyJ2i2LYn0-bIrKScsGQzjL1bU Paypal response:

3

3 Answers

1
votes

try using two fake accounts from sandbox.paypal (1 personal, 1 business) in order to check the VERIFIED / INVALID RESPONSES instead of the IPN Simulator.

you can get those at https://developer.paypal.com/developer/accounts/ and give them fake credits to play with.

I never got a VERIFIED from the IPN Simulator but always get one while testing through the sandbox.

0
votes

In your IPN PHP Script, try changing all urlencode to rawurlencode and urldecode to rawurldecode.

0
votes

I finally found an updated (August 5, 2016) working answer to this query. You can use this code as your final IPN for Sandbox or Live. With the following consideration:

  1. Be sure to place your IPN listener to ->My selling tools -> instant payment notifications Section.
  2. Do not use IPN Simulator in sandbox, it will always return INVALID.
  3. Create and Use an actual Sandbox Button, but DO NOT put your IPN listener to RETURN PAGE that says "Take customers to this URL when they finish checkout".

That's all of it. I hope this will help.

And here is the working code:

<?php
$post_data = file_get_contents('php://input');
$post_array = explode('&', $post_data);
$dataFromPayPal = array();
foreach ($post_array as $keyval) {
    $keyval = explode ('=', $keyval);
    if (count($keyval) == 2)
        $dataFromPayPal[$keyval[0]] = urldecode($keyval[1]);
}

$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
    $get_magic_quotes_exists = true;
}
foreach ($dataFromPayPal 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";
}

$ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');
//use https://www.paypal.com/cgi-bin/webscr in live environment.
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_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));

if( !($res = curl_exec($ch)) ) {
    curl_close($ch);
    exit;
}
curl_close($ch);



if (strcmp ($res, "INVALID") == 0) {
        echo "INVALID";
}
else if (strcmp ($res, "VERIFIED") == 0) {
        echo "VALID";
}

?>