<?php
/*
 * ##################################################################
 * Created on: Jul 28, 2005
 * File name:  chronopay.php 
 * ##################################################################
 * This code is a sole property of netenberg.com 
 * ##################################################################
 */
$name       = "ChronoPay";
$chronopay  = array (
                array ("Product Id"     , "chronopay_product_id"), 
                array ("Currency"       , "chronopay_currency", "USD"), 
                array ("Active"         , "active", "No", "Yes"), 
                array ("Title"          , "title")
                );
$send_method= "POST";
$pay        = new chronopay($demo_mode);
/*
 * Class to do all chronopay
 * chronopay Version 
 */
class chronopay
{
	/*
	 * Constructor
	 */
	function choronopay($demo_mode= 0)
	{
		$this->demo_mode  = $demo_mode;
		$this->pay_url    = "https://secure.chronopay.com/index_shop.cgi";
	}
	/*
	 * Function to send variables
	 */
	function sendVariables($path_url, $pp_vals)
	{
		$this->_POST1                             = array ();
		$this->_POST1['product_id']               = $pp_vals['chronopay_product_id'];
		$this->_POST1['product_price_currency']   = $pp_vals['chronopay_currency'];
		$this->_POST1['product_price']            = number_format($_POST['gross_amount'],2);
        $this->_POST1['product_name']             = $_POST['friendly_desc'];
        if(empty($this->_POST1['product_name']))
        {
            $this->_POST1['product_name'] = $_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['cb_url']       = $path_url."/ipn.php";
		$this->_POST1['decline_url']  = $path_url."/NOK.php";

        $this->_POST1['name']       = $_POST['name'];
		$this->_POST1['street']     = $_POST['address'];
		$this->_POST1['city']       = $_POST['city'];
		$this->_POST1['state']      = $_POST['state'];
		$this->_POST1['zip']        = $_POST['zip'];
        $this->_POST1['country']    = $_POST['country'];
        $this->_POST1['phone']      = $_POST['telephone'];
        $this->_POST1['email']      = $_POST['email'];
        
        $this->_POST1['cs1']        = $this->_POST1['item_number'];
        $this->_POST1['cs2']        = "Chronopay";
        $this->_POST1['cb_type']    = "P";

	}
	/*
	 * IPN=Internet Payment Notifier
	 */
	function ipn(& $BL)
	{
		$this->item_number    = $_POST['cs1'];
		$this->transaction_id = $_POST['transaction_id'];
		$this->payment_status = $_POST['transaction_type'];
		if (!empty ($this->item_number) && !empty ($this->transaction_id) && $_POST['cs2']=="Chronopay" && $BL->verifyAmount($this->item_number,$_POST['total']))
		{
			$BL->processTransaction($this->item_number, $this->transaction_id);
			return true;
		}
		return false;
	}
}
?>