<?php
require_once 'modules/admin/models/PluginCallback.php';
require_once 'modules/billing/models/class.gateway.plugin.php';

class PluginMoneybookersCallback extends PluginCallback
{
    
    function processCallback()
    {
        // ignore get requests
        if (!isset($_POST['transaction_id']) && !isset($_POST['status'])) {
            return;
        }
        
        //Create plug in class to interact with CE
        $cPlugin = new Plugin($_POST['transaction_id'], 'moneybookers', $this->user);
        
        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($this->settings->get("plugin_moneybookers_Secret Word")))).$_POST['mb_amount'].$_POST['mb_currency'].$_POST['status'];
        $hash = strtoupper(trim(md5(trim($hash))));
        
        $cPlugin->m_TransactionID = $_POST['mb_transaction_id'];
        $cPlugin->m_Action = "charge";
        $cPlugin->m_Amount = (isset($_POST['amount']))? $_POST['amount'] : "0.0";
        
        if (strcasecmp(trim($_POST['md5sig']), $hash) == 0 && $_POST['status'] == 2) {
            $cPlugin->PaymentAccepted($_POST['amount'], $responsetext." MB Trans ID(".$_POST['mb_transaction_id'].")");
        } else {
            $cPlugin->PaymentRejected("Error: ".$responsetext." MB Trans ID(".$_POST['mb_transaction_id'].")");
        }
    }
    
}

?>
