Php Paypal IPN未更新数据库
我已经阅读了许多已经提交的帮助请求,但没有一个对我有帮助。所以我正在提交我的代码,看看是否有人可以帮助我 所以,当我做一个沙箱测试时,IPN得到了验证,但我的代码没有运行。有人能帮我吗 我之所以要更新,是因为当有人单击“购买”按钮时,它会在paypal中输入一个自定义字段,并带有一个记录id以进行跟踪,这是可行的,但不会被更新 IPNListener.php:Php Paypal IPN未更新数据库,php,paypal,Php,Paypal,我已经阅读了许多已经提交的帮助请求,但没有一个对我有帮助。所以我正在提交我的代码,看看是否有人可以帮助我 所以,当我做一个沙箱测试时,IPN得到了验证,但我的代码没有运行。有人能帮我吗 我之所以要更新,是因为当有人单击“购买”按钮时,它会在paypal中输入一个自定义字段,并带有一个记录id以进行跟踪,这是可行的,但不会被更新 IPNListener.php: <?php require_once("MAILER/smtpservice.php"); funct
<?php
require_once("MAILER/smtpservice.php");
function Connect()
{
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "root";
$dbname = "server";
// Create connection
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname) or die($conn->connect_error);
return $conn;
}
$conn = Connect();
class PayPal_IPN {
function ipn($ipn_data) {
define('SSL_P_URL', 'https://www.paypal.com/cgi-bin/webscr');
define('SSL_SAND_URL', 'https://www.sandbox.paypal.com/cgi-bin/webscr');
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
if (!preg_match('/paypal\.com$/', $hostname)) {
$ipn_status = 'Validation post isn\'t from PayPal';
if ($ipn_data == true) {
//You can send email as well
}
return false;
}
// parse the paypal URL
$paypal_url = ($_REQUEST['test_ipn'] == 1) ? SSL_SAND_URL : SSL_P_URL;
$url_parsed = parse_url($paypal_url);
$post_string = '';
foreach ($_REQUEST as $field => $value) {
$post_string .= $field . '=' . urlencode(stripslashes($value)) . '&';
}
$post_string.="cmd=_notify-validate"; // append ipn command
// get the correct paypal url to post request to
$paypal_mode_status = $ipn_data; //get_option('im_sabdbox_mode');
if ($paypal_mode_status == true)
$fp = fsockopen('ssl://www.sandbox.paypal.com', "443", $err_num, $err_str, 60);
else
$fp = fsockopen('ssl://www.paypal.com', "443", $err_num, $err_str, 60);
$ipn_response = '';
if (!$fp) {
// could not open the connection. If loggin is on, the error message
// will be in the log.
$ipn_status = "fsockopen error no. $err_num: $err_str";
if ($ipn_data == true) {
echo 'fsockopen fail';
}
return false;
} else {
// Post the data back to paypal
fputs($fp, "POST $url_parsed[path] HTTP/1.1\r\n");
fputs($fp, "Host: $url_parsed[host]\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: " . strlen($post_string) . "\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $post_string . "\r\n\r\n");
// loop through the response from the server and append to variable
while (!feof($fp)) {
$ipn_response .= fgets($fp, 1024);
}
fclose($fp); // close connection
}
// Invalid IPN transaction. Check the $ipn_status and log for details.
if (!preg_match("/VERIFIED/s", $ipn_response)) {
$ipn_status = 'IPN Validation Failed';
if ($ipn_data == true) {
echo 'Validation fail';
print_r($_REQUEST);
}
return false;
} else {
$ipn_status = "IPN VERIFIED";
if ($ipn_data == true) {
echo 'SUCCESS';
}
return true;
}
}
function ipn_response($request) {
//mail("sanjeev00733@gmail.com","My subject",print_r($request,true));
$ipn_data = true;
if ($this->ipn($ipn_data)) {
// if paypal sends a response code back let's handle it
if ($ipn_data == true) {
//mail send
$sub = 'PayPal IPN Message';
$msg = print_r($request, true);
$to = "jcagnor@gmail.com";
sendEmail($to, $sub, $msg);
}
// process the membership since paypal gave us a valid +
$this->insert_data($request);
}
}
function issetCheck($post, $key) {
if (isset($post[$key])) {
$return = $post[$key];
} else {
$return = '';
}
return $return;
}
function insert_data($request) {
global $conn;
$post = $request;
$item_name = $this->issetCheck($post, 'item_name');
$amount = $this->issetCheck($post, 'mc_gross');
$currency = $this->issetCheck($post, 'mc_currency');
$payer_email = $this->issetCheck($post, 'payer_email');
$first_name = $this->issetCheck($post, 'first_name');
$last_name = $this->issetCheck($post, 'last_name');
$country = $this->issetCheck($post, 'residence_country');
$txn_id = $this->issetCheck($post, 'txn_id');
$txn_type = $this->issetCheck($post, 'txn_type');
$payment_status = $this->issetCheck($post, 'payment_status');
$payment_type = $this->issetCheck($post, 'payment_type');
$payer_id = $this->issetCheck($post, 'payer_id');
$record_id = $this->issetCheck($post, 'custom');
$create_date = date('Y-m-d H:i:s');
$payment_date = date('Y-m-d H:i:s');
$conn->query("UPDATE donateinfo SET item_name = '$item_name', payment_amount = '$amount', payment_status = '$payment_status', payment_currency = '$currency', payer_email = '$payer_email', txn_id = '$txn_id' WHERE record_id = '$record_id'");
}
}
$obj = New PayPal_IPN();
$obj->ipn_response($_REQUEST);
您的更新缺少逗号分隔符。检查上面的错误会显示语法错误。编辑:此评论与原始帖子一致-我希望这不是即时编辑。@Fred ii-仍然不起作用,我更新了原始代码以显示我所做的更改。