|
-
Mar 16th, 2013, 04:03 PM
#1
Thread Starter
Hyperactive Member
Paypal IPN
Hi,
I am trying to setup paypal's IPN system, but using the ipn simulator i am unable to get any 'VERIFIED' responses.
Here is the code i am using:
PHP Code:
<?php
//read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
//post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.paypal.com\r\n";
$header .= "Connection: close\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
//
//error connecting to paypal
if (!$fp) {
//
}
//successful connection
if ($fp) {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
$res = trim($res); //NEW & IMPORTANT
if (strcmp($res, "VERIFIED") == 0) {
//insert order into database
//SEND EMAIL
$to = "[email protected]";
$subject = "Good IPN";
$message = " this is working ipn" . $payment_status . $item_name;
$from = "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
}
if (strcmp ($res, "INVALID") == 0) {
//insert into DB in a table for bad payments for you to process later
//SEND EMAIL
$to = "[email protected]";
$subject = "Bad IPN";
$message = "this is not working ipn";
$from = "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
}
}
fclose($fp);
}
?>
Thanks, Chris.
If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.
If you fail, try and try again, its the only way to success.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|