Paypal IPN 通知未发送
Posted
技术标签:
【中文标题】Paypal IPN 通知未发送【英文标题】:Paypal IPN notification not being sent 【发布时间】:2016-06-10 09:15:30 【问题描述】:目前我没有 ssl 证书。我刚刚订购了它,我现在需要设置一个新的 Web 服务器,而我正在构建这个应用程序,我正在使用我现有的服务器和一个插件域。完成后,我将安装新的专用服务器和 SSL 证书。
我正在使用以下按钮:
<form target="paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="amount" value="25">
<input type="hidden" name="item_number" value="1111">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="custom" value="123456">
<input type="hidden" name="business" value="[my-business-paypal-email]">
<input type="hidden" name="notify_url" value="http://www.[mywebsiteURL].com/gdpripnh-exec.php">
<input type="hidden" name="return" value="http://www.[mywebsiteURL].com/upgrade.php">
<input type="submit" border="0" name="submit" value="Buy Now!" />
</form>
我已在我的 Paypal 开发人员控制面板中设置了我的 Paypal IPN url,因为它不起作用我将 notify_url 添加到按钮。
我尝试了ipn测试模拟器,得到了这个错误响应:
IPN 未发送,握手未验证。请检查您的信息。
我正在使用这个 IPN 脚本
<?php
// CONFIG: Enable debug mode. This means we'll log requests into 'ipn.log' in the same directory.
// Especially useful if you encounter network errors or other intermittent problems with IPN (validation).
// Set this to 0 once you go live or don't require logging.
define("DEBUG", 1);
// Set to 0 once you're ready to go live
define("USE_SANDBOX", 1);
define("LOG_FILE", "./giggdipn.log");
// Read POST data
// reading posted data directly from $_POST causes serialization
// issues with array data in POST. Reading raw POST data from input stream instead.
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval)
$keyval = explode ('=', $keyval);
if (count($keyval) == 2)
$myPost[$keyval[0]] = urldecode($keyval[1]);
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc'))
$get_magic_quotes_exists = true;
foreach ($myPost as $key => $value)
if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1)
$value = urlencode(stripslashes($value));
else
$value = urlencode($value);
$req .= "&$key=$value";
// Post IPN data back to PayPal to validate the IPN data is genuine
// Without this step anyone can fake IPN data
if(USE_SANDBOX == true)
$paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
else
$paypal_url = "https://www.paypal.com/cgi-bin/webscr";
$ch = curl_init($paypal_url);
if ($ch == FALSE)
return FALSE;
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
if(DEBUG == true)
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
// CONFIG: Optional proxy configuration
//curl_setopt($ch, CURLOPT_PROXY, $proxy);
//curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
// Set TCP timeout to 30 seconds
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
// CONFIG: Please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set the directory path
// of the certificate as shown below. Ensure the file is readable by the webserver.
// This is mandatory for some environments.
//$cert = __DIR__ . "./cacert.pem";
//curl_setopt($ch, CURLOPT_CAINFO, $cert);
$res = curl_exec($ch);
if (curl_errno($ch) != 0) // cURL error
if(DEBUG == true)
error_log(date('[Y-m-d H:i e] '). "Can't connect to PayPal to validate IPN message: " . curl_error($ch) . PHP_EOL, 3, LOG_FILE);
curl_close($ch);
exit;
else
// Log the entire HTTP response if debug is switched on.
if(DEBUG == true)
error_log(date('[Y-m-d H:i e] '). "HTTP request of validation request:". curl_getinfo($ch, CURLINFO_HEADER_OUT) ." for IPN payload: $req" . PHP_EOL, 3, LOG_FILE);
error_log(date('[Y-m-d H:i e] '). "HTTP response of validation request: $res" . PHP_EOL, 3, LOG_FILE);
// Split response headers and payload
list($headers, $res) = explode("\r\n\r\n", $res, 2);
curl_close($ch);
// Inspect IPN validation result and act accordingly
if (strcmp ($res, "VERIFIED") == 0)
// check whether the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your PayPal email
// check that payment_amount/payment_currency are correct
// process payment and mark item as paid.
// 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'];
$custom = $_POST['custom'];
include($_SERVER['DOCUMENT_ROOT'].'/addme/config/connect.php');
include($_SERVER['DOCUMENT_ROOT'].'/functions/global-functions.php');
if (strtolower($payment_status) == 'completed')
//good stuff happens here
else
//bad stuff happens here
if(DEBUG == true)
error_log(date('[Y-m-d H:i e] '). "Verified IPN: $req ". PHP_EOL, 3, LOG_FILE);
else if (strcmp ($res, "INVALID") == 0)
// log for manual investigation
// Add business logic here which deals with invalid IPN messages
if(DEBUG == true)
error_log(date('[Y-m-d H:i e] '). "Invalid IPN: $req" . PHP_EOL, 3, LOG_FILE);
exit();
?>
所以我按下了 paypal 按钮并被重定向到 paypal 沙箱页面,我使用测试帐户登录并付款。付款成功,我返回到我指定的页面。没有任何 IPN 活动。
//good stuff happens here
我正在收集信息并将其输入到我的 SQL 数据库中。我还在更新用于测试的日志文件。但什么都没有发生。
我很困惑,因为我确实只在 giggdipn.log 中登录过一次。它说:
[2016-02-26 17:27 America/Chicago] 无法连接到 PayPal 以验证 IPN 消息:SSL 连接错误
我删除它并再次尝试,只是为了看看,现在我根本没有得到它。
所以我用谷歌搜索并尝试添加:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
我还是一无所获。
【问题讨论】:
您确定您为 ipn 响应提供的 url 正确且可从外部访问吗? 否决票接受你会认为我很愚蠢!这证明我是!!!!我完全忘记了我使用不是来自我的 IP 地址的 htaccess 重定向所有流量!我刚上床睡觉,早上我将创建一个规则以允许访问 ipn。我猜这一定是问题所在。当我这样做时,我会更新你。不敢相信我完全忽略了这一点,花了将近半天的时间!!非常感谢你,我现在可以睡个好觉了! 是的,它现在工作正常,我已经完成了付款部分。 :-) 我必须先设置我的 ssl 证书。 可以在官方关闭原因下关闭:这个问题是由于无法再复制的问题或简单的印刷错误引起的。虽然类似的问题可能是这里的主题,但这个问题的解决方式不太可能帮助未来的读者。 【参考方案1】:确保为 IPN 响应提供的 Url 可供外界访问。
【讨论】:
添加了访问规则,现在我正在更新我的日志文件,但是我收到了错误; [2016-02-27 02:59 America/Chicago] 无法连接到 PayPal 以验证 IPN 消息:SSL 连接错误 - 我现在正在设置我的专用服务器并将安装我的扩展 ssl 证书。当它完成后,我希望我会解决这个问题,但我会以任何一种方式更新它......随着时间的推移,为我交叉手指! 最简单的答案有时最难找到。我怀疑 ssl 错误与注释的 cacert 代码块有关,但在设置 ssl 时不需要它。以上是关于Paypal IPN 通知未发送的主要内容,如果未能解决你的问题,请参考以下文章