所以我目前正在尝试创建一个小型网店并使用paypal IPN + Sandbox。目前我的Paypal IPN脚本似乎不起作用。付款通过(Money转移)但是,我的paypal_ipn脚本中没有任何内容(记录到文本文件并向数据库添加一行)。
这是我目前的paypal ipn文件:
<?php
include("../functions.php");
include("../config.php");
// PHP 4.1
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
$header = "";
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 ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
$address = $_POST['custom_ip'];
if (!$fp) {
// HTTP ERROR
log("[HTTP_ERROR]" . PHP_EOL . var_dump($_POST) . PHP_EOL . "[/HTTP_ERROR]", "payment/success.txt");
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
log("[PAYMENT]" . PHP_EOL . var_dump($_POST) . PHP_EOL . "[/PAYMENT]", "payment/success.txt");
mysql_query("INSERT INTO `purchases` (*) VALUES('$item_name', '$item_number', '$payment_amount', '$address', '$payer_email')");
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
log("[FAILED PAYMENT]" . PHP_EOL . var_dump($_POST) . PHP_EOL . "[/FAILED PAYMENT]", "payment/errors.txt");
}
}
fclose ($fp);
}
?>
这是我的表格:
<form name="_xclick" action="https://www.sandbox.paypal.com/cgi-bin/webscr"
method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="duncan-facilitator@mymcstatus.net">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="item_name" value="<?php print($product['title']); ?>">
<input type="hidden" name="amount" value="<?php print($product['price']); ?>">
<input type="hidden" name="return" value="http://website.com/shop/payment/?success">
<input type="hidden" name="notify_url" value="http://website.com/shop/payment/paypal_ipn.php">
<input type="hidden" name="custom_ip" value="<?php print($_SERVER['REMOTE_ADDR']); ?>"/>
<input type="image" src="https://www.paypalobjects.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.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
我没有看到任何错误,但我是新手,所以任何事情都可能......
感谢您的帮助。
答案 0 :(得分:0)
原来是因为我的代码中有错误:
我声明的函数'log'是一个已经使用过的系统函数,所以我解析的参数导致错误。我改变了我的功能名称,一切正常:)