I’m just testing the Paypal IPN here. I’ve got it set up with Sandbox. I’m sending it fake IPN requests, and it’s receiving the IPN. Then, I’m getting it to return the information for verification, and I’m writing the response to a text file so I can check it out on my own. The IPN is firing fine, and the response is getting written to the text file.
There’s just one problem… The response is blank.
The response is supposed to be received as “VERIFIED” or “INVALID”, and these are the only 2 possible responses… so what’s going on =S. Any help is greatly appreciated.
The entire code is posted below:
$ipn_post_data = $_POST;
$response = "";
// Choose url
$url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
// Set up request to PayPal
$request = curl_init();
curl_setopt_array($request, array
(
CURLOPT_URL => $url,
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => http_build_query(array('cmd' => '_notify-validate') + $ipn_post_data),
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HEADER => FALSE,
CURLOPT_SSL_VERIFYPEER => TRUE,
CURLOPT_CAINFO => 'cacert.pem',
));
// Execute request and get response and status code
$response = curl_exec($request);
$status = curl_getinfo($request, CURLINFO_HTTP_CODE);
// Close connection
curl_close($request);
$fh = fopen( "ipntest.txt", 'a+' );
$date = date( "Y-M-j H:i" );
fwrite( $fh, $date . " Response: " . $response . "\n" );
fclose( $fh );
if($status == 200 && $response == 'VERIFIED')
{
// All good! Proceed...
}
else
{
// Not good. Ignore, or log for investigation...
}
Text file output:
2012-Nov-26 23:24 Response:
2012-Nov-26 23:25 Response:
I had been using this code previously, I’ve been trying to get it to work for a week, so it’s not just a temporary failure or something…
Cheers guys.
So just for future reference, for people with this same problem:
The issue here was not having a CA file.
I’m unsure what exactly a CA file does but I know it has something to do with Paypal’s SSL certificate and establishing an SSL connection. When I started looking at cURL’s errors, I saw the following:
The quick solution that I found was to download the IpnListener.php class. (This was recommended by eldblz. It made dealing with IPN way easier AND it provided a solution to my not having a CAFile. If you download the entire IpnListener.php package, it includes a folder called cert which includes the api_cert_chain.crt that you need, and already has it configured for use.