<?php
  require_once 'check_security.php';
require_once('lib/AhkWeb_Config.php');
require_once('lib/AhkWebCheckSum.php');
require_once('txnResult.php');
$status=$_POST["status"];



$date=date();
$hash = $_POST['hash'];

  $array = array();
$paramList = array();
If ($status=="SUCCESS") {
    
    $paramList = hash_decrypt($hash,$secret);


// Checksum verify.

$array = json_decode($paramList);

	
foreach ($array as $key => $value) {
    if($key=="txnAmount"){
     $amount= $value;  
    }else if($key=="txnId"){
        $txnid=$value;
    }else if($key=="sender_note"){
        $pid=$value;
    }else if($key=="orderId"){
        $orid=$value;
    }
  echo "<b>$key:</b> <b style='color:green'>$value</b><hr>";
}	
echo '<h2><b style="color:green">Checksum Verified!</b></h2>';	
	
}
    
    
    
    
    
    
    
   echo "Fair Battle";
$servername = "localhost";
$username = "nuahkbzh_upi";
$password = "nuahkbzh_upi";
$dbname = "nuahkbzh_upi";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO `addmoney` ( `email`, `userid`, `oderid`, `txid`, `amount`, `status`, `trans_date`, `data`) VALUES ( '$email', $pid', '$orid', '$txnid', '$amount', '$status', '$date', '$paramList')";
$sql2 = "SELECT * FROM `userdataa` WHERE `id`='$pid'";
$result = $conn->query($sql2);

if ($result->num_rows > 0) {
  // output data of each row
  while($row = $result->fetch_assoc()) {
   $totalcoin=$row['addmoney'];
   
  }
  $newcoin=$totalcoin+$amount;
 

if ($conn->query($sql) === TRUE) {
    
  $sql3 = "UPDATE `userdatas` SET `addmoney` = '$newcoin' WHERE `id` = '$pid'";
$result1 = $conn->query($sql3);
if($result1){
    header("Location: https://fairbattle.earnmoreapp.in/fairb/Addmoney.php?sucss");
die();
}
} else {
  echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();

}else{
header("Location: https://fairbattle.earnmoreapp.in/fairb/Addmoney.php?fail");
die();
}

?>