<?php
/*****************************************************************************************************/
/*  CALL BACK CODE FROM CHRONOPAY : This code needs to be called from your processor upon completion */
/* 									This is the Server ipn call.  									 */
/* 									The users are redirected via callback.php						 */
/*****************************************************************************************************/
define('INCLUDE_STEPS', 'pluginCallback');
require_once dirname(__FILE__) . '/../../../common/common.php';
require_once 'classes/class.gateway.plugin.php';

//Get vars from post/get
$lTransType 	= trim( stripslashes($_POST['transaction_type']) );
$lTransId 		= trim( stripslashes($_POST['transaction_id']) );
$lCustId 		= trim( stripslashes($_POST['customer_id']) );
$lSiteId 		= trim( stripslashes($_POST['site_id']) );
$iProductId 	= trim( stripslashes($_POST['product_id']) );
$lTransDate 	= trim( stripslashes($_POST['date']) );
$lTransTime 	= trim( stripslashes($_POST['time']) );
$lTransName 	= trim( stripslashes($_POST['name']) );
$lTransEmail 	= trim( stripslashes($_POST['email']) );
$lTotal		 	= trim( stripslashes($_POST['total']) );
$lInvoiceID		= trim( stripslashes($_POST['cs1']) );
$lSignUp		= trim( stripslashes($_POST['cs2']) );
$lThing 		= trim( stripslashes($_POST['cs3']) );
$lPricePaid		= trim( stripslashes($_POST['total']) );



$GLOBALS['logger']->log(5, 'ChronoPay callback invoked');
$str = "Request from: ".$_SERVER['REMOTE_ADDR']."\n";
$str .= "POST Vars: \n";
foreach( $_POST as $k=>$v )
	$str .= "   $k => $v \n";
$GLOBALS['logger']->log(5, $str);

$cPlugin = new Plugin($lInvoiceID);

$transLog = '<br/>Transaction ID: '.$lTransId."<br/>".
				'Customer ID: '.$lCustId."<br/>".
				'Customer Email: '.$lTransEmail."<br/>".
				'Chronopay Date: '.$lTransDate."<br/>".
				'Chronopay Time: '.$lTransTime;		

//Determine if payment was made
if( $lTransType=='onetime' || $lTransType=='initial' || $lTransType=='rebill' ) 
{
	$transaction = " ChronoPay Payment of $lPricePaid was accepted \n".$transLog;
	$cPlugin->m_TransactionID = $lTransId;
	$cPlugin->PaymentAccepted($lPricePaid, $transaction);
} 
else 
{
	//transaction failed
	$transaction = "ChronoPay Payment rejected\n ".$transLog;
	$cPlugin->PaymentRejected($transaction);
}

//$GLOBALS['logger']->log(5, var_export($cPlugin, true) );


?>