<?php
/*
 * ##################################################################
 * Created on: Jul 28, 2005
 * File name:  worldpay.php 
 * ##################################################################
 * This code is a sole property of netenberg.com 
 * ##################################################################
 */
$name       = "Worldpay";
$worldpay   = array (
                array ("WorldPay Installation ID", "wp_instId"), 
                array ("Currency", "wp_currency"), 
                array ("Active", "active", "No", "Yes"), 
                array ("Title", "title")
                );
$send_method= "POST";
$pay        = new worldpay($demo_mode);
/*
 * Class to do all worldpay
 * worldpay Version 1.0
 */
class worldpay
{
	/*
	 * Constructor
	 */
	function worldpay($demo_mode= 0)
	{
		$this->demo_mode  = $demo_mode;
		$this->pay_url    = "https://select.worldpay.com/wcc/purchase";
	}
	/*
	 * Function to send variables
	 */
	function sendVariables($path_url, $pp_vals)
	{
		$this->_POST1             = array ();
		$this->_POST1['instId']   = $pp_vals['wp_instId'];
		$this->_POST1['item_number'] = time().rand(0, 1000);
		if (isset ($_POST['force_inv_no']))
        {
			$this->_POST1['item_number'] = $_POST['force_inv_no'];
        }
		$this->_POST1['cartId']   = $this->_POST1['item_number'];
		$this->_POST1['amount']   = number_format($_POST['gross_amount'],2);
		$this->_POST1['currency'] = $pp_vals['wp_currency'];
		$this->_POST1['desc']     = $_POST['desc'];
		if ($this->demo_mode)
        {
			$this->_POST1['testMode'] = 100;
        }
		$this->_POST1['M_pp']     = "WorldPay";
		$this->_POST1['M_item_no']= $this->_POST1['item_number'];
		$this->_POST1['name']     = $_POST['name'];
		$this->_POST1['tel']      = $_POST['telephone'];
		$this->_POST1['address']  = $_POST['address'];
		$this->_POST1['city']     = $_POST['city'];
		$this->_POST1['state']    = $_POST['state'];
		$this->_POST1['postcode'] = $_POST['zip'];
		$this->_POST1['country']  = $_POST['country'];
		$this->_POST1['email']    = $_POST['email'];
	}
	/*
	 * IPN=Internet Payment Notifier
	 */
	function ipn(& $BL)
	{
		$this->item_number    = $_POST['M_item_no'];
		$this->transaction_id = $_POST['transId'];
		$this->payment_status = $_POST['transStatus'];
		if (!empty ($this->item_number) && $this->payment_status == "Y" && $_POST['M_pp'] == "WorldPay")
		{
			$BL->processTransaction($this->item_number, $this->transaction_id);
			return true;
		}
		return false;
	}
}
?>