
<?php

include "../control/activity.php";
$dd = new activity();


$table = "admin_calculation";
$condition = null;
$getAdminDetails = $dd->single($table,$condition);



session_start();

require_once "connection.php";

$am = $_REQUEST['am'];
$userKey= $_REQUEST['loginKey'];

error_reporting(0);
require_once('lib/AhkWeb_Config.php');
require_once('lib/AhkWebCheckSum.php');
//print_r($_POST);
$verifySignature = '';
$array = array();
$paramList = array();

$secret = $getAdminDetails['geteway_secret']; // Your Secret Key.
$status = $_POST['status']; // Its Payment Status Only, Not Txn Status.
$message = $_POST['message']; // Txn Message.
$cust_Mobile = $_POST['cust_Mobile']; // Txn Message.
$cust_Email = $_POST['cust_Email']; // Txn Message.
$hash = $_POST['hash']; // Encrypted Hash / Generated Only SUCCESS Status.
$checksum = $_POST['checksum'];  // Checksum verifySignature / Generated Only SUCCESS Status.

// Payment Status.
if($status=="SUCCESS"){
	
$paramList = hash_decrypt($hash,$secret);
$verifySignature = AhkWebCheckSum::verifySignature($paramList, $secret, $checksum);

// Checksum verify.
if($verifySignature){
    
 $arr = json_decode($paramList);
 $status = $arr->txnStatus;
 $txnAmount = $arr->txnAmount;
 $utr = $arr->utr;
 $sender_note = $arr->sender_note;

if($status == "TXN_SUCCESS")
{
     $table = "userdetails";
     $value = "wallet=wallet+$txnAmount";
     $condition = " userKey='$sender_note'";
     $result = $dd->updateData($table,$value,$condition);
     if($result){
         $date = date("h:i d/m/Y");
         $ref = mt_rand(1111111111,9999999999);
         $table = "funds_request";
         $value = "(`userKey_id`, `request_date`, `request_type`, `amount`, `refrence_number`, `funds_status`, `approved_date`, `avl_balance`, `remark`) 
         SELECT '$sender_note','$date','Automatic','$txnAmount','$utr','Approved','$date',wallet,'Funds add by automatic' FROM userdetails WHERE userKey='$sender_note'";
         $result= $dd->insertData($table,$value);
         if($result){
             $_SESSION['loginKey']=$sender_note;
            echo "<script>alert('Payment successfull..!!'),window.open('../index.php','_self')</script>";
         }
     }
}
 
    
    
    
    

}
}else{
    echo "<script>alert('Payment Failed..!!'),window.open('../deposit.php','_self')</script>";
}

?>