tags:

views:

96

answers:

2

Hey all...

I'm trying to figure out how to use PayPal's IPN and I've run into a wall.

I want a buyer to be forwarded to a success page after making a purchase, and I want that page to show the details of their transaction. I choose IPN instead of the PDT because I also want to do some other behind the scenes stuff with their data.

Anyway, here's the code I'm using -- I'm testing in sandbox mode -- but it returns "FAIL" every time.

$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.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

$fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {

// PAYMENT VALIDATED & VERIFIED!

echo "Validated!";

}

else if (strcmp ($res, "INVALID") == 0) {

// PAYMENT INVALID & INVESTIGATE MANUALY!

echo "Invalid!";

}
}
fclose ($fp);
}
A: 

i got the same problem in the test enviroment because my item_name has especial character, then i change item_name to only english word and number. it works fine.

but in real enviroment i still find this problem,i read the https://www.x.com/docs/DOC-1551, but i still don't know why

beimuaihui
Thanks for the tip. My item_name is all english letters though, so I don't think this is causing the problem.
Rob
A: 

I didn't realize that the sandbox account I set up was Unverified. I re-made the pre-configured sandbox account and then it started to work perfectly.

Rob