<?php
	include_once($_SERVER['DOCUMENT_ROOT'] . '/student_portal/acceptance_pay/includes/paymentParameters.php');
	
	//Form
	echo  '<form action="" method="post">';
	echo  	'Transaction Reference:<input type="text" name="txn_ref"/></br></br>';
	echo  '<input type="submit" name="submit"/>';
	echo  '</form>';
	//HTML Form
	
	if(!empty($_POST['submit'])) 
	{
		$submittedref = $_POST["txn_ref"];	//submitted transaction reference (eg 250OID100000164)
		
		//Calculate HASH
                $hash = getHashValue($product_id . $submittedref . $macKey); 	//hash to be passed in header
		
                $payAmount = getAmountFromDB($submittedref);
                echo $payAmount;
                
		$url = getRequeryURL($product_id, $submittedref, $payAmount); // json
                
                echo '<br/>';echo '<br/>';
                echo 'REQUEST URL:-';               echo '<br/>';
		echo $url;                          echo '<br/>';
                echo 'REQUEST HEADER';              echo '<br/>';
                echo '--Hash = ' . $hash;
                echo '<br/>';echo '<br/>';

		//header details. Put hash here
		$headers = array(
						"GET /HTTP/1.1",
						"Host: 172.25.20.246",
						"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1",
						//"Content-type:  multipart/form-data",
						//"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 
						"Accept-Language: en-us,en;q=0.5",
						//"Accept-Encoding: gzip,deflate",
						//"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7",
						"Keep-Alive: 300",
						"Connection: keep-alive",
						"Hash: $hash"	//hash value
                    );        
	   //print_r2($headers);
		$ch = curl_init();  //INITIALIZE CURL///////////////////////////////
//               
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 
		curl_setopt($ch, CURLOPT_POST, false );
//
		$data = curl_exec($ch);  //EXECUTE CURL STATEMENT///////////////////////////////
		$json = null;
		if (curl_errno($ch)) 
		{ 
                    echo 'REQUEST FAILED: THERE WAS AN ERROR' . '<br/>';
			print "Error: " . curl_error($ch) . "</br></br>";
			
			$errno = curl_errno($ch);
			$error_message = curl_strerror($errno);
			print $error_message . "</br></br>";;
			
			print_r($headers);
		}
		else 
		{  
			// Show me the result
			$json = json_decode($data, TRUE);
				   
			curl_close($ch);    //END CURL SESSION///////////////////////////////
			
			//print_r(array_values($json));
			
			// Display Array Elements///////////////
			echo "Transaction Amount: ".$json["Amount"]."</br>";
			echo "Card Number: ".$json["CardNumber"]."</br>";
			echo "Transaction Reference: ".$json["MerchantReference"]."</br>";
			echo "Payment Reference: ".$json["PaymentReference"]."</br>";
			echo "Retrieval Reference Number: ".$json["RetrievalReferenceNumber"]."</br>";
			echo "Lead Bank CBN Code:".$json["LeadBankCbnCode"]."</br>";
			//echo "Lead Bank Name: ".$json["LeadBankName"]."</br>";
			//echo "Split Accounts: ".$json["SplitAccounts"]."</br>";
			echo "Transaction Date: ".$json["TransactionDate"]."</br>";
			echo "Response Code: ".$json["ResponseCode"]."</br>";
			echo "Response Description: ".$json["ResponseDescription"]."</br>";	
			// //////Display Array Elements////////////
                        
                        updateData($submittedTransactionReference, $json["ResponseCode"], $json["ResponseDescription"]);

		}
                
		session_write_close();
	}
	else               
	{
		// Display the Form and the Submit Button
		echo "NO POST DATA";
	}	
?>
<head>
<meta charset="UTF-8">
<title>COLLEGEPAY DEMO APP</title>
</head>
</br></br></br><a href="http://localhost/CollegePayX/">Home  </a>
<a href="http://localhost/CollegePayX/database/viewLogs.php">VIEW TXN LOGS</a>
