Php 贝宝IPN-它是如何工作的?
我需要一个关于贝宝IPN如何工作的简要解释。没有任何细节,只是基本的东西 我应该如何设置HTML变量以及如何获取数据以验证Paypal的付款?这就是我所需要知道的,我找不到关于这一点的快速解释 如果可能的话,给我看一些代码行,肯定会有帮助 谢谢。是一种消息服务,用于发送有关特定事件的通知,例如:Php 贝宝IPN-它是如何工作的?,php,html,paypal,payment,Php,Html,Paypal,Payment,我需要一个关于贝宝IPN如何工作的简要解释。没有任何细节,只是基本的东西 我应该如何设置HTML变量以及如何获取数据以验证Paypal的付款?这就是我所需要知道的,我找不到关于这一点的快速解释 如果可能的话,给我看一些代码行,肯定会有帮助 谢谢。是一种消息服务,用于发送有关特定事件的通知,例如: 即时支付,包括快速结帐、直接信用卡 付款和授权(授权的交易付款) 但尚未收集) eCheck付款和相关状态,如待定、已完成或 被拒绝,以及由于其他原因(如 审查是否存在潜在欺诈 定期付款和订阅操作 与
- 即时支付,包括快速结帐、直接信用卡 付款和授权(授权的交易付款) 但尚未收集)
- eCheck付款和相关状态,如待定、已完成或 被拒绝,以及由于其他原因(如 审查是否存在潜在欺诈
- 定期付款和订阅操作
- 与合同相关的退单、争议、撤销和退款 交易
- 即时支付,包括快速结帐、直接信用卡 付款和授权(授权的交易付款) 但尚未收集)
- eCheck付款和相关状态,如待定、已完成或 被拒绝,以及由于其他原因(如 审查是否存在潜在欺诈
- 定期付款和订阅操作
- 与合同相关的退单、争议、撤销和退款 交易
code
我已经多次使用了与此类似的c#版本(PHP版本看起来非常类似)
我发现非常有用(并且易于使用):我发现非常有用(并且易于使用):谢谢。我认为Paypal IPN需要一些设置,我从来没有想过我可以像这样直接使用它。我正在用Paypal沙箱测试我的代码,这是否意味着我必须将此代码中的www.
更改为沙箱。
?您可能需要更改URL…您还需要在开发人员区域设置测试IPN通知。PayPal配置UI令人困惑,但实际的IPN过程很简单。您还需要确保PayPal可以访问您的IPN处理程序,即它需要是一个公共URL。它是公共的,是一个简单的URL,看起来像这样http://localhost/phpsite/donations/donate/index.php?mode=success
,但当我从paypal返回此页面时,会用一些商家的东西替换?mode=success.:\@AlphaMale链接到的文档中也有关于该过程的良好信息:谢谢。我认为Paypal IPN需要一些设置,我从来没有想过我可以像这样直接使用它。我正在用Paypal沙箱测试我的代码,这是否意味着我必须将此代码中的www.
更改为沙箱。
?您可能需要更改URL…您还需要在开发人员区域设置测试IPN通知。PayPal配置UI令人困惑,但实际的IPN过程很简单。您还需要确保PayPal可以访问您的IPN处理程序,即它需要是一个公共URL。它是公共的,是一个简单的URL,看起来像这样http://localhost/phpsite/donations/donate/index.php?mode=success
,但当我从paypal返回此页面时,会用一些商家的东西替换?mode=success.:\@AlphaMale链接到的文档也有关于这个过程的良好信息:我发现这个PHP类非常有用(并且易于使用):这就是我正在寻找的。谢谢你的评论-如果这是一个答案,我肯定会接受它:作为一个答案公布!很高兴这有帮助
<?php
//reading raw POST data from input stream. reading pot data from $_POST may cause serialization issues since POST data may contain arrays
$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_exits = true;
}
foreach ($myPost as $key => $value)
{
if($get_magic_quotes_exits == true && get_magic_quotes_gpc() == 1)
{
$value = urlencode(stripslashes($value));
}
else
{
$value = urlencode($value);
}
$req .= "&$key=$value";
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.paypal.com/cgi-bin/webscr');
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_HTTPHEADER, array('Host: www.paypal.com'));
// In wamp like environment where the root authority certificate doesn't comes in the bundle, you need
// to download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set the directory path
// of the certificate as shown below.
// curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
$res = curl_exec($ch);
curl_close($ch);
// 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'];
if (strcmp ($res, "VERIFIED") == 0) {
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
?>