<?php
/*
 * ##################################################################
 * Created on: Jul 28, 2005
 * File name:  epay.php 
 * ##################################################################
 * This code is a sole property of netenberg.com 
 * ##################################################################
 */
$name     = "Epay";
$epay = array (
                array ("Merchant ID"    , "epay_id"), 
                array ("Currency"       , "epay_currency", "USD", "EUR"), 
                array ("Active"         , "active", "No", "Yes"), 
                array ("Title"          , "title")
                );
$send_method = "POST";
$pay         = new epay($demo_mode);
/*
 * Class to do all epay
 * epay Version 1.0
 */
class epay
{
	/*
	 * Constructor
	 */
	function epay($demo_mode= 0)
	{
		$this->demo_mode = $demo_mode;
		$this->pay_url   = "http://www.epay.vg/";
	}
	/*
	 * Function to send variables
	 */
	function sendVariables($path_url, $pp_vals)
	{
		$this->_POST1 = array ();
		$this->_POST1['EPAY_MERCHANT_ID'] = $pp_vals['epay_id'];
        $this->_POST1['EPAY_CURRENCY']    = strtolower($pp_vals['epay_currency']);
        $this->_POST1['EPAY_AMOUNT']      = number_format($_POST['gross_amount'],2);
        $this->_POST1['EPAY_USER_MEMO']   = $_POST['desc'];

        $this->_POST1['item_number']= time().rand(0, 1000);
        if (isset ($_POST['force_inv_no']))
        {
            $this->_POST1['item_number'] = $_POST['force_inv_no'];
        }
        $this->_POST1['EPAY_ORDER_PARAMS'] = $this->_POST1['item_number'];

		$this->_POST1['notifyurl']  = $path_url."/ipn.php";
        $this->_POST1['successurl'] = $path_url."/OK.php";
        $this->_POST1['cancelurl']  = $path_url."/NOK.php";

		$this->_POST1['payment_method'] = "epay";
	}
	/*
	 * IPN=Internet Payment Notifier
	 */
	function ipn(& $BL)
	{
		$this->item_number    = $_POST['EPAY_ORDER_PARAMS'];
		$this->transaction_id = $_POST['batch'];
		$this->payment_status = $_POST['status'];
        
		if (!empty ($this->item_number) && isset($_POST['EPAY_ORDER_PARAMS']))
		{
            if($this->payment_status == 0)
            {
                $_POST['skip_auto_creation'] = 1;
            }
            $BL->processTransaction($this->item_number, $this->transaction_id);
			return true;
		}
		return false;
	}
}
?>