我有以下脚本来获取$ _REQUEST数据来执行数据库处理,我可以通过在同一服务器上为测试分配测试数据来执行此脚本,但是在实时测试中,它始终显示Transaction aborted! Specific transaction not found!
消息甚至$trx !== FALSE
正在执行,我可以检查所有数据是否也在DB中更新,它停在这里,其余的进程如points deduction
和create invoice
都没有执行,我想知道为什么TEST DATA
和REAL TIME DATA
具有不同的行为和结果,在相同的服务器环境中进行了测试,所有设置都相同,实时数据也适用于测试。
我需要有人帮助查看我的代码是否出错?
<?php
//Real time data get from payment provider
$refNo = $_REQUEST['RefNo'];
$transId = $_REQUEST['TransId'];
$authcode = $_REQUEST['AuthCode'];
$eStatus = $_REQUEST['Status'];
$signature = $_REQUEST['Signature'];
/* TEST DATA */
$eStatus = 1;
$refNo = '1468408036-0JSKZ8';
$transId = 'T108902465200';
$authcode = '3FL931320S778334X';
$signature = 'zVq0m7WKxyDuOKVdExIQbaoJCi0=';
if($eStatus == 1){
try {
// Check whether have such order in db
// If yes, get all relevant details for invoice generation.
$trx = $buyer->get_transaction_if_exist(filter_var($refNo, FILTER_SANITIZE_STRING), $mysqli);
if($trx !== FALSE){
//Update payment status in db
$postVars = array(
'payment_status' => 'completed',
'payment_id' => $transId,
'auth_code' => $authcode,
'signature' => $signature
);
if($buyer->update($postVars, 'pp_transaction', 'order_num', $refNo, $mysqli) === TRUE){
//perform Points deduction if found checkout with Points+Cash
$points_consume = $trx->total_points_consume;
$checkout_method = $trx->checkout_method;
$member_id = $trx->member_id;
//get existing Points
$cust = $buyer->get_customer_by_id($account_id, $mysqli);
$leftover_Points = $cust->my_points - $points_consume;
if($checkout_method == 2){
//update deduction points to member account
$arr1 = array('my_points' => $leftover_Points);
$buyer->update($arr1, 'members', 'acct_id', $member_id, $mysqli);
//log
$logVar = array(
'acct_id' => $account_id,
'order_num' => $refNo,
'point_consume' => $points_consume
);
$buyer->insert($logVar, 'points_consume_log', $mysqli);
}
//Generate invoice and send to buyer
require(WEBROOT.'/createInvoice.php');
require(WEBROOT.'/sendInvoice.php');
}
}else{
//Cannot found specific transaction record in DB
$payment_error = 'Transaction aborted!';
$error_desc = 'Specific transaction not found!';
}
} catch (Exception $e) {
$payment_error = $e->getMessage();
//die();
}
}
?>
查询是否存在此类订单:
public function get_transaction_if_exist($refno, $mysqli)
{
if(empty($refno)){
return false;
}
$q = "SELECT * FROM `pp_transaction` ";
$q .= "WHERE order_num='".$refno."' ";
$q .= "AND payment_status IN('pending','failed')";
$sql = $mysqli->query($q);
if($sql->num_rows > 0){
$obj = $sql->fetch_object();
return $obj;
}
return false;
}
非常感谢。
答案 0 :(得分:0)
以下是我可以想到的为什么它可以用于测试数据而不是真实数据的可能性:
$refno
,或匹配记录的payment_status
不是IN ('pending','failed')
$refNo
值不是您所期望的$refNo
正确,可能执行查询时出错,因此它永远不会成功运行SELECT
命令测试方案1
像以前一样使用所有真实数据,但硬编码$refNo
,其中包含您知道在数据库中的数字,在您知道的payment_status
是pending
或{{1}的记录上}}。如果脚本有效,那么您就找到了问题。
测试方案2
在运行查询之前,在failed
函数中添加var_dump($refno); die();
。验证回显的值是否与方案1一致。
测试方案3
向get_transaction_if_exist
get_transaction_if_exist
如果打印出SQL错误,则表示您已找到问题