<?php

require_once 'modules/billing/models/class.gateway.plugin.php';

$cPlugin = new Plugin($params["invoiceNumber"],"psigate", $this->user, $this->customer);

//create transaction code
if ($psi->getTrxnApproved()=="APPROVED") $responsetext = "This $transType has been approved";
elseif ($psi->getTrxnApproved()=="DECLINED") $responsetext = "This $transType has been declined";
else $responsetext = "There has been an error processing this $transType";

if (($psi->getTrxnApproved()=="APPROVED" || $psi->getTrxnApproved()=="DECLINED")) {
    $transaction = $responsetext.". ".$psi->getErrorMessage()." - (PSI Trans:".$psi->getTrxnTransRefNumber().")";
} else {
    $transaction = $responsetext.". PSI Message: ".$psi->getErrorMessage()." (PSI Trans: 0)";
}
$transactioncode=$transaction;

//check to see if transaction was accepted
if ($psi->getTrxnApproved()=="APPROVED"){
    $cPlugin->m_Amount = $params['invoiceTotal'];
    $cPlugin->m_TransactionID = $psi->getTrxnTransRefNumber();
    $cPlugin->m_Action = $transType;
    $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 = $psi->getTrxnTransRefNumber();
    $cPlugin->m_Action = $transType;
    $cPlugin->m_Last4 = substr($params["userCCNumber"],-4); 
    $cPlugin->PaymentRejected($transactioncode);
}
