Reputation: 9
I am uable to get the VERIFIED answer from paypal using the IPN I'm receiving the POST data from PayPal via the notify_url. I then send it back to PayPal with cmd=_notify-validate infront of the data.
Using PayPals documented code, I'm using this to send the message to PayPal
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n"; // HTTP POST request
$header.= "Content-Type: application/x-www-form-urlencoded\r\n";
$header.= "Host: www.sandbox.paypal.com\r\n";
$header.= "Content-Length: " . strlen($req) . "\r\n";
$header.= "Connection: Close\r\n\r\n";
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
Then I use this
if (!$fp) {
// HTTP ERROR;
} else {
var_dump(fputs($fp, $header . $req));
while (!feof($fp)) {
$res = stream_get_contents($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
//Transaction verified
}
}
}
In fact I have two $res (due to the while loop). The first does not seems to be of interest and the second is
55 GMT
Connection: close
Set-Cookie: X-PP-SILOVER=name%3DSANDBOX3.WEB.1%26silo_version%3D880%26app%3Dslingshot%26TIME%3D1273590100; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT
Set-Cookie: Apache=10.72.128.11.1416751435364358; path=/; expires=Tue, 15-Nov-44 14:03:55 GMT
Vary: Accept-Encoding
Strict-Transport-Security: max-age=14400
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
8
VERIFIED
0
It seems that the first part is a header and the second part (8 VERIFIED 0) is the real response but why do I have this 0 and 8 ? Usually people use
if (strcmp ($res, "VERIFIED") == 0) {
To check that the $res is VERIFIED... So can I consider that the response is 'VERIFIED', using something like
if(strstr($res,'VERIFIED')) {
Some help please ?!?
Thanks
Upvotes: 1
Views: 106
Reputation: 198
I had the exact same issue, and was able to solve it the same way. If I use the sample code from PayPal I get no response at all.
But I have come across something that works using cURL here: https://github.com/paypal/ipn-code-samples/blob/master/paypal_ipn.php.
I needed to install cURL using these instructions: curl_init() function not working
And also download and use the cacert.pem found in the script comments.
I am still not certain why stream_get_contents() is returning the headers. If you have figured it out, can you update this?
Upvotes: 1
Reputation: 2178
I have the same issue than you. And I use strstr($res,'VERIFIED') to check if notification is verified.
Upvotes: 0