<?php
/*****************************************************************************************************/
/*  CALL BACK CODE FROM 2CHECKOUT : This code needs to be called from your processor upon completion */
/*****************************************************************************************************/
define('INCLUDE_STEPS', 'pluginCallback');
require_once dirname(__FILE__) . '/../../../common/common.php';
require_once 'classes/class.gateway.plugin.php';

//Get vars from post/get
$lInvoiceID = $_REQUEST['ce_invoice_num'];
+$lInvoicePaid = $_REQUEST['x_2checked'];
$lSignUp = $_REQUEST['signup'];
$lErrorCode = "";
$lPricePaid = $_REQUEST['x_amount'];
$lOrderID = $_REQUEST['order_number'];


//Create plug in class to interact with CE
$cPlugin = new Plugin($lInvoiceID);


//Determine if payment was made & make sure that it was not made in demo mode
if (($lInvoicePaid == 'Y' || $lInvoicePaid == 'K') && $_REQUEST['demo'] != 'Y') {
	$transaction = " 2checkout Payment of $lPricePaid was accepted (OrderID:".$lOrderID.")";
	$cPlugin->PaymentAccepted($lPricePaid, $transaction);
} else {
		//if the payment was made in demo mode let's log it
		if($_REQUEST['demo']=='Y'){
			$transaction = " 2checkout Payment of $lPricePaid was accepted (OrderID:".$lOrderID.") (DEMO MODE)";
			$cPlugin->PaymentAccepted($lPricePaid, $transaction);
		}
		else {
			//if not in demo mode we will log the reason_response_code from 2co
			$lErrorCode = $_REQUEST['x_response_reason_code'];
			$transaction = "Payment rejected - Reason: ".$lErrorCode;
			$cPlugin->PaymentRejected($transaction);
		}
}

//Forward User needs to come after PaymentAccepted or PaymentRejected
$cPlugin->ForwardUser($lSignUp);
?>
