<?php


function print_r2($val)
{
        echo '<pre>';
        print_r($val);
        echo  '</pre>';
}

session_start();
print_r2($_SESSION);echo "</br>";echo "</br>";
print_r2($_POST);
//$subpdtid = 6204; // collegpay your product ID
$subpdtid = 227088; // your product ID
$submittedamt = $_SESSION["amount"];
$submittedref = $_POST['txnref'];

        $nhash = "SzKp1l7UnqqBP7ADUULrwkFjTa2tjoQpZkMz48kkdRXqN6Pq5xl4gMgSMLw9CgYUCKIpXESX6IRC8m34l7vlZEXekPMPSUq7SC5tkt9owspOahJqeFI5XrsoP1SxJxV5" ; // the mac key sent to you
        //CP $nhash = "E187B1191265B18338B5DEBAF9F38FEC37B170FF582D4666DAB1F098304D5EE7F3BE15540461FE92F1D40332FDBBA34579034EE2AC78B1A1B8D9A321974025C4" ; // the mac key sent to you
        $hashv = $subpdtid.$submittedref.$nhash;  // concatenate the strings for hash again
		$thash = hash('sha512',$hashv); 

		$parami = array(
				"productid"=>$subpdtid,
				"transactionreference"=>$submittedref,
				"amount"=>$submittedamt
		);
		$ponmo = http_build_query($parami);

$url = "http://172.35.2.11/webpay/api/v1/gettransaction.json?$ponmo"; // json
//$url = "http://webpay.interswitchng.com/collections/api/v1/gettransaction.json?$ponmo"; // json
//$url = "http://sandbox.interswitchng.com/webpay/api/v1/gettransaction.json?$ponmo"; // json
//$url = "http://172.25.20.246/webpay/api/v1/gettransaction.json?$ponmo"; // json
//https://stageserv.interswitchng.com/test_paydirect/api/v1/gettransaction.json
//https://172.25.20.246/test_paydirect/api/v1/gettransaction.json
//stageserv.interswitchng.com stageserv.interswitchng.com note the variables appended to the url as get values for these parameters

$headers = array(
        "GET /HTTP/1.1",
        "Host: webpay.interswitchng.com",
        "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1",
        "Accept: */* ",
        //"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: " . $thash
    );        
print_r2($headers);
echo $url;

$ch = curl_init();  //INITIALIZE CURL///////////////////////////////
//               

curl_setopt($ch, CURLOPT_PROXY,'172.16.10.20:8080');


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_POST, false );
//
$data = curl_exec($ch);  //EXECUTE CURL STATEMENT///////////////////////////////
$json = null;



if (curl_errno($ch)) 
{ 
        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_r2($json);
	// loop through the array nicely for your UI
}

session_write_close();


?>
	</br></br></br><a href="http://172.35.2.12:8090/demopay4/">Home</a>
	</br></br></br><a href="http://172.35.2.12:8090/demopay4/requery.php">Requery</a>
  </body>
</html>
