Php 贝宝支付验证,IPN如何工作
我正在搜索如何使用贝宝IPN即时支付通知,从过去的两周,无法理解如何在我的代码中准确使用它 我正在使用下面的HTML代码创建一个PayPal按钮 button.html 下面的代码用于处理付款和验证付款 paypal.php 一个额外的类文件:可以在这里找到 代码运行良好,但我现在遇到了一个大问题,我正在尝试从以下行验证付款是否成功,并为会话中的用户向数据库添加10个信用Php 贝宝支付验证,IPN如何工作,php,paypal,paypal-ipn,Php,Paypal,Paypal Ipn,我正在搜索如何使用贝宝IPN即时支付通知,从过去的两周,无法理解如何在我的代码中准确使用它 我正在使用下面的HTML代码创建一个PayPal按钮 button.html 下面的代码用于处理付款和验证付款 paypal.php 一个额外的类文件:可以在这里找到 代码运行良好,但我现在遇到了一个大问题,我正在尝试从以下行验证付款是否成功,并为会话中的用户向数据库添加10个信用 case 'success': // Order was successful... echo "&
case 'success': // Order was successful...
echo "<br/><p><b>Payment Successful.</b><br /></p>";
foreach ($_POST as $key => $value)
{
/*echo "$key: $value<br>";*/
// Do the required action, **add 10 credits in the database for the user on session**
}
break;
最后,问题是当我点击button.html页面上的按钮时,它会重定向到Paypal.php页面,当我输入我的Paypal登录详细信息时,付款成功
有一个小的文本->返回到发件人的网站我需要点击它,当我点击它,它会带我回到PAYPAL.PHP页面,然后案例'成功'被解雇。如果我付款并关闭PAYPAL页面而不点击RETURN TO THE SENDER的网站,并且没有等到PAYPAL.PHP页面加载,网站就无法验证付款,也无法添加信用
如何在成功付款而不是成功返回PAYPAL.PHP页面时自动执行此过程并添加积分
谢谢我觉得你把PDT和IPN搞混了。PDT的工作原理是将数据发送到您的返回URL,但这不是处理支付后处理任务的推荐方法 这就是IPN发挥作用的地方,它是将数据无声地发布到您的侦听器URL,而不管用户是否将其返回到您的返回URL。这样,不管怎样,只要所有配置都正确,代码都将始终运行 在我看来,你似乎在混合这两者,并因此得到了混合的结果
<?php
require_once('paypal.class.php'); // include the class file
$p = new paypal_class; // initiate an instance of the class
$p->paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; // testing paypal url
//$p->paypal_url = 'https://www.paypal.com/cgi-bin/webscr'; // paypal url
// setup a variable for this script (ie: 'http://www.micahcarrick.com/paypal.php')
$this_script = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
// if there is not action variable, set the default action of 'process'
if (empty($_GET['action'])) $_GET['action'] = 'process';
switch ($_GET['action']) {
case 'process': // Process and order...
$CatDescription = $_REQUEST['CatDescription'];
$payment = $_REQUEST['payment'];
$id = $_REQUEST['id'];
$key = $_REQUEST['key'];
$p->add_field('business', 'info@aoptrading.com');
$p->add_field('return', $this_script.'?action=success');
$p->add_field('cancel_return', $this_script.'?action=cancel');
$p->add_field('notify_url', $this_script.'?action=ipn');
$p->add_field('item_name', $CatDescription);
$p->add_field('amount', $payment);
$p->add_field('key', $key);
$p->add_field('item_number', $id);
$p->submit_paypal_post(); // submit the fields to paypal
//$p->dump_fields(); // for debugging, output a table of all the fields
break;
case 'success': // Order was successful...
echo "<br/><p><b>Payment Successful.</b><br /></p>";
foreach ($_POST as $key => $value) { echo "$key: $value<br>"; }
break;
case 'cancel': // Order was canceled...
echo "<br/><p><b>The order was canceled!</b></p><br />";
foreach ($_POST as $key => $value) { echo "$key: $value<br>"; }
break;
case 'ipn': // Paypal is calling page for IPN validation...
if ($p->validate_ipn()) {
// For this example, we'll just email ourselves ALL the data.
$dated = date("D, d M Y H:i:s", time());
$subject = 'Instant Payment Notification - Recieved Payment';
$to = 'info@aoptrading.com'; // your email
$body = "An instant payment notification was successfully recieved\n";
$body .= "from ".$p->ipn_data['payer_email']." on ".date('m/d/Y');
$body .= " at ".date('g:i A')."\n\nDetails:\n";
$headers = "";
$headers .= "From: Test Paypal \r\n";
$headers .= "Date: $dated \r\n";
$PaymentStatus = $p->ipn_data['payment_status'];
$Email = $p->ipn_data['payer_email'];
$id = $p->ipn_data['item_number'];
if($PaymentStatus == 'Completed' or $PaymentStatus == 'Pending'){
$PaymentStatus = '2';
}else{
$PaymentStatus = '1';
}
foreach ($p->ipn_data as $key => $value) { $body .= "\n$key: $value"; }
fopen("http://www.virtualphoneline.com/admins/TestHMS.php?to=".urlencode($to)."&subject=".urlencode($subject)."&message=".urlencode($body)."&headers=".urlencode($headers)."","r");
}
break;
}
?>
case 'success': // Order was successful...
echo "<br/><p><b>Payment Successful.</b><br /></p>";
foreach ($_POST as $key => $value)
{
/*echo "$key: $value<br>";*/
// Do the required action, **add 10 credits in the database for the user on session**
}
break;