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"]
<?php
/* This code created by Andrew Wells (www.pr0gr4mm3r.com) */
/* Your comments or questions are welcome: contact@pr0gr4mm3r.com */
include("includes/Snoopy.php");
/* 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);
if ($result)
{
$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 */
}
}
else
{
/* connection failed */
}
?>[/sourcecode]
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.
lizanne October 1st, 2011 at 7:27 pm
Many thanks- this saved me, as I have a site on godaddy.