<?php
// Estonian e-payments system 1.4
// 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 can be moved in POST and GET
$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';
}
//Storing post variables for submitting automated request
$curlData=array();
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.'"/>';
$curlData[$key]=$p;
$hash.='&'.$key.'='.$p;
}
echo '<input type="hidden" name="epay-final" value="final"/>';
$curlData['epay-final']='final';
$hash=md5($hash);
echo '<input type="hidden" name="epay-hash" value="'.$hash.'"/>';
$curlData['epay-hash']=$hash;
echo '<input type="submit" name="epay-submitbutton" id="epay-submitbutton" value="click here if you are not being redirected"/>';
$curlData['epay-submitbutton']='click here if you are not being redirected';
echo '</form>';
echo '<input type="hidden" name="generated" id="generated" value="1"/>';
echo '</body>';
echo '</html>';
//This is for automated cURL request back to website, if cURL is not enabled, then some bank services might not work
if(in_array('curl',get_loaded_extensions())){
$handle=curl_init($data['epay-r']);
curl_setopt($handle,CURLOPT_POST,true);
curl_setopt($handle,CURLOPT_POSTFIELDS,$curlData);
curl_exec($handle);
}
} else {
echo 'gateway has nothing to handle';
}
} else {
echo 'gateway has nothing to handle';
}
?>
|