<?php

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

class PluginMoneybookersCallback extends PluginCallback
{
    
    function processCallback()
    {
        //Create plug in class to interact with CE
        $cPlugin = new Plugin($_POST['transaction_id'], 'moneybookers', $this->user, $this->customer);
        
        if ($_POST['status'] == 2) {
            $responsetext = "This transaction has been approved.";
        } else {
            $responsetext = "This transaction has been declined.";
        }
        
        $hash = $_POST['merchant_id'].$_POST['transaction_id'].strtoupper(md5(trim($GLOBALS["gSettingsArray"]["plugin_moneybookers_Secret Word"]))).$_POST['mb_amount'].$_POST['mb_currency'].$_POST['status'];
        $hash = strtoupper(trim(md5(trim($hash))));
        
        if (strcasecmp(trim($_POST['md5sig']), $hash) == 0 && $_POST['status'] == 2) {
            $cPlugin->m_Amount = $_POST['amount'];
            $cPlugin->m_TransactionID = $_POST['mb_transaction_id'];
            $cPlugin->m_Action = "charge";
            $cPlugin->PaymentAccepted($_POST['amount'], $responsetext." MB Trans ID(".$_POST['mb_transaction_id'].")");
        } else {
            $cPlugin->PaymentRejected("Error: ".$responsetext." MB Trans ID(".$_POST['mb_transaction_id'].")");
        }
    }
    
}

?>
