<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

//Start Session
include_once($_SERVER['DOCUMENT_ROOT'] . '/student_portal/acceptance_pay/includes/startSecureSession.php');
include_once($_SERVER['DOCUMENT_ROOT'] . '/student_portal/acceptance_pay/includes/paymentParameters.php');
include_once($_SERVER['DOCUMENT_ROOT'] . '/student_portal/acceptance_pay/database/includes/databaseFunctions.php');

sec_session_start();

include_once($_SERVER['DOCUMENT_ROOT'] . '/student_portal/acceptance_pay/includes/print_R2.php');
include_once($_SERVER['DOCUMENT_ROOT'] . '/student_portal/acceptance_pay/includes/functions.php');

print_R2($_SESSION);
echo "<br/>";

$submittedProductId = $product_id;
$submittedTransactionReference = $_POST['txn_ref'];
$submittedAmount = $_SESSION['amount'];
$macKey = $macKey;

$requeryURL = getRequeryURL($submittedProductId, $submittedTransactionReference, $submittedAmount);

echo "<br/>";
echo "GET TRANSACTION URL";
echo "<br/>";
echo $requeryURL;
echo "<br/>";

$securityHash = getHashValue($submittedProductId . $submittedTransactionReference . $macKey);

$getRequestHeaders = 
        array(
            "GET /HTTP/1.1",
            "Host: stageserv.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: */* ",
            "Accept-Language: en-us,en;q=0.5",
            "Keep-Alive: 300",
            "Connection: keep-alive",
            "Hash: " . $securityHash
        );      


$ch = curl_init();  //INITIALIZE CURL///////////////////////////////
//               
curl_setopt($ch, CURLOPT_URL, $requeryURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $getRequestHeaders);
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)) 
{ 
        print "Error: " . curl_error($ch) . "</br></br>";

        $errno = curl_errno($ch);
        $error_message = curl_strerror($errno);
        print $error_message . "</br></br>";;

        print_R2($headers);

}
else 
{  
    // Show me the result
    $json = json_decode($data, TRUE);

    curl_close($ch);    //END CURL SESSION///////////////////////////////
    
    echo '<br/>';echo '<br/>';
    echo 'TRANSACTION SUMMARY';echo '<br/>';echo '----------------------------------------------------------';echo '<br/>';
    if($json["ResponseCode"] != '00')
    {
        echo 'YOUR TRANSACTION FAILED. FIND BELOW TRANSACTION DETAILS.';        echo '<br/>';
        echo "Response Code: ".$json["ResponseCode"]."</br>";                  
        echo "Response Description: ".$json["ResponseDescription"]."</br>";    
        echo "Transaction Reference: " . $_POST['txnref'];          echo '<br/>';
    }
    else
    {
        echo 'YOUR TRANSACTION WAS SUCCESSFUl. FIND BELOW TRANSACTION DETAILS.';            echo '<br/>';
        echo "Response Code: ".$json["ResponseCode"]."</br>";                   
        echo "Response Description: ".$json["ResponseDescription"]."</br>";     
        echo "Payment Reference: ".$json["PaymentReference"]."</br>";
        echo "Transaction Reference: " . $_POST['txnref'];          echo '<br/>';
    }
    echo '----------------------------------------------------------';
    
    print_R2($json);
    // loop through the array nicely for your UI

    updateData($submittedTransactionReference, $json["ResponseCode"], $json["ResponseDescription"]);
}
?>
<head>
    <meta charset="UTF-8">
    <title>COLLEGEPAY DEMO APP</title>
</head>
<a href="/student_portal/acceptance_pay/">HOME</a>
<a href="/student_portal/acceptance_pay/requery.php">Requery</a>
<a href="/student_portal/acceptance_pay/database/viewLogs.php">VIEW TXN LOGS</a>
<br/><br/>
    <img src="images/isw_logo_new_combined.png" title="INTERSWITCH_LOGO" alt="INTERSWITCH LOGO" />
