[英]How to setup payments with paypal IPN
我正在我的网站上设置Paypal IPN,以便已登录的用户可以购买积分。 我已经有了会话和登录名以及$ id变量,什么也没有,我不需要任何帮助。 我需要有关贝宝IPN方面的帮助。 因此,到目前为止,我是在我的Paypal帐户上设置的通知URL。 这是通知网址:
$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";
}
// STEP 2: Post IPN data back to paypal to validate
$ch = curl_init('https://www.paypal.com/cgi-bin/webscr'); // change to [...]sandbox.paypal[...] when using sandbox to test
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);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
// In wamp like environments that do not come bundled with root authority certificates,
// please 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');
if( !($res = curl_exec($ch)) ) {
// error_log("Got " . curl_error($ch) . " when processing IPN data");
curl_close($ch);
exit;
}
curl_close($ch);
// STEP 3: 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 Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
if ($_POST['mc_gross'] != NULL)
$payment_amount = $_POST['mc_gross'];
else
$payment_amount = $_POST['mc_gross1'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
$custom = $_POST['custom'];
// Insert your actions here
if ($payment_status = "Completed")
{
// my sql statement to update the points will go here, I don't need help
// with that
}
if ($txn_id)
{
}
} else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
因此,这似乎设置正确,没有错误,我要添加的SQL语句在测试它们时效果很好,等等。我唯一的问题是付款。 我不知道如何让用户付费。 我知道如何设置贝宝API并将贝宝付款与我的网站集成...这就是我要做的吗? 如果不是,那么我如何允许用户输入自定义金额,让他们付款,然后通知URL自动验证他们的付款? 这个问题看似很广泛,但我并不是要任何人为我编写免费代码。 我只是在寻找可以为我指出正确方向的人,因为我已经花了很长时间寻找这些信息,但似乎找不到。 非常感谢所有帮助! 谢谢 :)
IPN是事后处理工具。 它实际上并不本身处理事务(除非您碰巧在正在执行的IPN脚本中完成了自己的API集成。)
因此,是的,您需要使用Payments Standard,Express Checkout / Pro或任何您愿意的方式将付款部分实际绑定到您的网站。 然后,一旦付款,它将相应地触发IPN。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.