PayPal IPN and GoDaddy Hosting
This took over 4 hours of debugging for me to figure out. Hopefully, this will save you time. Basically, the problem I was having was that I wasn’t getting the responses necessary from PayPal when I sent the requests from GoDaddy servers. This script made it much easier to get the job done.
[sourcecode language="php" collapse="true"]
/* This code created by Andrew Wells (www.pr0gr4mm3r.com) */
/* Your comments or questions are welcome: email@example.com */
/* first, reform the variables to post them back */
$post_vars['cmd'] = ‘_notify-validate’;
$post_vars['ipn_test'] = 1;
foreach ($_POST as $key => $value)
$post_vars[$key] = $value;
/* now send the data back */
$snoopy = new Snoopy;
$submit_url = ‘http://www.sandbox.paypal.com/cgi-bin/webscr’;
/* uncomment these lines if you use GoDaddy.com as your host */
/* $snoopy->proxy_host = "proxy.shr.secureserver.net";
$snoopy->proxy_port = "3128"; */
$result = $snoopy->submit($submit_url, $post_vars);
$headers = implode("\n", $snoopy->headers);
$content = $snoopy->results;
if (strpos(‘VERIFIED’, $content) !== FALSE)
/* information checks out, but be sure to verify payment information and amount */
else if (strpos(‘INVALID’, $content) !== FALSE)
/* information is invalid; possible spoofing */
/* connection failed */
The above code is what I now use to test and post-back my PayPal Instant Payment Notifications. It does make use of the Snoopy script, so be sure to download yourself a copy here if you don’t have it. This is much better than PayPal’s sample because 1) it works, and 2) it is neater code because it uses the Snoopy class.
Points to address:
- This script is meant to post to the PayPal Sandbox. When implementing this script for real, comment out line 9, and take out ‘sandbox.’ on line 18.
- Uncomment lines 21-22 if your host if GoDaddy.
- Line 34 is where you put the code for a successful verification*.
- Line 39 is where you put the code for an unsuccessful verification (possible spoofing).
- Line 44 is where you put the code to handle a connection failure.
*A successful validation does not mean all the information is correct, especially if you aren’t using encrypted PayPal buttons. You still want to verify all payment information.
This entry was posted on Wednesday, December 20th, 2006 at 7:37 pm and is filed under PHP. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.