<?PHP
///// Internet Secure change 15/08/2004
if (isset($_REQUEST['Language'])) {
	unset ($_REQUEST['Language']);
}
///// Internet Secure change 15/08/2004

include "inc/var.php";
include "inc/connect.php";
include "inc/whm_functions.php";
include "inc/invoice_functions.php";

if (isset($c)) { $sid=$c; }
else
	{
	if (!$HTTP_POST_VARS) 
		{ 	
		list($sid, $dest_bit)=explode("|", $merchant_product_id);
		$other=true;
		}

	$buffer="";
	if(phpversion()<="4.0.6") { $_POST=$HTTP_POST_VARS; }
	while (@list($key, $value)=@each($_POST)) 
		{ 
		$buffer.=$key."=".$value."<br>";
		if (trim($key)=="custom") { $sid=$value; }
		else if (trim($key)=="cart_order_id") { $sid=$value; }
		else if (trim($key)=="cartId") { $sid=$value; }
		else if (trim($key)=="option1") { $sid=$value; }
///// Internet Secure change 15/08/2004
		else if (trim($key)=="xxxVar1") { $sid=$value; }
///// Internet Secure change 15/08/2004
		else if (trim($key)=="transStatus") { $transStatus=$value; }
		else if (trim($key)=="callbackPW") { $callbackPW=$value; }
		
		# transaction ID's
		if ($key=="txn_id") { $txn_id=$value; }
		else if ($key=="orderid") { $txn_id=$value; }
		else if ($key=="order_number") { $txn_id=$value; }
///// Internet Secure change 15/08/2004		
		else if ($key=="receiptnumber") { $txn_id=$value; }
///// Internet Secure change 15/08/2004
		}
	
	
	$read=fopen($below_public."/deletemeworldpay.txt", "w");
	$result = fwrite ($read, $buffer);
	fclose ($read);
	}

if (isset($transStatus)&&isset($callbackPW))
	{
	$query2="select ";
	$query2.="worldpay_callback ";
	$query2.="from ";
	$query2.="payment_process ";
	$query2.="where ";
	$query2.="pid='2'";

	$rs2=mysql_fetch_row(mysql_query($query2));

	$worldpay_callback=stripslashes(trim($rs2[0]));

	if ($transStatus!="Y") { die("Transaction was denied. This invoice was not paid successfully."); }
	else if (strcmp($callbackPW, $worldpay_callback)!=0) { die("Call back password was incorrect.  This invoice was not paid successfully."); } 
	}



$query0="select ";
$query0.="count(*) ";
$query0.="from ";
$query0.="invoice_session ";
$query0.="where sid='".addslashes(trim($sid))."'";

$rs0=mysql_fetch_row(mysql_query($query0));

$sid_count=$rs0[0];

if ($sid_count<=0) { header("Location: ".$http_web."/step_one.php"); exit; }
else if (!isset($sid)) { header("Location: ".$http_web."/step_one.php"); exit; }
else { $iid=d("576cb7f68040520768bf51c75f7f4c84", $sid); }

$query1="update ";
$query1.="invoice ";
$query1.="set ";
$query1.="`status`='1', ";
$query1.="date_paid='".time()."', ";
$query1.="txn_id='".addslashes(trim($txn_id))."' ";
$query1.="where iid='".addslashes(trim($iid))."'";

mysql_query($query1);

invoice_paid_successfully($iid, $currency, $currency_type, $email_admin);

mysql_close($dblink);

header("Location: ".$http_web."/invoice_service.php?c=".urlencode(e("576cb7f68040520768bf51c75f7f4c84", $iid)));
exit;
?>