【发布时间】:2013-01-28 17:33:14
【问题描述】:
我正在为慈善棋盘游戏活动设计一个网站,人们可以在其中观看活动现场直播,并且可以向慈善机构(儿童游戏)捐款,以迫使玩家连续玩 60 小时。因为捐款会直接送到 Child's Play,所以我需要使用 notify_url 设置来传递我的 IPN 通知 URL;我们之前已经完成了两次马拉松比赛并且没有遇到任何问题,但我们最近将其移植到了 PHP。
现在,在过去的几个月里,我一直在使用沙盒对网站进行广泛的测试,一切都运行良好。现在距离马拉松只有几个星期了,所以我切换到实际的 PayPal 系统,启动了测试捐赠,现在我遇到了一个问题:由于某种原因,PayPal 根本没有点击 notify_url。我通过暂时切换回沙盒验证了 URL,一切正常。我还在侦听器代码中添加了一些对 error_log 的调用,以查看它是否只是在某处的代码中被捕获,但发现它根本没有被命中。
如果有人可以在这里就我能做什么提供任何建议,我将不胜感激。显然我的时间有点紧,所以如果你能尽快回复,我将不胜感激。
编辑:以下是相关代码:
if (isset($_GET['paypalipn'])) {
// tell PHP to log errors to ipn_errors.log in this directory
ini_set('log_errors', true);
ini_set('error_log', dirname(__FILE__).'/ipn_errors.log');
// intantiate the IPN listener
$listener = new IpnListener();
// tell the IPN listener to use the PayPal test sandbox
$listener->use_sandbox = false;
error_log("here");
// try to process the IPN POST
try {
$listener->requirePostMethod();
$verified = $listener->processIpn();
} catch (Exception $e) {
error_log($e->getMessage());
exit(0);
}
error_log("here2");
// Process the IPN
if ($verified) {
error_log("here3");
$errmsg = ''; // stores errors from fraud checks
// Split the custom variable
$split_custom = explode("&", $_POST['custom']);
$custom_array = array();
for ($i = 0; $i<count($split_custom); $i++) {
$current_set = explode("=", $split_custom[$i]);
$custom_array[$current_set[0]] = $current_set[1];
}
error_log("here4");
if (!isset($custom_array['game'])) {
$custom_array['game'] = 0;
}
if (!isset($custom_array['player'])) {
$custom_array['player'] = 0;
}
error_log("here5");
if (!empty($errmsg)) {
// manually investigate errors from the fraud checking
$body = "IPN failed fraud checks: \n$errmsg\n\n";
$body .= $listener->getTextReport();
mail('jafawcett@gmail.com', 'IPN Fraud Warning', $body);
} else {
mail('jafawcett@gmail.com', 'Successful IPN', $listener->getTextReport());
}
error_log("donor_un: ".$custom_array['donor_un']);
process_donation($_POST['mc_gross'], $custom_array['player'], $custom_array['game'], $custom_array['donor_name'], $_POST['payer_email'], $custom_array['donor_un']);
} else {
// manually investigate the invalid IPN
mail('jafawcett@gmail.com', 'Invalid IPN', $listener->getTextReport());
}
}
对于 ipn 侦听器类,我使用的是 Micah Carrick 创建的,可在此处获得: https://github.com/Quixotix/PHP-PayPal-IPN
【问题讨论】:
-
发布你目前拥有的代码。
-
抱歉,按了提交有点快:/
标签: php paypal paypal-ipn paypal-sandbox