0){
while($row=mysqli_fetch_assoc($trans_result)){
$client_txn_id=$row['client_txn_id'];
$user_token=$row['user_token'];
$amount=$row['amount'];
$token=$row['gateway_key'];
$sql234 = "SELECT * FROM `orders` WHERE order_id = '$client_txn_id'";
// Execute the query
$result = mysqli_query($connnew, $sql234);
// Check if the query was successful
if (mysqli_num_rows($result) > 0) {
// Fetch and display the results
while ($row = mysqli_fetch_assoc($result)) {
$bytepaytmtxnref=$row["paytm_txn_ref"];
$remark = $row['remark1'];
echo "Order ID: " . " - Byte Transaction ID: " . $row["paytm_txn_ref"] . "
";
}
} else {
echo "No results found.";
}
$sqlSelectMid = "SELECT MID FROM paytm_tokens WHERE user_token='$token'";
$resultMid = mysqli_query($connnew, $sqlSelectMid);
while ($rowMid = mysqli_fetch_assoc($resultMid)) {
$mid = $rowMid['MID'];
}
// Replace with your actual MID
$txn_ref_id = $bytepaytmtxnref; // Replace with your actual transaction reference ID
// Create the JSON data
$JsonData = json_encode(array("MID" => $mid, "ORDERID" => $txn_ref_id));
// Initialize cURL session
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, "https://securegw.paytm.in/order/status?JsonData=" . urlencode($JsonData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute the cURL request and store the response
echo $result = curl_exec($ch);
// Check if decoding was successful
$responseArray = json_decode($result, true);
if ($responseArray !== null) {
$transactionId= $responseArray['TXNID'];
$paymentState=$responseArray['STATUS'];
$vpa="test@paytm";
$user_name="NULL";
$paymentApp=$responseArray['GATEWAYNAME'];
$TXNAMOUNT=$responseArray['TXNAMOUNT'];
$t_date=$responseArray['TXNDATE'];
$cxrmerchantTransactionId=$responseArray['ORDERID'];
$bytehackamount=$amount;
$payUTR=$responseArray['BANKTXNID'];
// $status=$paymentState;
//
$orderId = $client_txn_id;
$txn_at = $t_date;
$message = 'Transaction Pending';
$status= 'PENDING';
if($TXNAMOUNT==$amount ){
$utr = $payUTR;
if ($responseArray['STATUS'] == "TXN_SUCCESS"){
$status='SUCCESS';
$message = 'Transaction Successfully';
}
if ($responseArray['STATUS'] == "FAILURE" || $responseArray['STATUS'] == "TXN_FAILURE" ){
$status= 'FAILURE';
$message = 'Transaction Failed';
}
$keysql="select * from transactions where client_txn_id='$orderId' and status='PENDING'";
$order_result=mysqli_query($conn,$keysql);
if(mysqli_num_rows($order_result)>0){
$sql1 = "update transactions set amount='$amount',message='$message',remark='$remark',status='$status',upi_txn_id='$utr',txnAt='$txn_at',entry='webhook' where client_txn_id='$orderId'";
$res=mysqli_query($conn, $sql1);
if($status=="SUCCESS"){
$sql123 = "update transactions set `amt_update`='$date' where client_txn_id='$orderId'";
$res123=mysqli_query($conn, $sql123);
$keysql1="select * from payin_wallet where user_token='$user_token'";
$order_result1=mysqli_query($conn,$keysql1);
if(mysqli_num_rows($order_result1)>0){
while($row1=mysqli_fetch_assoc($order_result1)){
$current_amount=$row1['current_amount'];
$total_amount=$row1['total_amount'];
$total_current= $current_amount+$amount;
$total_amt= $total_amount+$amount;
echo $sql12 = "update payin_wallet set current_amount='$total_current' , total_amount='$total_amt' where user_token='$user_token'";
$res=mysqli_query($conn, $sql12);
$sqlhis = "INSERT INTO udate_history (update_date,amount,user_token,order_id) VALUES ('$date','$amount','$user_token','$orderId')";
$histry=mysqli_query($conn, $sqlhis);
}
}
}
if($status=="SUCCESS"){
$fetchsql="select * from transactions where client_txn_id='$orderId' and user_token='$user_token'";
$fetch_result=mysqli_query($conn,$fetchsql);
while($rowdata=mysqli_fetch_assoc($fetch_result)){
$response['orderId'] =$rowdata['client_txn_id'];
$response['message']=$rowdata['message'];
$response['amount']=$rowdata['amount'];
$response['status']=$rowdata['status'];
$response['utr']=$rowdata['upi_txn_id'];
$response['status'] = $rowdata['status'];
$response['date'] = $rowdata['txnAt'];
$json_response = json_encode($response);
// echo $json_response;
// Encode data to JSON
$jsonData = $json_response;
$sql01="select * from users where user_token='$user_token' and callback_url!=''";
$result_user=mysqli_query($conn,$sql01);
while($row01=mysqli_fetch_assoc($result_user)){
$callback_url=$row01['callback_url'];
// Set up cURL
// $webhookUrl = "https://merchant.indpay.in.net/callbackurl.php";
$webhookUrl=$callback_url;
$ch = curl_init($webhookUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($jsonData)
]);
// Execute cURL
echo $resp = curl_exec($ch);
// Close cURL
curl_close($ch);
}
}
}
if($status=="FAILURE"){
$sql123 = "update transactions set `amt_update`='$date' where client_txn_id='$orderId'";
$res123=mysqli_query($conn, $sql123);
$fetchsql="select * from transactions where client_txn_id='$orderId' and user_token='$user_token'";
$fetch_result=mysqli_query($conn,$fetchsql);
while($rowdata=mysqli_fetch_assoc($fetch_result)){
$response['orderId'] =$rowdata['client_txn_id'];
$response['message']=$rowdata['message'];
$response['amount']=$rowdata['amount'];
$response['status']=$rowdata['status'];
$response['utr']=$rowdata['upi_txn_id'];
// $response['status'] = $rowdata['status'];
$response['date'] = $rowdata['txnAt'];
$json_response = json_encode($response);
// echo $json_response;
// Encode data to JSON
$jsonData = $json_response;
$sql01="select * from users where user_token='$user_token' and callback_url!=''";
$result_user=mysqli_query($conn,$sql01);
while($row01=mysqli_fetch_assoc($result_user)){
$callback_url=$row01['callback_url'];
// Set up cURL
// $webhookUrl = "https://merchant.indpay.in.net/callbackurl.php";
$webhookUrl=$callback_url;
$ch = curl_init($webhookUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($jsonData)
]);
// Execute cURL
echo $resp = curl_exec($ch);
// Close cURL
curl_close($ch);
}
}
}
}
}else{
$sql1 = "update transactions set amount='$amount',message='Transaction Failed',remark='$remark',status='FAILURE',upi_txn_id='$utr',txnAt='$txn_at',entry='webhook' where client_txn_id='$orderId'";
$res=mysqli_query($conn, $sql1);
}
}
// $token="183ee74eb4417a7e5caa95b385721748";
// $fields = [
// 'order_id' => $client_txn_id,
// 'user_token' => $token,
// ];
// $postdata = http_build_query($fields);
// $ch = curl_init();
// curl_setopt($ch, CURLOPT_URL, 'https://payin.indpay.in.net/api/check-order-status');
// curl_setopt($ch, CURLOPT_POST, true);
// curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// $result = curl_exec($ch);
// echo $result;
// echo "
";
// $json_output = json_decode($result, true);
// if ($json_output['status']) {
// }else{
// $message = $json_output['message'];
// if($message=='Order not found'){
// $keysql1="select * from transactions where client_txn_id='$client_txn_id' and status='PENDING'";
// $order_result1=mysqli_query($conn,$keysql1);
// if(mysqli_num_rows($order_result1)>0){
// echo $sql1 = "update transactions set message='$message',remark='$message',status='FAILURE',entry='webhook' where client_txn_id='$client_txn_id'";
// $res=mysqli_query($conn, $sql1);
// }
// }
// }
}
}
?>