<?php
  function safe_b64encode($string) {
        $data = base64_encode($string);
        $data = str_replace(array('+','/','='),array('-','_',''),$data);
        return $data;
    }
  function encode($value){
        if(!$value){return false;}
        $text = $value;
        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
        $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, "DEAL_SYSTEM", $text, MCRYPT_MODE_ECB, $iv);
        return trim(safe_b64encode($crypttext));
    }
$errorExists = false;
$errorTxt = "";
$orderIDEncoded=encode($_GET["id"]);
$parentDir = dirname($_SERVER['REQUEST_URI']);


if($_GET['vpc_TxnResponseCode'] == '0' || $_GET['vpc_Message']=="Approved")
{
    $paymentResponse=$_GET["vpc_Message"];
    //$Loc="https://www.alatoolmuscat.com/new/cart/migspay/";
	if($_GET["type"]=="coupon")
	{
		$Loc="https://" . $_SERVER["HTTP_HOST"].$parentDir."/giftcoupon/migs/";
	}
	else
	{
		$Loc="https://" . $_SERVER["HTTP_HOST"].$parentDir."/cart/expresscheckout/source/Migs/";
		
	}
    $Loc=$Loc.'id/'.$orderIDEncoded;
	if($_GET['Title'])
    $Loc=$Loc.'/Title/'.$_GET['Title'];
	
	if($_GET['vpc_TxnResponseCode'])
    $Loc=$Loc.'/vpc_TxnResponseCode/'.$_GET['vpc_TxnResponseCode'];
	
	if($_GET['vpc_AVSRequestCode'])
    $Loc=$Loc.'/vpc_AVSRequestCode/'.$_GET['vpc_AVSRequestCode'];
	
	if($_GET['vpc_AVSResultCode'])
	$Loc=$Loc.'/vpc_AVSResultCode/'.$_GET['vpc_AVSResultCode'];
	
	if($_GET['vpc_AcqAVSRespCode'])
	$Loc=$Loc.'/vpc_AcqAVSRespCode/'.$_GET['vpc_AcqAVSRespCode'];
	
	if($_GET['vpc_AcqCSCRespCode'])
	$Loc=$Loc.'/vpc_AcqCSCRespCode/'.$_GET['vpc_AcqCSCRespCode'];
	
	if($_GET['vpc_AcqResponseCode'])
	$Loc=$Loc.'/vpc_AcqResponseCode/'.$_GET['vpc_AcqResponseCode'];
	
	if($_GET['vpc_Amount'])
	$Loc=$Loc.'/vpc_Amount/'.$_GET['vpc_Amount'];
	
	if($_GET['vpc_AuthorizeId'])
	$Loc=$Loc.'/vpc_AuthorizeId/'.$_GET['vpc_AuthorizeId'];
	
	if($_GET['vpc_BatchNo'])
	$Loc=$Loc.'/vpc_BatchNo/'.$_GET['vpc_BatchNo'];
	
	if($_GET['vpc_CSCResultCode'])
	$Loc=$Loc.'/vpc_CSCResultCode/'.$_GET['vpc_CSCResultCode'];
	
	if($_GET['vpc_Card'])
	$Loc=$Loc.'/vpc_Card/'.$_GET['vpc_Card'];
	
	if($_GET['vpc_CardNum'])
	$Loc=$Loc.'/vpc_CardNum/'.$_GET['vpc_CardNum'];
	
	if($_GET['vpc_CSCResultCode'])
	$Loc=$Loc.'/vpc_CSCResultCode/'.$_GET['vpc_CSCResultCode'];
	
	if($_GET['vpc_Command'])
	$Loc=$Loc.'/vpc_Command/'.$_GET['vpc_Command'];
	
	if($_GET['vpc_Locale'])
	$Loc=$Loc.'/vpc_Locale/'.$_GET['vpc_Locale'];
	
	if($_GET['vpc_MerchTxnRef'])
	$Loc=$Loc.'/vpc_MerchTxnRef/'.$_GET['vpc_MerchTxnRef'];
	
	if($_GET['vpc_Merchant'])
	$Loc=$Loc.'/vpc_Merchant/'.$_GET['vpc_Merchant'];
	
	if($_GET['vpc_Message'])
	$Loc=$Loc.'/vpc_Message/'.$_GET['vpc_Message'];
	
	if($_GET['vpc_OrderInfo'])
	$Loc=$Loc.'/vpc_OrderInfo/'.urlencode($_GET['vpc_OrderInfo']);
	
	if($_GET['vpc_ReceiptNo'])
	$Loc=$Loc.'/vpc_ReceiptNo/'.$_GET['vpc_ReceiptNo'];
	
	if($_GET['vpc_RiskOverallResult'])
	$Loc=$Loc.'/vpc_RiskOverallResult/'.$_GET['vpc_RiskOverallResult'];
	
	
	if($_GET['vpc_SecureHash'])
	$Loc=$Loc.'/vpc_SecureHash/'.$_GET['vpc_SecureHash'];
	
	if($_GET['vpc_TransactionNo'])
	$Loc=$Loc.'/vpc_TransactionNo/'.$_GET['vpc_TransactionNo'];
	
	if($_GET['vpc_TxnResponseCode'])
	$Loc=$Loc.'/vpc_TxnResponseCode/'.$_GET['vpc_TxnResponseCode'];
	
	if($_GET['vpc_VerSecurityLevel'])
	$Loc=$Loc.'/vpc_VerSecurityLevel/'.$_GET['vpc_VerSecurityLevel'];
	
	if($_GET['vpc_VerStatus'])
	$Loc=$Loc.'/vpc_VerStatus/'.$_GET['vpc_VerStatus'];
	
	if($_GET['vpc_VerType'])
	$Loc=$Loc.'/vpc_VerType/'.$_GET['vpc_VerType'];
	
	if($_GET['vpc_Version'])
	$Loc=$Loc.'/vpc_Version/'.$_GET['vpc_Version'];
	
	if($_GET['L_SHORTMESSAGE0'])
	$Loc=$Loc.'/L_SHORTMESSAGE0/'.urlencode($_GET['L_SHORTMESSAGE0']);
	
	if($_GET['L_LONGMESSAGE0'])
	$Loc=$Loc.'/L_LONGMESSAGE0/'.urlencode($_GET['L_LONGMESSAGE0']);
	
	
    $Loc=$Loc.'/loc/'.$locRes;
    header("Location:$Loc");
}
else
{
     //$Loc="https://www.alatoolmuscat.com/new/cart/unlock/";
	 if($_GET["type"]=="coupon")
	{
		$Loc="https://" . $_SERVER["HTTP_HOST"].$parentDir."/giftcoupon/unlock/";
	}
	else
	{
	 	$Loc="https://" . $_SERVER["HTTP_HOST"].$parentDir."/cart/unlock/";
	}
	 $Loc=$Loc.'id/'.$orderIDEncoded;
     $Loc=$Loc.'/tno/'.$_GET['vpc_TransactionNo'];
    $Loc=$Loc.'/code/'.$_GET['vpc_TxnResponseCode'];
    $Loc=$Loc.'/message/'.$_GET['vpc_Message'];
    header("Location:$Loc");
}
exit();
?>