我正在使用我的网站设置paypal IPN,以便登录的用户可以购买积分。我已经有会话和登录和$ id变量,什么不是,我不需要任何帮助。我需要有关paypal IPN方面的帮助。所以,到目前为止我所拥有的通知网址也是我在paypal帐户上设置的。这是通知网址:
$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语句在我测试时工作得很好等等。我唯一的问题是付款。我不知道如何让用户付费。我知道如何设置paypal API并将paypal付款与我的网站集成...是我必须做的事情?如果没有,那么我如何允许用户输入自定义金额,让他们付款,然后他们的付款将由通知网址自动验证?这个问题似乎相当广泛,但我不是要求任何人为我编写免费代码。我只是想找个人指出我正确的方向,因为我已经搜索了这么长时间并且很难找到这些信息,我似乎无法找到它。非常感谢所有帮助!谢谢:))
答案 0 :(得分:0)
IPN是一种交易后处理工具。它本身并不实际处理事务(除非您碰巧在您的IPN脚本中完成了自己的API集成。)
所以,是的,您需要使用Payments Standard,Express Checkout / Pro或任何您熟悉的实际将付款部分绑定到您的网站。然后,一旦付款,它将相应地触发IPN。