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


$date = date('d/m/Y_H:i:s');
$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>';	




   $datal="ahhhhgs";
    
    

$result1 = mysqli_query($conn,"INSERT INTO `addmoney` ( `email`, `m_id`, `oderid`, `txid`, `amount`, `status`, `trans_date`, `data`) VALUES ( '$datal', '$pid', '$orid', '$txnid', '$amount', '$status', '$date', '$paramList')");
$result = mysqli_query($conn,"SELECT * FROM `userdataa` WHERE `id`='$pid'");





if ($result->num_rows > 0) {
  // output data of each row
  $result = mysqli_query($conn,"SELECT * FROM `userdataa` WHERE `id`='$pid'");
  while($row = $result->fetch_assoc()) {
   $totalcoin=$row['addmoney'];
   
   
  }
 
 
  $newcoin=$totalcoin+$amount;


if ($result) {
    
  $sql3 = mysqli_query($conn,"UPDATE `userdataa` SET `addmoney` = '$newcoin' WHERE `userdataa`.`id` ='$pid'");

if($result1){
header("Location: Sucess23.php");
die();
}
} else {
  echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();

}else{
header("Location: fail.php");
}

	
}else{
header("Location: fail.php");
}
    
    
    
    
 
?>