Location: PHPKode > scripts > Estonian e-payments solution > gate.epay.php
<?php

	// Estonian e-payments system 1.1 beta
	// Kristo Vaher 2011 http://www.waher.net
	// Licensed under LGPL http://www.gnu.org/licenses/lgpl-3.0.txt
	// Published http://waher.net/archives/852
	
	//This is gateway file used to process data to be sent to bank or returned from bank, it also deals with converting the encoding
	
	//It is recommended not to edit this file, unless really necessary
	
	ini_set('display_errors',1);
	error_reporting(E_ALL);
	ini_set('error_reporting', E_ALL);
	
	require('class.epay.php');
	require('config.epay.php');
	
	if(!empty($_GET) || !empty($_POST)){
		$data=array_merge($_POST,$_GET);
		if(isset($data['epay-t']) && isset($config[$data['epay-t']]) && !empty($config[$data['epay-t']]) && !isset($data['epay-r'])){
			$config=$config[$data['epay-t']];
			$config['payment']=$data['epay-t'];
			if($data['epay-t']=='sampo-est'){
				header('Content-Type: text/html; charset=ISO-8859-1');
				$charset='ISO-8859-1';
				foreach($data as $key=>$value){
					$data[$key]=utf8_decode($value);
				}
			} else {
				header('Content-Type: text/html; charset=UTF-8'); 
				$charset='UTF-8';
			}
			if(isset($data['order']) && isset($data['amount'])){
				$config['order']['order-code']=$data['order']; //unique order code in web service
				$config['order']['amount']=$data['amount']; //amount of money to transfer
				$config['settings']['return-url']=$data['return']; //amount of money to transfer
				if(isset($data['currency'])){
					$config['order']['currency']=$data['currency']; //currency to transfer in
				} else {
					$config['order']['currency']='EUR'; //currency to transfer in
				}
				if(isset($data['message'])){
					$config['order']['message']=$data['message']; //subject/explanation field in payment
				} else {
					$config['order']['message']='Order #'.$data['order-code'];
				}
				if(isset($data['language'])){
					$config['settings']['language']=$data['language']; //subject/explanation field in payment
				} else {
					$config['settings']['language']='english';
				}
				echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
				echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="et">';
					echo '<head>';
						echo '<meta http-equiv="Content-Type" content="text/html; charset='.$charset.'"/>';
					echo '</head>';
					echo '<body onload="if(document.getElementById(\'generated\').value==1){document.forms[\'epay-form\'].submit();}" style="font:11px Verdana; text-align:center;">';
						echo '<p>please wait while you are being redirected to e-payment web service</p>';
						$banklink=new Payment($config);
						$banklink->submitForm();
						echo '<input type="hidden" name="generated" id="generated" value="1"/>';
					echo '</body>';
				echo '</html>';
			} else {
				echo 'order code and amount need to be set';
			}
		} else if(isset($data['epay-r'])){
			$config=$config[$data['epay-t']];
			$config['payment']=$data['epay-t'];
			$banklink=new Payment($config);
			$payment=$banklink->checkPayment($data);
			$payment['epay-t']=$data['epay-t'];
			$payment['epay-rt']=$data['epay-rt'];
			ksort($payment);
			if($data['epay-t']=='sampo-est'){
				header('Content-Type: text/html; charset=ISO-8859-1');
				$charset='ISO-8859-1';
				foreach($payment as $key=>$value){
					$payment[$key]=utf8_encode($value);
				}
			} else {
				header('Content-Type: text/html; charset=UTF-8'); 
				$charset='UTF-8';
			}
			echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
			echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="et">';
				echo '<head>';
					echo '<meta http-equiv="Content-Type" content="text/html; charset='.$charset.'"/>';
				echo '</head>';
				echo '<body onload="if(document.getElementById(\'generated\').value==1){document.forms[\'epay-form\'].submit();}" style="font:11px Verdana; text-align:center;">';
					echo '<p>please wait while you are being redirected to e-payment web service</p>';
					echo '<form name="epay-form" action="'.$data['epay-r'].'" method="post">';
						$hash=$config['hash'];
						foreach($payment as $key=>$p){
							echo '<input type="hidden" name="'.$key.'" value="'.$p.'"/>';
							$hash.='&'.$key.'='.$p;
						}
						echo '<input type="hidden" name="epay-final" value="final"/>';
						$hash=md5($hash);
						echo '<input type="hidden" name="epay-hash" value="'.$hash.'"/>';
						echo '<input type="submit" name="epay-submitbutton" id="epay-submitbutton" value="click here if you are not being redirected"/>';
					echo '</form>';
					echo '<input type="hidden" name="generated" id="generated" value="1"/>';
				echo '</body>';
			echo '</html>';
		} else {
			echo 'gateway has nothing to handle';
		}
	} else {
		echo 'gateway has nothing to handle';
	}
	
?>
Return current item: Estonian e-payments solution