justine0905
justine0905

Reputation: 139

IPN Delivery Failed:500 Internal Server Error (sandbox)

We've been working on a site functionality for a couple of days that uses the PAYPAL IPN. When we test our IPN listener in the developer.paypal IPN simulator, we get an error message "IPN Delivery Failed:500 Internal Server Error". Also in the IPN history in sandbox.paypal account, we get the HTTP response code of 500. However if we change these lines of code from sandbox to paypal, we get HTTP response code of 200(sent).

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

//use www.paypal for a live site
//$header .= "Host: www.paypal.com\r\n"; 
$header .= "Host: www.sandbox.paypal.com\r\n";

$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n";
$header .= "Connection: close\r\n\r\n";
$errstr=$errno='';

$paypalurl='ssl://www.sandbox.paypal.com';
//$paypalurl='ssl://www.paypal.com';

$fp = fsockopen ($paypalurl, 443, $errno, $errstr, 30);

Two months ago, I've worked on a similar IPN listener and it went fine when I was testing in sandbox. I tried to test that IPN listener yesterday and it was also giving me the 500 HTTP response code. I tried to look for errors in the error log but no error about the recent HTTP request is being listed.

Upvotes: 2

Views: 2049

Answers (1)

Tadas Sasnauskas
Tadas Sasnauskas

Reputation: 2313

  1. Use curl library. PayPal no longer recommends this code.
  2. If possible, do this in a background job queue so you can retry in case of a failure. PayPal has its bad days sometimes and it occasionally responds with ISE 500 on perfectly valid requests. The only thing that solved this to us was putting processing of IPN callbacks in background.
  3. Also, sometimes PayPal will respond with 200 OK and some garbage. This is why your code should be ready to handle three cases: response is 'VERIFIED' -> continue, response is 'INVALID' -> log and drop, everything else -> log and put it back to queue to retry later.

Upvotes: 1

Related Questions