<?php

require_once 'classes/PluginCallback.php';
require_once 'modules/billing/models/class.gateway.plugin.php';
require_once 'plugins/gateways/protxform/functions.php';

class PluginProtxformCallback extends PluginCallback
{
    
    function processCallback()
    {
        if (isset($_GET['fail']) && $_GET['fail'] == 1) {
            // Failed payment
            
            $cPlugin = new Plugin("0", 'protxform', $this->user, $this->customer);
            $Decrypt_Password = $cPlugin->GetPluginVariable("plugin_protxform_Crypt Password");
            
            $Decoded = SimpleXor(base64Decode($crypt),$Decrypt_Password);
            $values = getToken($Decoded);
            
            $lInvoiceID = $values['VendorTxCode'];
            $lInvoiceID = substr($lInvoiceID, 0, strpos($lInvoiceID, "D"));
            $lErrorCode = "";  //For Future Use
            $lPricePaid = "";  //For Future Use
            
            $cPlugin = new Plugin($lInvoiceID, 'protxform', $this->user, $this->customer);
            $cPlugin->PaymentRejected($lErrorCode);
            $cPlugin->ForwardUser();
            
        } else {
            // Passed payment

            $crypt = $_REQUEST['crypt'];
            
            $cPlugin = new Plugin("0", 'protxform', $this->user, $this->customer);
            $Decrypt_Password = $cPlugin->GetPluginVariable("plugin_protxform_Crypt Password");
            
            $Decoded=SimpleXor(base64Decode($crypt),$Decrypt_Password);
            $values = getToken($Decoded);
            
            $lInvoiceID = $values['VendorTxCode'];
            $lInvoiceID = substr($lInvoiceID, 0, strpos($lInvoiceID, "D"));
            $lErrorCode = "";  //For Future Use
            $lPricePaid = "";  //For Future Use
            
            $cPlugin = new Plugin($lInvoiceID, 'protxform', $this->user, $this->customer);
            $cPlugin->PaymentAccepted($lPricePaid);
            
            //users coming from protx need to be redirected to invoicing
            $cPlugin->ForwardUser();
        }
    }
    
}

?>
