<?php
/*****************************************************************************************************/
/*  CALL BACK CODE FROM WORLPAY : This code needs to be called from your processor upon completion */
/*****************************************************************************************************/
// $cPlugin->GetPluginVariable takes queries in the form of plugin_[pluginname]_[variable]

define('INCLUDE_STEPS', 'pluginCallback');
require_once dirname(__FILE__) . '/../../../common/common.php';
require_once 'classes/class.gateway.plugin.php';

//Get vars from post/get
$tInvoiceID = $_POST['cartId'];
$tTransStatus = $_POST['transStatus'];
$tTransID = $_POST['transId'];
$tCallBackPW = $_POST['callbackPW'];
$lPricePaid = $_POST['cost'];  //For Future Use
$testmode = "";
//Create plug in class to interact with CE
$cPlugin = new Plugin($tInvoiceID);

//Determine if payment was made
if ($tTransStatus=="Y"){
    if ($_POST['testMode'] == 100) {
        $testmode = "Test ";
    }
    $transaction = " Worldpay $testPayment of $lPricePaid Successful (Worldpay ID:".$tTransID.")";
	if (trim($tCallBackPW) != trim($cPlugin->GetPluginVariable("plugin_worldpay_Callback Password"))){
		exit;
		//might want to send a warning email in the future for security warning
		//	$cPlugin->PaymentRejected($lErrorCode);
	}else{
		$cPlugin->PaymentAccepted($lPricePaid,$transaction);
	}
}else{
    $transaction = " Worldpay $testPayment of $lPricePaid Failed (Worldpay ID:".$tTransID.")";
	$cPlugin->PaymentRejected($transaction);
}
?>