<?php include('Crypto.php')?>
<?php
$ra=rand(10,1000000000);
 include('link/databaseconnection.php');
	    $date=date("Y-m-d");
        date_default_timezone_set("asia/kolkata");
        $time=date("h:i:sa");
	error_reporting(0);
	
		$workingKey='D2CDE288674EA1C8003BDDA97ACE0169';		//Working Key should be provided here.
	$encResponse=$_POST["encResp"];			//This is the response sent by the CCAvenue Server
	$rcvdString=decrypt($encResponse,$workingKey);		//Crypto Decryption used as per the specified working key.
	$order_status="";
	$decryptValues=explode('&', $rcvdString);
	$dataSize=sizeof($decryptValues);
	

	for($i = 0; $i < $dataSize; $i++) 
	{
		$information=explode('=',$decryptValues[$i]);
		if($i==3)	
			$order_status=$information[1];
	}
	$order_id='';$tracking_id='';$bank_ref_no='';
	$order_status='';$failure_message='';$payment_mode='';
	$card_name='';$status_code='';$status_message='';
	$currency='';$amount='';$billing_name='';
	$billing_address='';$billing_city='';$billing_state='';
	$billing_zip='';$billing_country='';$billing_tel='';
	$billing_email='';
	for($i = 0; $i < $dataSize; $i++) 
	{
			$information=explode('=',$decryptValues[$i]);
			if($i==0)	$order_id=$information[1];
			if($i==1)	$tracking_id=$information[1];
			if($i==2)	$bank_ref_no=$information[1];
			if($i==3)	$order_status=$information[1];
			if($i==4)	$failure_message=$information[1];
			if($i==5)	$payment_mode=$information[1];
			if($i==6)	$card_name=$information[1];
			if($i==7)	$status_code=$information[1];
			if($i==8)	$status_message=$information[1];
			if($i==9)	$currency=$information[1];
			if($i==10)	$amount=$information[1];
			if($i==11)	$billing_name=$information[1];
			if($i==12)	$billing_address=$information[1];
			if($i==13)	$billing_city=$information[1];
			if($i==14)	$billing_state=$information[1];
			if($i==15)	$billing_zip=$information[1];
			if($i==16)	$billing_country=$information[1];
			if($i==17)	$billing_tel=$information[1];
			if($i==18)	$billing_email=$information[1];
			
	}

	$sel="select * from payment_fees where order_id='$order_id' order by id desc";
	$res=mysqli_query($conn,$sel);
	if($row=mysqli_fetch_array($res,MYSQLI_BOTH))
	{
		$mob=$row['billing_tel'];
		$am=$row['amount'];
		$session=$row['session'];
		$id=$row['form_id'];
		$up="update payment_fees set tracking_id='$tracking_id',bank_ref_no='$bank_ref_no',order_status='$order_status',payment_mode='$payment_mode',card_name='$card_name',status_code='$status_code' ,status_message='$status_message',currency='$currency',amount='$amount',date='$date',time='$time' where order_id='$order_id'";
		if(mysqli_query($conn,$up))
		{
			if($order_status=='Success')
			{
				
					
	            	echo "<script>alert('Your  Fees Successfully Paid');window.location.href='slip.php?flag=$order_id';</script>";
                	
                	
			}
			else
				{
			echo "<script>alert('Your  Fees Failed/Cancel .');window.location.href='slip.php?flag=$order_id';</script>";
                	
		}
			
		}
	}
	else
	{
		$up="update payment_fees set tracking_id='$tracking_id',bank_ref_no='$bank_ref_no',order_status='$order_status',payment_mode='$payment_mode',card_name='$card_name',status_code='$status_code' ,status_message='$status_message',currency='$currency',amount='$amount',date='$date',time='$time' where order_id='$order_id'";
		if(mysqli_query($conn,$up))
		{
			echo "<script>alert('Your Registration Fees  Failed Please Try Again');window.location.href='adm_process.php';</script>";
		}
	}
	


	

	
		
	
?>
