<?php 
session_start();
if(!isset($_SESSION["logged_in"]) && $_SESSION["logged_in"]!=true){
    header("Location: login.php");
    exit;
}

if(empty($_GET["id"]) && $_GET["id"]==""){
	header("Location: studentchange.php");
	exit();
}
require('db_connect.php');
$id= $_GET["id"];
$sqlCHK= mysqli_query($conn,"SELECT * FROM tbl_userregistration_ug2 WHERE payment_redirectid='".$id."'");
if(mysqli_num_rows($sqlCHK) > 0){
    $fetchDetail= mysqli_fetch_all($sqlCHK,MYSQLI_ASSOC);
    
} else {
    header("Location: studentchange.php");
	exit();
}

$salt = SALT_KEY; //Pass your SALT here
$_POST['api_key'] = API_KEY; //Pass your API KEY here

$_POST['amount'] = $fetchDetail[0]["payable_amount"];
//$_POST['amount'] = 2;
$_POST['city'] = $fetchDetail[0]["per_district"];
$_POST['country'] = 'India';
$_POST['currency'] = 'INR';
$_POST['description'] = 'Admis-II Payment';
$_POST['email'] = $fetchDetail[0]["email"];
$_POST['mode'] = 'LIVE';
$_POST['name'] = $fetchDetail[0]["name"];
//$_POST['order_id'] = 'order_'.$fetchDetail[0]["id"];
$_POST['order_id'] = 'HDJC-UG-II'.$fetchDetail[0]["id"];
$_POST['phone'] = $fetchDetail[0]["contactno"];
$_POST['return_url'] = SITE_URL.'/return_page.php';
$_POST['state'] = $fetchDetail[0]["per_state"];
$_POST['udf1'] = $fetchDetail[0]["id"];
$_POST['udf2'] = $fetchDetail[0]["userid"];
$_POST['udf3'] = $fetchDetail[0]["coupan_serialno"];
$_POST['udf4'] = $fetchDetail[0]["coupan_code"];
$_POST['udf5'] = $fetchDetail[0]["cut_mark1"];
$_POST['zip_code'] = $fetchDetail[0]["per_postcode"];

$hash = hashCalculate($salt, $_POST);

function hashCalculate($salt,$input){
	/* Columns used for hash calculation, Donot add or remove values from $hash_columns array */
	$hash_columns = ['address_line_1', 'address_line_2', 'amount', 'api_key', 'city', 'country', 'currency', 'description', 'email', 'mode', 'name', 'order_id', 'phone', 'return_url', 'state', 'udf1', 'udf2', 'udf3', 'udf4', 'udf5', 'zip_code',];
	/*Sort the array before hashing*/
	sort($hash_columns);

	/*Create a | (pipe) separated string of all the $input values which are available in $hash_columns*/
	$hash_data = $salt;
	foreach ($hash_columns as $column) {
		if (isset($input[$column])) {
			if (strlen($input[$column]) > 0) {
				$hash_data .= '|' . trim($input[$column]);
			}
		}
	}
	$hash = strtoupper(hash("sha512", $hash_data));
	
	return $hash;
}
?>
<p>Redirecting...Please Wait</p>
<form action="https://biz.traknpay.in/v2/paymentrequest" id="payment_form" method="POST">
<input type="hidden" value="<?php echo $hash; ?>"  name="hash"/>
<input type="hidden" value="<?php echo $_POST['api_key'];?>" name="api_key"/>
<input type="hidden" value="<?php echo $_POST['return_url']; ?>" name="return_url"/>
<input type="hidden" value="<?php echo $_POST['mode']; ?>" name="mode"/>
<input type="hidden" value="<?php echo $_POST['order_id']; ?>" name="order_id"/>
<input type="hidden" value="<?php echo $_POST['amount']; ?>" name="amount"/>
<input type="hidden" value="<?php echo $_POST['currency']; ?>" name="currency"/>
<input type="hidden" value="<?php echo $_POST['description']; ?>" name="description"/>
<input type="hidden" value="<?php echo $_POST['name']; ?>" name="name"/>
<input type="hidden" value="<?php echo $_POST['email']; ?>" name="email"/>
<input type="hidden" value="<?php echo $_POST['phone']; ?>" name="phone"/>
<input type="hidden" value="<?php echo $_POST['city']; ?>" name="city"/>
<input type="hidden" value="<?php echo $_POST['state']; ?>" name="state"/>
<input type="hidden" value="<?php echo $_POST['zip_code']; ?>" name="zip_code"/>
<input type="hidden" value="<?php echo $_POST['country']; ?>" name="country"/>
<input type="hidden" value="<?php echo $_POST['udf1']; ?>" name="udf1"/>
<input type="hidden" value="<?php echo $_POST['udf2']; ?>" name="udf2"/>
<input type="hidden" value="<?php echo $_POST['udf3']; ?>" name="udf3"/>
<input type="hidden" value="<?php echo $_POST['udf4']; ?>" name="udf4"/>
<input type="hidden" value="<?php echo $_POST['udf5']; ?>" name="udf5"/>
<noscript><input type="submit" value="Continue"/></noscript>
</form>
<script>
function formAutoSubmit () {
	var payform = document.getElementById("payment_form");
	payform.submit();
}
window.onload = formAutoSubmit;
</script>
