我在 Paypal 沙盒上创建了买家和卖家测试帐户。我还创建了一个 Paypal 按钮。
支付宝按钮:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="6M75NVDV8ZHR8">
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
我已经启用了 IPN 并在那里设置了通知 URL。
在创建 Paypal 按钮时,我插入我的站点 URL 以实现成功交易。
成功的交易和 IPN 通知共享同一个 URL。
这是引用 URL 的 PHP 脚本:
<?php
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
print_r($_POST);
foreach ($_POST as $key => $value) {
echo "loop";
echo $value = urlencode(stripslashes($value));
echo $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('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
echo " PAYMENT VALIDATED & VERIFIED! ";
}
else if (strcmp ($res, "INVALID") == 0) {
echo " PAYMENT INVALID & INVESTIGATE MANUALY! ";
}
}
fclose ($fp);
}
?>
该print_r
函数仅打印Array()
,在 foreach 循环中不显示任何内容。
只有在PAYMENT INVALID & INVESTIGATE MANUALLY!
页面上显示。
这里有什么问题?
因为我想在成功的交易中插入一些数据。
更新
这是我的帖子数组:
Array
(
)
DoDirectPayment failed: Array
(
[TIMESTAMP] => 2012%2d05%2d03T12%3a54%3a08Z
[CORRELATIONID] => 51176eef6a5
[ACK] => Failure
[VERSION] => 51%2e0
[BUILD] => 2860716
[L_ERRORCODE0] => 10527
[L_ERRORCODE1] => 10563
[L_ERRORCODE2] => 10562
[L_ERRORCODE3] => 81234
[L_SHORTMESSAGE0] => Invalid%20Data
[L_SHORTMESSAGE1] => Invalid%20Data
[L_SHORTMESSAGE2] => Invalid%20Data
[L_SHORTMESSAGE3] => Invalid%20Parameter
[L_LONGMESSAGE0] => This%20transaction%20cannot%20be%20processed%2e%20Please%20enter%20a%20valid%20credit%20card%20number%20and%20type%2e
[L_LONGMESSAGE1] => This%20transaction%20cannot%20be%20processed%2e%20Please%20enter%20a%20valid%20credit%20card%20expiration%20month%2e
[L_LONGMESSAGE2] => This%20transaction%20cannot%20be%20processed%2e%20Please%20enter%20a%20valid%20credit%20card%20expiration%20year%2e
[L_LONGMESSAGE3] => ExpDate%20%3a%20Invalid%20Parameter
[L_SEVERITYCODE0] => Error
[L_SEVERITYCODE1] => Error
[L_SEVERITYCODE2] => Error
[L_SEVERITYCODE3] => Error
)
我更改了 ipn.php 代码,现在我收到此错误:“无效的信用卡号”。
我已经使用预配置创建了买家帐户,它会随机生成信用卡号。
现在当我去添加/编辑信用卡时,我不能只编辑卡号地址和到期日。
并且也无法添加新信用卡,而是将此信用卡的错误分配给另一个 Paypal 帐户消息。