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

$cPlugin = new Plugin($params["invoiceNumber"],"bluepay");

//create transaction code
if ($bluePay->getStatus()=="1") $responsetext = "This transaction has been approved";
elseif ($bluePay->getStatus()=="0") $responsetext = "This transaction has been declined";
elseif ($bluePay->getStatus()=="E") $responsetext = "There has been an error processing this transaction";
elseif ($bluePay->getStatus()=="") $responsetext = "Server Configuration Error";

if (($bluePay->getStatus() == "1" || $bluePay->getStatus() == "0") && $bluePay->getTransId()) {
    $transaction = $responsetext.". (BP Trans:".$bluePay->getTransId().")";
} else {
    $transaction = $responsetext.". BP Message: ".$bluePay->getMessage()." (BP Trans: 0)";
}
$transactioncode=$transaction;

//check to see if transaction was accepted
if ($bluePay->getStatus()=="1"){
	$cPlugin->m_Amount = $params['invoiceTotal'];
	$cPlugin->m_TransactionID = $bluePay->getTransId();
	$cPlugin->m_Action = "charge";
	$cPlugin->m_Last4 = substr($params["userCCNumber"],-4);
	$cPlugin->PaymentAccepted($params['invoiceTotal'],$transactioncode);
}else if(!$bolInSignup){
	//Only add transaction if we are NOT coming from signup
	$cPlugin->m_Amount = $params['invoiceTotal'];
	$cPlugin->m_TransactionID = $bluePay->getTransId();
	$cPlugin->m_Action = "charge";
	$cPlugin->m_Last4 = substr($params["userCCNumber"],-4);	
	$cPlugin->PaymentRejected($transactioncode);
}