<?php
/*
 * ##################################################################
 * Created on: Jul 28, 2005
 * File name:  eway.php 
 * ##################################################################
 * This code is a sole property of netenberg.com 
 * ##################################################################
 */
$name    = "eWAY";
$eway = array (
            array ("Customer ID", "eway_CustomerID"), 
            array ("Site Title" , "eway_SiteTitle"),
            array ("Active"     , "active", "No", "Yes"), 
            array ("Title"      , "title")
            );
$send_method = "POST";
$pay         = new eway($demo_mode);
/*
 * Class to do all eway
 * eway Version 
 */
class eway
{
	/*
	 * Constructor
	 */
	function eway($demo_mode= 0)
	{
		$this->demo_mode = $demo_mode;
		$this->pay_url   = "https://www.eway.com.au/gateway/payment.asp";
	}
	/*
	 * Function to send variables
	 */
	function sendVariables($path_url, $pp_vals)
	{
		$this->_POST1 = array ();
		$this->_POST1['ewayCustomerID'] = $pp_vals['eway_CustomerID'];
        $this->_POST1['ewaySiteTitle'] = $pp_vals['eway_SiteTitle'];
		$this->_POST1['ewayTotalAmount'] = ($_POST['gross_amount']*100);
        $this->_POST1['item_name'] = $_POST['friendly_desc'];
        if(empty($this->_POST1['item_name']))
        {
            $this->_POST1['item_name'] = $_POST['desc'];
        }
        $this->_POST1['ewayCustomerInvoiceDescription'] = $this->_POST1['item_name'];

		$this->_POST1['item_number'] = time().rand(0, 1000);
		if (isset ($_POST['force_inv_no']))
        {
			$this->_POST1['item_number'] = $_POST['force_inv_no'];
        }
        $this->_POST1['ewayCustomerInvoiceRef'] = $this->_POST1['item_number'];
        $this->_POST1['ewayTrxnNumber'] = $this->_POST1['item_number'];
            
		$this->_POST1['ewayURL'] = $path_url."/ipn.php";        
		$this->_POST1['ewayAutoRedirect']= 1;
        $this->_POST1['btnProcessPayment']= "Process Payment";

		$array_name = array ();
		$array_name = explode(' ', $_POST['name'], 2);
		$this->_POST1['ewayCustomerFirstName']= $array_name[0];
		$this->_POST1['ewayCustomerLastName'] = $array_name[1];
        $this->_POST1['ewayCustomerEmail'] = $_POST['email'];
		$this->_POST1['ewayCustomerAddress']  = $_POST['address'].", ".$_POST['city'].", ".$_POST['state'].", ".$_POST['country'];
		$this->_POST1['ewayCustomerPostcode'] = $_POST['zip'];      
	}
	/*
	 * IPN=Internet Payment Notifier
	 */
	function ipn(& $BL)
	{
		$this->item_number    = $_POST['ewayTrxnNumber'];
		$this->transaction_id = $_POST['ewayTrxnReference'];
		$this->payment_status = $_POST['ewayTrxnStatus'];
		if (!empty ($this->item_number) && !empty ($this->transaction_id) && $this->payment_status=="True")
		{
			$BL->processTransaction($this->item_number, $this->transaction_id);
			return true;
		}
		return false;
	}
}
?>