开发者

PayPal IPN "FAIL"

开发者 https://www.devze.com 2022-12-30 14:18 出处:网络
I\'m trying to figure out how to use PayPal\'s IPN and I\'v开发者_如何学Goe 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

I'm trying to figure out how to use PayPal's IPN and I'v开发者_如何学Goe 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);
}


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消