【发布时间】:2011-12-18 05:04:48
【问题描述】:
我正在为自定义数字电子商务创建 IPN,但我遇到了一个问题: 一切正常的文件,我在我的数据库中创建了一个“待付款”,其 ID 称为 PID(付款 ID),用户转到贝宝页面,付款完成后贝宝在 IPN 侦听器上与我联系,检查是否支付完成并启用用户购买的所有媒体。
我使用 micah carrick php 类成功创建了一个 IPN (http://www.micahcarrick.com/php-paypal-ipn-integration-class.html) 一切正常,除了 我总是得到 pendign 付款状态,我无法得到确认。
我目前正在贝宝沙箱中测试它,我创建了 2 个买家和一个卖家,并且我已经为每个人启用了“付款审查”。
我也尝试了不同的方法,但我总是得到相同的结果。
代码: file_put_contents('ipn.log',"\n>IPN\n",FILE_APPEND);
//Check the Payment ID,i pass it to the IPN by GET
if(!isset($_GET['pid'])|| !is_numeric($_GET['pid'])){
file_put_contents('ipn.log',"\n!!!IPN:INVALID PID(".$_GET['pid'].")!!!\n",FILE_APPEND);
exit('PID INVALIDO!');
}
//Logging errors
ini_set('log_errors', true);
ini_set('error_log', dirname(__FILE__).'/ipn_errors.log');
// instantiate the IpnListener class
require('ipnlistener.php');
$listener = new IpnListener();
//Use the sandbox instead of going "live"
$listener->use_sandbox = true;
//validate the request
try {
$listener->requirePostMethod();
$verified = $listener->processIpn();
}
catch (Exception $e) {
error_log($e->getMessage());
exit(0);
}
//Just for debug
file_put_contents('ipn.log',"\n###IPN:verifying...###\n",FILE_APPEND);
if($verified){//the payment is verified
file_put_contents('ipn.log',"\n###IPN:transaction verified(confirmed=".$_POST['payment_status'].")###\n".$listener->getTextReport(),FILE_APPEND);
/*
Once you have a verified IPN you need to do a few more checks on the POST
fields--typically against data you stored in your database during when the
end user made a purchase (such as in the "success" page on a web payments
standard button). The fields PayPal recommends checking are:
1. Check the $_POST['payment_status'] is "Completed"
2. Check that $_POST['txn_id'] has not been previously processed
3. Check that $_POST['receiver_email'] is your Primary PayPal email
4. Check that $_POST['payment_amount'] and $_POST['payment_currency']
are correct
Since implementations on this varies, I will leave these checks out of this
example and just send an email using the getTextReport() method to get all
of the details about the IPN.
*/
if($_POST['payment_status']=="Completed"){
//--check if the price is right and enable the user media--
confirm_payment($_GET['pid'],$_POST['payment_amount']);
file_put_contents('ipn.log',"\n###IPN:Transaction completed###\n".$listener->getTextReport(),FILE_APPEND);
}
}
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.
*/
file_put_contents('ipn.log',"\n###IPN:ERROR###\n".$listener->getTextReport(),FILE_APPEND);
}
我创建的调试日志总是这样
> IPN ##IPN:verifying...### ##IPN:transaction encrypted(confirmed=Pending)
【问题讨论】:
标签: php paypal paypal-ipn paypal-sandbox