Paypal IPN from the sandbox not working

I spent two hours today trying to figure out why paypal wasn’t sending any instant payment notifications (IPN) to one of our new projects. Everything seemed right, I had notify_url in the form, the script could be accessed remotely, I had logging on for http and the script itself. After processing a payment I had 0 requests from the paypal servers hit our development server.

I read around various blogs and discussion forums for obvious problems, of which there are many (see below), but I was sure I had done everything right!

Eventually I stumbled across some posts on the paypal developers forum where a few posters were complaining that the sandbox IPN posts were either really slow (hours) or just never got sent. Worse still, there was one post where paypal acknowledged that payment notifications just did not work on the sandbox for two months!!

I used the IPN test in the sandbox area to test the script in the end. You have to type in the test values manually and you can’t test the entire process in one go but at least it got the job done. Needless to say, the single IPN tests work flawlessly. As one final test I used two live paypal accounts to send small payments to each other. IPN worked without a hitch on the live paypal site.

So, if you are stuggling to get IPN working and your logs show that paypal is not posting to your server, maybe this is your problem too. Before you assume it is however, I read of many other common issues that although blatantly obvious, many people (including myself) have often fallen for:

  1. I don’t know why, but some people were using URLs like http://localhost/ipn.php for the notify_url value. Their argument is that it works for the return url. The return URL works as localhost because paypal posts the value in your own browser, which can resolve localhost to the computer you are on. Paypals own servers obviously can’t!
  2. The ipn processing script was inaccessible (password protected, behind firewalls, etc). Make sure you can access it from outside your local network and that requests from paypal are in your web server logs.
  3. Certain types of escaping for the POST request to paypal can mean that paypal doesn’t understand the URL.
  4. The IPN processing script erroring before it can log any information. Make sure php/http/whatever logging is enabled for this script – logging is a god send for cases like this.

Hopefully you haven’t fallen for any of the above and its just paypal being crappy. In any case, I hope this post saves somebody a bit of time.

This entry was posted in Googled, Peeves, Web dev. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

15 Comments

  1. ma
    Posted April 10, 2009 at 1:16 pm | Permalink

    That’s good to know it isn’t just me.

    I had a streak of good luck in the beginning, because I had no issues at all. IPNs were instantaneous.

    Now, after having put the project on hold for a week or so and then restarting it, I was afraid I broke something in the program. My logging in the listener didn’t even recognize that the listener started, but I could get it to log when I manually visited the listener url. Hopefully, it is just PayPal’s sandbox.

  2. Alex
    Posted August 8, 2009 at 2:57 pm | Permalink

    We also used to have the problem with Paypal sandbox, and they didn’t respond to the requests for about a week. Fortunately, the Paypal integration with AceFlex ebusiness software has been finished later after Paypal’s servers started to operate again. However, don’t be surprised if other Paypal services suddenly stopped working. Even, if you follow their up-to-date documentation sometimes it doesn’t shoot and you need to find other work-arounds.

  3. Posted March 15, 2011 at 4:19 am | Permalink

    It is 2011 now. Has this bug been fixed? I am facing the same problem with the Sandbox. Any idea how to get around it?

  4. Posted March 15, 2011 at 5:32 am | Permalink

    I realized why I was facing the same problem. It was because I didn’t have a ‘Verified’ account in my sandbox.

  5. Laci
    Posted July 6, 2011 at 7:38 am | Permalink

    I have a verified account in sandbox, did received IPNs on the start of the project, but after 3 months simply no IPNs at all. URL is oke, because I’ve can call it from everywhere and it’s logged. I even tried resending IPNs, but nothing…

    Some tips?

  6. Posted August 23, 2011 at 10:41 am | Permalink

    abcdef

  7. Michael
    Posted September 15, 2011 at 2:40 am | Permalink

    Another thing to check when using the IPN simulator is to make sure your listener is on port 80 or 443. The simulator will not connect to URLs listening on non-standard ports. I had to find this out the hard way talking to a PayPal tech this afternoon.

    On a side note, I’m also experiencing the issue of IPN not getting sent when I place an order in the sandbox. The only way to test my code right now is by using the simulator. What a pita.

  8. Posted October 19, 2011 at 11:25 am | Permalink

    I had my code working and receiving messages from IPN on Monday. Today I came back to run more tests, and even though the sandbox reports the messages as having been sent, my logs are showing them as not coming in.

    I did fall for trap #1, but worked that out myself. And I can ‘call’ the IPN code by entering the url into my browser, it fails but then that is expected, but importantly it produces the logs, so I know it is accessible. As for points #3 and #4, I’m not sure. It worked nicely on Monday, and nothing changed in that code between then and now.

    I’ve seen the IPN simulator mentioned a few times, but I don’t know where to find it. PayPal doesn’t seem to mention it in their docs. Can anyone help?

  9. Posted October 22, 2011 at 11:17 pm | Permalink

    Michael is right. Ensure your host runs on port 80 or port 443 before you try anything else. Paypal didn’t send me anything using the IPN simulator when my handler was on ports 8000 or 8080, but it worked fine on ports 80 or 443.

  10. Posted November 14, 2011 at 9:34 am | Permalink

    Sometimes, even the sandbox IPN simulator doesn’t work properly. It was running fine for me yesterday morning, then all of a sudden stopped working. Obviously I assumed that I had broken something in the code, but couldn’t spot anything. Went back to it in the afternoon without making any changes, and hey presto, the IPN files were being received. Frustrating to say the least.

    Currently I’m sat here cursing paypal because it’s not fucking working again.

  11. Tiziano
    Posted November 30, 2011 at 6:46 pm | Permalink

    I’m testing the simulator to a PHP Page (as example here: http://www.mydomain.com/mypage.php) that simply detects what is in the variable $_POST. The scope is to check if the array $_POST is fileld in, and in what manner the variables are sent to my site.

    The routine, write the array into a .TXT file.
    I just accepted the test PayPal Sandbox gives. just clicking on Send IPN.

    Well … the file is written but it’s empty.

    At this point I had put a condition: if ($_POST){ etc etc;) else { mail_to_me }.

    It was emailing me everytime. It means: the POST variable was empty.

    Whats up with me ? :-(

  12. Tiziano
    Posted November 30, 2011 at 8:55 pm | Permalink

    BTW I found this code and I isntalled it.
    What happens is that: testing the IPN from the TEST window of Sandbox, the script works, the only one thing I get always INVALID, but variables are passed through.
    Instead of, when I make a transaction (alwasy in Sandbox) the variables are empty. Nothing is passed through.

    Here please the script

    $value) {
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
    }

    // post back to PayPal system to validate

    $header = "POST /cgi-bin/webscr HTTP/1.0\r\n";

    // If testing on Sandbox use:
    $header .= "Host: http://www.sandbox.paypal.com:443\r\n";
    //$header .= "Host: ipnpb.paypal.com:443\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

    // If testing on Sandbox use:
    $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
    //$fp = fsockopen ('ssl://ipnpb.paypal.com', 443, $errno, $errstr, 30);

    // assign posted variables to local variables
    $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'];

    if (!$fp) {
    // HTTP ERROR
    } else {
    fputs ($fp, $header . $req);
    while (!feof($fp)) {
    $res = fgets ($fp, 1024);
    if (strcmp ($res, "VERIFIED") == 0) {
    // check the payment_status is Completed
    // check that txn_id has not been previously processed
    // check that receiver_email is your Primary PayPal email
    // check that payment_amount/payment_currency are correct
    // process payment

    $mail_From = "From: TEST-IPN PayPal@paypal.com";
    $mail_To = "my_account@mydomain.com";
    $mail_Subject = "VERIFIED IPN";
    $mail_Body = $req;

    foreach ($_POST as $key => $value){
    $emailtext .= $key . " = " .$value ."\n\n";
    }

    mail($mail_To, $mail_Subject, $emailtext . "\n\n" . $mail_Body, $mail_From);

    } else if (strcmp ($res, "INVALID") == 0) {
    // log for manual investigation

    $mail_From = "From: TEST-IPN PayPal@paypal.com";
    $mail_To = "my_account@mydomain.com";
    $mail_Subject = "INVALID IPN";
    $mail_Body = $req;

    foreach ($_POST as $key => $value){
    $emailtext .= $key . " = " .$value ."\n\n";
    }

    mail($mail_To, $mail_Subject, $emailtext . "\n\n" . $mail_Body, $mail_From);

    }
    }
    fclose ($fp);
    }

    ?>

  13. Tiziano
    Posted November 30, 2011 at 9:11 pm | Permalink

    I’m sorry the first part of the code was cut by the system here.
    I report the first completed lines (if they are not cut again!):


    // read the post from PayPal system and add 'cmd'
    $req = 'cmd=_notify-validate';

    foreach ($_POST as $key => $value) {
    $value = urlencode(stripslashes($value));

  14. Tiziano
    Posted December 2, 2011 at 12:59 pm | Permalink

    Well I found the reasons it is not working. But PayPal is not clear at all!!!
    Even in Sandbox can work properly.

    I mean: not only with the test IPN page.
    It’s necessary to go in sandbox then: test Accounts => Enter Sandbox text Site

    a new window appears and, inside it, another login it’s required.
    Click on profile
    Instant Payment Notification Preferences
    Insert your test site with the script and give ok.

    everything works also in sandbox in this manner.

    I employed nights to find solution. it’s not explained properly on their manual neither in internet sites.

  15. vance
    Posted January 11, 2012 at 9:10 pm | Permalink

    thanks Tiziano, i spend weeks with this and was close to give up. Paypal sucks! anyone knows of a better solution with no signup fees?

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

  • Categories

  • Archives