<?php
/*
 * ##################################################################
 * Created on: Jul 28, 2005
 * File name:  cashu.php 
 * ##################################################################
 * This code is a sole property of netenberg.com 
 * ##################################################################
 */
$name   = "cashu";
$cashu  = array (
            array ("Merchant ID"    , "cu_merchant_id"), 
            array ("Currency"       , "cu_currency", "USD", "CSH"), 
            array ("Encryption Key" , "cu_enkey"), 
            array ("Active"         , "active", "No", "Yes"), 
            array ("Title"          , "title")
            );
$send_method    = "POST";
$pay            = new cashu($demo_mode);
/*
 * Class to do all cashu
 * cashu Version 1.0
 */
class cashu
{
	/*
	 * Constructor
	 */
	function cashu($demo_mode= 0)
	{
		$this->demo_mode  = $demo_mode;
		$this->pay_url    = "https://www.cashu.com/cgi-bin/pcashu.cgi";
	}
	/*
	 * Function to send variables
	 */
	function sendVariables($path_url, $pp_vals)
	{
		$this->cu_merchant_id         = $pp_vals['cu_merchant_id'];
		$this->_POST1                 = array ();
		$this->_POST1['item_number']  = time().rand(0, 1000);
		if (isset ($_POST['force_inv_no']))
        {
			$this->_POST1['item_number'] = $_POST['force_inv_no'];
        }
		$this->_POST1['merchant_id']  = $this->cu_merchant_id;
		$this->_POST1['session_id']   = session_id();
		$this->_POST1['amount']       = number_format($_POST['gross_amount'],2);
		// $token will have the MD5 digest value of the string.
		$str                          = strtolower($this->cu_merchant_id.":".number_format($_POST['gross_amount'],2).":".$pp_vals['cu_currency'].":".$pp_vals['cu_enkey']);
		$token                        = md5($str);
		$this->_POST1['token']        = $token;
		$this->_POST1['display_text'] = $_POST['desc']."-".$this->_POST1['item_number'];
		$this->_POST1['currency']     = $pp_vals['cu_currency'];
		$this->_POST1['language']     = "en";
		$this->_POST1['txt1']         = $_POST['desc']."-".$this->_POST1['item_number'];
		$this->_POST1['txt2']         = $this->_POST1['item_number'];
		$this->_POST1['txt3']         = "CASHU";
		//switch demo mode
		if ($this->demo_mode)
        {
			$this->_POST1['test_mode']= "1";
        }
	}
	/*
	 * IPN=Internet Payment Notifier
	 */
	function ipn(& $BL)
	{
		$this->item_number    = $_POST['txt2'];
		$this->transaction_id = $_POST['txt2'];
        $this->payment_status ="OK";
		if ($_POST['txt3'] == "CASHU" && !empty ($this->item_number) && !empty ($this->transaction_id))
		{
			$BL->processTransaction($this->item_number, $this->transaction_id);
			return true;
		}
		return false;
	}
}
?>