IPN模拟器成功,但未运行数据库操作


IPN simulator Successful but does not Run database manipulation

由于某种原因,我在这方面遇到了更多的麻烦,所以我应该。。。我有一个Paypal的IPN列表,IPN模拟器每次都说成功,使用不同的方法,但我无法让它根据成功的响应来操作数据库。

有什么想法吗?

<?php
//INCLUDE CONNECTION STRING
include('connect.php');
// STEP 1: read POST data
// Reading POSTed data directly from $_POST causes serialization issues with array data in the POST.
// Instead, read raw POST data from the input stream. 
$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 IPN message sent from PayPal and prepend 'cmd=_notify-validate'
$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');
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'));
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) {
// 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($payment_status=="Completed"){
    $selectuser = mssql_query("select statsmemberid from statsmembers where email='$payer_email'");
            if(mssql_num_rows($selectuser) != 0){
            $row = mssql_fetch_row($selectuser);
            $statsmemberid = $row[0];
            $getCredits = mssql_query("select creditsbought from statsmuplayers where statsmemberid='$statsmemberid'");
            $row = mssql_fetch_row($getCredits);
            $totalCredits = $row[0]+11;             
            $updatemu = mssql_query("update statsmuplayers set creditsbought='$totalCredits' where statsmemberid='$statsmemberid'");
            echo "Credits Applyed";
            }else{
                echo "Invalid Email";
            }


}

} else if (strcmp ($res, "INVALID") == 0) {
// IPN invalid, log for manual investigation
echo "The response from IPN was: <b>" .$res ."</b>";
}
?>

我建议您将所有这些代码封装到几个对象中。这将真正帮助你找出哪里出了问题。

你想要一个处理与paypal的IPN通信的对象(你不需要从头开始写,这是我在谷歌搜索中发现的第一个PHP实现https://github.com/dodev34/paypal-ipn-response-client)

然后您需要一个处理数据库连接的基础对象。最后,您需要一个statsmembers对象来扩展数据库连接对象并强制执行业务逻辑。您可能只需要提升一些PHP ORM代码,就像您在这里看到的那样http://www.phpactiverecord.org/projects/main/wiki/Quick_Start

这将允许您单独测试更新功能与实际的贝宝IPN通信。好消息是,在这一点上,您不必像上面的评论中建议的那样,依赖于写入系统文件进行调试。

我一眼就看不出你代码中的具体错误对不起,你确定你通过贝宝正确地传递了payer_email吗?