<?php
/*
 * ##################################################################
 * Created on: Jul 28, 2005
 * File name:  paymate.php 
 * ##################################################################
 * This code is a sole property of netenberg.com 
 * ##################################################################
 */
$name       = "Paymate";
$paymate    = array (
            array ("ID"         , "mid"), 
            array ("Currency"   , "paymate_currency", "USD", "AUD"), 
            array ("Active"     , "active", "No", "Yes"), 
            array ("Title"      , "title")
            );
$send_method= "GET";
$pay        = new paymate($demo_mode);
/*
 * Class to do all paymate
 * paymate Version 1.0
 */
class paymate
{
	/*
	 * Constructor
	 */
	function paymate($demo_mode= 0)
	{
		$this->demo_mode  = $demo_mode;
		$this->pay_url    = "https://www.paymate.com.au/PayMate/ExpressPayment";
		if ($this->demo_mode)
        {
			$this->pay_url= "https://www.paymate.com.au/PayMate/TestExpressPayment";
        }
	}
	/*
	 * Function to send variables
	 */
	function sendVariables($path_url, $pp_vals)
	{
		$this->_POST1                 = array ();
		$this->_POST1['mid']          = $pp_vals['mid'];
		$this->_POST1['amt']          = number_format($_POST['gross_amount'],2);
		$this->_POST1['amt_editable'] = 'N';
		$this->_POST1['currency']     = $pp_vals['paymate_currency'];
		//switch demo mode
		if ($this->demo_mode)
        {
			$this->_POST1['mid'] = 'testuser';
        }
		$this->_POST1['item_number'] = time().rand(0, 1000);
		if (isset ($_POST['force_inv_no']))
        {
			$this->_POST1['item_number'] = $_POST['force_inv_no'];
        }
		$this->_POST1['ref']              = $this->_POST1['item_number'];
		$this->_POST1['pmt_sender_email'] = $_POST['email'];
		$array_name                       = array ();
		$array_name                       = explode(' ', $_POST['name'], 2);
		$this->_POST1['pmt_contact_firstname']    = $array_name[0];
		$this->_POST1['pmt_contact_surname']      = $array_name[1];
		$this->_POST1['pmt_contact_phone']        = $_POST['telephone'];
		$this->_POST1['pmt_country']              = $_POST['country'];
		$this->_POST1['regindi_address1']         = $_POST['address'];
		$this->_POST1['regindi_sub']              = $_POST['city'];
		$this->_POST1['state']                    = $_POST['state'];
		$this->_POST1['regindi_pcode']            = $_POST['zip'];
		$this->_POST1['return']                   = $path_url."/ipn.php";
		$this->_POST1['popup']                    = true;
	}
	/*
	 * IPN=Internet Payment Notifier
	 */
	function ipn(& $BL)
	{
		$this->item_number        = $_POST['ref'];
		$this->transaction_id     = $_POST['transactionID'];
        $this->payment_status     = $_POST['responseCode'];
		if (!empty ($this->item_number) && ($this->payment_status == "PA" || $this->payment_status == "PP") && strlen($this->transaction_id) == 11)
		{
			if ($this->payment_status == "PP")
            {
				$_POST['skip_auto_creation']= 1;
            }
			$BL->processTransaction($this->item_number, $this->transaction_id);
			return true;
		}
		return false;
	}
}
?>