<?php

	include "funcs.php";

	$ip = $HTTP_SERVER_VARS["REMOTE_ADDR"];
	$iprange = trim(substr($ip,0,10));
	if ($iprange != "151.9.115.")
	{
		die();
	}

	$RetResult = $HTTP_POST_VARS['RESULT'];
	$RetIdTrans = $HTTP_POST_VARS['ID_TRANS'];
	$RetAuth = $HTTP_POST_VARS['AUTHORIZATIONCODE'];
	$RetAmount = $HTTP_POST_VARS['AMOUNT'];
	$RetShopTransactionId = $HTTP_POST_VARS['SHOPTRANSACTIONID'];
	$RetClientIP = $HTTP_POST_VARS['CLIENT_IP'];
	$RetTimeTrans = $HTTP_POST_VARS['TIME_TRANS'];
	$RetDateTrans = $HTTP_POST_VARS['DATE_TRANS'];
	$RetCardType = $HTTP_POST_VARS['CARDTYPE'];
	$RetParAgg = $HTTP_POST_VARS['PAR_AGG'];
	$RetRecurringId = $HTTP_POST_VARS['RECURRING_ID'];

	$validato = 1;


	if ($RetClientIP == "")
	{
		$validato = 0;
	}

	if ($validato == 1) {
		$RecurringDesc = "";
		if ($RetRecurringId > 0)
		{
			$RecurringDesc = "ricorrente ";
		}
		if ($RetResult == "0")
		{
			$ResultDescription = "Transazione $RecurringDesc"."SysPay autorizzata";
			AccettaPG($RetShopTransactionId,1,$RetAmount,$RetClientIP);
			
		} elseif ($RetResult == "1")
		{
			$ResultDescription = "Transazione $RecurringDesc"."SysPay NON autorizzata";
			RifiutaPG($RetShopTransactionId,1,$RetAmount,$RetClientIP);
		}
		$mail_to = "<<1-email_ordini>>";
		$mail_shop = "<<1-negozio>>";

		$sendmail_from = $mail_to;

		$sendmail_subject = $mail_shop  . " - " . $ResultDescription . " " . $RetShopTransactionId;
		$sendmail_replyto = $mail_to;

		$info = $ResultDescription . "\n\n";
		$info .= "Codice ordine: " . $RetShopTransactionId ."\n";
		$info .= "ID Transazione: " . $RetIdTrans ."\n";
		$info .= "ID Autorizzazione: " . $RetAuth ."\n";
		$info .= "Importo: " . $RetAmount ."\n";
		$info .= "IP Cliente: " . $RetClientIP ."\n\n";
		if ($RetRecurringId > 0)
		{
			$info .= "Pagamento ricorrente\n";
			$info .= "Recurring_ID: " . $RetRecurringId ."\n";
		}

		mail($mail_to, $sendmail_subject, $info, "From: " . $sendmail_from . "\r\n" . "Reply-To: " . $sendmail_replyto . "");

	}
		
?>

<HTML>
<BODY>
</BODY>
</HTML>