<?php
/*
 * ##################################################################
 * Created on: Jul 28, 2005
 * File name:  stormpay.php 
 * ##################################################################
 * This code is a sole property of netenberg.com 
 * ##################################################################
 */
$name       = "Stormpay";
$stormpay   = array (
                array ("Stormpay email" , "payee_email"), 
                array ("Secret Code"    , "sp_secret_code"),
                array ("Active"         , "active", "No", "Yes"), 
                array ("Title"          , "title")
                );
$send_method= "POST";
$pay        = new stormpay($demo_mode);
/*
 * Class to do all stormpay
 * stormpay Version 1.0
 */
class stormpay
{
	/*
	 * Constructor
	 */
	function stormpay($demo_mode= 0)
	{
		$this->demo_mode  = $demo_mode;
		$this->pay_url    = "https://www.stormpay.com/stormpay/handle_gen.php";
	}
	/*
	 * Function to send variables
	 */
	function sendVariables($path_url, $pp_vals)
	{
		$this->_POST1                 = array ();
		$this->_POST1['payee_email']  = $pp_vals['payee_email'];
		$this->_POST1['amount']       = number_format($_POST['gross_amount'],2);
		$this->_POST1['generic']      = 1;
		$this->_POST1['product_name'] = $_POST['desc'];
		$this->_POST1['require_IPN']  = 1;
		$this->_POST1['notify_URL']   = $path_url."/ipn.php";
        $this->_POST1['return_URL']   = $path_url."/OK.php";
        $this->_POST1['cancel_URL']   = $path_url."/NOK.php";
		//switch demo mode
		if ($this->demo_mode)
        {
			$this->_POST1['test_mode']= 1;
        }
		$this->_POST1['item_number']  = time().rand(0, 1000);
		if (isset ($_POST['force_inv_no']))
        {
			$this->_POST1['item_number']= $_POST['force_inv_no'];
        }
		$this->_POST1['transaction_ref']= $this->_POST1['item_number'];
		$this->_POST1['user1']        = $this->_POST1['item_number'];
		$this->_POST1['user2']        = 'strompay';
	}
	/*
	 * IPN=Internet Payment Notifier
	 */
	function ipn(& $BL)
	{
		$this->item_number    = $_POST['transaction_ref'];
		$this->transaction_id = $_POST['transaction_id'];
		$this->payment_status = $_POST['status'];
        
        $sqlSELECT = "SELECT  * FROM {$BL->props->tbl_payment_processors} WHERE `pp_name` ='stormpay'";
        $temp      = $BL->dbL->executeSELECT($sqlSELECT);
        $pp_vals   = $temp[0];         
        
		if (!empty ($_POST['user1']) && ($this->payment_status == "SUCCESS" || $this->payment_status == "TEST") && is_int($this->transaction_id) && !empty ($_POST['user1']) && !empty ($this->item_number) && $_POST['user1'] == $this->item_number && $_POST['user2'] == "stormpay" && $pp_vals['sp_secret_code']==$_POST['secret_code'])
		{
			$BL->processTransaction($this->item_number, $this->transaction_id);
			return true;
		}
		return false;
	}
}
?>