<?php
/*
 
	osCommRes, Services Oline 
	http://www.oscommres.com 
	Copyright (c) 2005 osCommRes 
	
	Freeway eCommerce 
	http://www.zac-ware.com/freeway 
	Copyright (c) 2007 ZacWare
	
	Released under the GNU General Public License
*/


// Set flag that this is a parent file
	define( '_FEXEC', 1 );
	

  require('includes/application_top.php');

  	if (!tep_session_is_registered("customer_id")){
		tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
	}
	
	$checkID=(isset($HTTP_SESSION_VARS["checkID"])?$HTTP_SESSION_VARS["checkID"]:'');
	$payment_page=(isset($HTTP_SESSION_VARS["payment_page"])?$HTTP_SESSION_VARS["payment_page"]:'');
	$afrestext="";
	$afrescode="";
	$afrescode=(isset($HTTP_POST_VARS["rescode"])?tep_db_prepare_input($HTTP_POST_VARS["rescode"]):'');
	$afrestext=(isset($HTTP_POST_VARS["restext"])?tep_db_prepare_input($HTTP_POST_VARS["restext"]):'');
	
	switch($payment_page){
		case "wallet":
			if($afrescode=="00" || $afrescode=="08") { //approved transaction
				$r=time();
				tep_write_payment_response($r,tep_join_keys_arr($HTTP_POST_VARS,"||"));
				tep_redirect(tep_href_link(FILENAME_WALLET_CHECKOUT_PROCESS, 'validID=' . $checkID, 'SSL'));
			}else{
				tep_redirect(tep_href_link(FILENAME_WALLET_CHECKOUT_PAYMENT, 'payment_error=westpac&error=' . urlencode($afrestext), 'SSL'));
			}
			break;
		default:
			if($afrescode=="00" || $afrescode=="08") { //approved transaction
				$r=time();
				tep_write_payment_response($r,tep_join_keys_arr($HTTP_POST_VARS,"||"));
				tep_redirect(tep_href_link(FILENAME_CHECKOUT_PROCESS, 'rstor=' . $r , 'SSL'));
			}else{
				tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=westpac&error=' . urlencode($afrestext), 'SSL'));
			}
			break;
	}
?>