<?php

include('VPCPaymentConnection.php');
$conn = new VPCPaymentConnection();


// This is secret for encoding the SHA256 hash
// This secret will vary from merchant to merchant

$secureSecret = "9C63FFB9F77C769AD0F6ACF4C0CABA8A";

// Set the Secure Hash Secret used by the VPC connection object
$conn->setSecureSecret($secureSecret);


// *******************************************
// START OF MAIN PROGRAM
// *******************************************
// Sort the POST data - it's important to get the ordering right
ksort ($_POST);

// add the start of the vpcURL querystring parameters
$vpcURL = $_POST["GTPayURL"];

// This is the title for display
//$title  = $_POST["Title"];


// Remove the Virtual Payment Client URL from the parameter hash as we 
// do not want to send these fields to the Virtual Payment Client.
unset($_POST["GTPayURL"]); 
unset($_POST["SubButL"]);

// Add VPC post data to the Digital Order
foreach($_POST as $key => $value) {
	if (strlen($value) > 0) {
		$conn->addDigitalOrderField($key, $value);
	}
}

$dt = new DateTime();
$dt->setTimeZone(new DateTimeZone('UTC'));
$dat = $dt->format('Y-m-d\TH-i-s\Z');

$conn->SetSecretVal("SHA256");

// Obtain a one-way hash of the Digital Order data and add this to the Digital Order
$secureHash = $conn->hashAllFields();

$conn->addDigitalOrderField("gtp_TransDate", $dat);
$conn->addDigitalOrderField("gtp_SecureHash", $secureHash);
$conn->addDigitalOrderField("gtp_SecureHashType", "SHA256");




// Obtain the redirection URL and redirect the web browser
$vpcURL = $conn->getDigitalOrder($vpcURL);


header("Location: ".$vpcURL);
//echo "<a href=$vpcURL>$vpcURL</a>";


?>
