【发布时间】:2012-01-20 07:50:24
【问题描述】:
我知道这个主题有很多问题,我现在用 paypal IPN 玩了将近 3 个小时,但没有成功。这是一个很长的问题,如果有人能读完,我真的很感激。
我正在尝试创建一个简单的在线服务,用户访问我的网站,单击贝宝付款按钮,然后将被带到贝宝进行付款。付款后,他们将被带回到验证他们是否付款的页面。如果付费,则显示在同一(php文件)中的注册页面,如果没有,用户将被重定向回主页。
我按照这里的教程进行操作: http://www.micahcarrick.com/paypal-ipn-with-php.html
我把所有东西都放在同一个目录中,(ipnlistener.php、ipn.php、ipn-errors.log)和一个 index.html,其中存储了 BUY NOW 按钮 代码: p>
<html>
<title>Test IPN</title>
<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="testmailsandbox@domain.com">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="item_name" value="Item">
<input type="hidden" name="amount" value="50">
<input type="hidden" name="return" value="http://mysite.com/ipn/">
<input type="hidden" name="notify_url" value="http://mysite.com/ipn/ipn.php">
<input type="image" src="http://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif"
border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
</html>
我没有触及ipnlistener.php 文件,因为它是ipn.php 使用的类
我的 ipn.php 文件:
/**
* @package PHP-PayPal-IPN
* @author Micah Carrick
* @copyright (c) 2011 - Micah Carrick
* @license http://opensource.org/licenses/gpl-3.0.html
*/
ini_set('log_errors', true);
ini_set('error_log','ipn_errors.log');
// instantiate the IpnListener class
include('ipnlistener.php');
$listener = new IpnListener();
/*
When you are testing your IPN script you should be using a PayPal "Sandbox"
account: https://developer.paypal.com
When you are ready to go live change use_sandbox to false.
*/
$listener->use_sandbox = true;
try {
$listener->requirePostMethod();
$verified = $listener->processIpn();
} catch (Exception $e) {
error_log($e->getMessage());
exit(0);
}
/*
The processIpn() method returned true if the IPN was "VERIFIED" and false if it
was "INVALID".
*/
if ($verified) {
// 1. Make sure the payment status is "Completed"
if ($_POST['payment_status'] != 'Completed') {
// simply ignore any IPN that is not completed
exit(0);
}
// 2. Make sure seller email matches your primary account email.
if ($_POST['receiver_email'] != 'testmailsandbox@domain.com') {
$errmsg .= "'receiver_email' does not match: ";
$errmsg .= $_POST['receiver_email']."\n";
}
// 3. Make sure the amount(s) paid match
if ($_POST['mc_gross'] != '50') {
$errmsg .= "'mc_gross' does not match: ";
$errmsg .= $_POST['mc_gross']."\n";
}
// 4. Make sure the currency code matches
if ($_POST['mc_currency'] != 'USD') {
$errmsg .= "'mc_currency' does not match: ";
$errmsg .= $_POST['mc_currency']."\n";
}
// TODO: Check for duplicate txn_id
if (!empty($errmsg)) {
// manually investigate errors from the fraud checking
$body = "IPN failed fraud checks: \n$errmsg\n\n";
$body .= $listener->getTextReport();
mail('myemail@domain.com', 'IPN Fraud Warning', $body);
} else {
//verified
include 'connect.php';
$sql = "INSERT INTO order VALUES
('$txn_id', '$payer_email', '$mc_gross')";
if (!mysql_query($sql)) {
error_log(mysql_error());
exit(0);
}
}
} else {
/*
An Invalid IPN *may* be caused by a fraudulent transaction attempt. It's
a good idea to have a developer or sys admin manually investigate any
invalid IPN.
*/
mail('myemail@domain.com', 'Invalid IPN', $listener->getTextReport());
}
?>
我已将我的商家 acc IPN 设置为收听“ipn.php”文件。 如您所见,付款是否已验证,我进行数据库查询以将新行插入 ORDER 表。
我转到 index.html 并单击“立即购买”按钮,使用我的买家 ID 付款。
然而,
我在错误日志中不断收到“无效的 HTTP 请求方法”错误。
任何人都可以帮助我发现问题还是我做错了? 谢谢,祝你有美好的一天。
【问题讨论】: