【发布时间】:2019-02-27 21:16:27
【问题描述】:
我已经在这工作了 3 天了,但仍然无法正常工作。
我想要做的是从 IPN 侦听器获取 PayPal 响应,以便我可以相应地修改我的数据库,但无论我做什么,它都不起作用。我已经在我的 PayPal Sandbox 帐户中完成了以下操作:
启用自动返回
设置自动返回 URL('paypal/success')
- 启用支付数据传输 (PDT)
- 启用 IPN 消息接收
- 设置 IPN URL ('paypal/ipn')
重定向到自动返回 URL 工作正常,我在成功页面中收到付款数据,但 IPN 不会因为我以外的原因处理。快速查看我的 PayPal 个人资料中的 IPN 历史记录显示正在发送消息,但我没有收到它们。
这是我当前的 IPN 监听器:Paypal/ipn
public function ipn() {
//Build the data to post back to Paypal
$postback = 'cmd=_notify-validate';
// go through each of the posted vars and add them to the postback variable
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$postback .= "&$key=$value";
}
// build the header string to post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Host: www.sandbox.paypal.com\r\n";//or www.sandbox.paypal.com
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($postback) . "\r\n\r\n";
// Send to paypal or the sandbox depending on whether you're live or developing
// comment out one of the following lines
$fp = fsockopen ('www.sandbox.paypal.com', 443, $errno, $errstr, 30);//open the connection
//$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
// or use port 443 for an SSL connection
//$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
if ( ! $fp ) {
// HTTP ERROR Failed to connect
$message = 'HTTP ERROR Failed to connect!';
$this->email_me($message);
} else { // if we've connected OK
fputs ($fp, $header . $postback); //post the data back
while ( ! feof($fp) ) {
$response = fgets ($fp, 1024);
if (strcmp (trim($response), "VERIFIED") == 0) { //It's verified
//read the payment details and the account holder
$payment_status = $_POST['payment_status'];
$receiver_email = urldecode($_POST['receiver_email']);
// further checks
if( ($payment_status == 'Completed') && ($receiver_email == $this->business_email) ) {
$message = 'IPN verified successfully!';
$this->email_me($message);
// Insert the transaction data in the database
$this->product_model->insert_transaction_details($_POST);
} else {
$message = 'Payment could not be verified!';
$this->email_me($message);
}
} else {
$message = 'IPN invalid!';
$this->email_me($message);
}
}
}
}
有人能指出我正确的方向吗? 另外,我是否可以在 chrome 调试器或我的 PayPal Sandbox 仪表板中检查 IPN 响应(“已验证”或“无效”)?我可以在我的仪表板中看到交货状态,但它没有在任何地方显示“已验证”或“无效”。
【问题讨论】:
-
您的 IPN 端点是否可以从 Internet 访问?如果它在本地主机上,PayPal 将无法连接到它。
-
它在实时服务器上。
-
我不明白你的意思@Mark_1
-
如果您的服务器位于防火墙后面,您需要添加规则以允许 PayPal 的 IPN 进程连接到您的服务器。如果每个人都可以访问您的服务器,则不需要这样做。
标签: php codeigniter paypal paypal-ipn