ob_start(); //start output buffering
session_start(); //enable sessions
require_once('config.php');
/**************************************************************************************************
* Global Definitions for this site
***************************************************************************************************/
$strProtocol="4.00";
if ($strConnectTo=="LIVE")
{
$strAbortURL="https://live.sagepay.com/gateway/service/abort.vsp";
$strAuthoriseURL="https://live.sagepay.com/gateway/service/authorise.vsp";
$strCancelURL="https://live.sagepay.com/gateway/service/cancel.vsp";
$strPurchaseURL="https://live.sagepay.com/gateway/service/vspserver-register.vsp";
$strRefundURL="https://live.sagepay.com/gateway/service/refund.vsp";
$strReleaseURL="https://live.sagepay.com/gateway/service/release.vsp";
$strRepeatURL="https://live.sagepay.com/gateway/service/repeat.vsp";
$strVoidURL="https://live.sagepay.com/gateway/service/void.vsp";
}
elseif ($strConnectTo=="TEST")
{
$strAbortURL="https://test.sagepay.com/gateway/service/abort.vsp";
$strAuthoriseURL="https://test.sagepay.com/gateway/service/authorise.vsp";
$strCancelURL="https://test.sagepay.com/gateway/service/cancel.vsp";
$strPurchaseURL="https://test.sagepay.com/gateway/service/vspserver-register.vsp";
$strRefundURL="https://test.sagepay.com/gateway/service/refund.vsp";
$strReleaseURL="https://test.sagepay.com/gateway/service/abort.vsp";
$strRepeatURL="https://test.sagepay.com/gateway/service/repeat.vsp";
$strVoidURL="https://test.sagepay.com/gateway/service/void.vsp";
}
else
{
$strAbortURL="https://test.sagepay.com/simulator/VSPServerGateway.asp?Service=VendorAbortTx";
$strAuthoriseURL="https://test.sagepay.com/simulator/VSPServerGateway.asp?Service=VendorAuthoriseTx";
$strCancelURL="https://test.sagepay.com/simulator/VSPServerGateway.asp?Service=VendorCancelTx";
$strPurchaseURL="https://test.sagepay.com/simulator/VSPServerGateway.asp?Service=VendorRegisterTx";
$strRefundURL="https://test.sagepay.com/simulator/VSPServerGateway.asp?Service=VendorRefundTx";
$strReleaseURL="https://test.sagepay.com/simulator/VSPServerGateway.asp?Service=VendorReleaseTx";
$strRepeatURL="https://test.sagepay.com/simulator/VSPServerGateway.asp?Service=VendorRepeatTx";
$strVoidURL="https://test.sagepay.com/simulator/VSPServerGateway.asp?Service=VendorVoidTx";
}
/**************************************************************************************************
* Useful functions for all pages in this kit
**************************************************************************************************/
//Function to redirect browser
function redirect($url, $inParent=false)
{
if (!headers_sent())
header('Location: '.$url);
else
{
echo '';
echo '';
}
}
// Filters unwanted characters out of an input string. Useful for tidying up FORM field inputs
function cleanInput($strRawText,$strType)
{
if ($strType=="Number") {
$strClean="0123456789.";
$bolHighOrder=false;
}
else if ($strType=="VendorTxCode") {
$strClean="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.";
$bolHighOrder=false;
}
else {
$strClean=" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,'/{}@():?-_&�$=%~<>*+\"";
$bolHighOrder=true;
}
$strCleanedText="";
$iCharPos = 0;
do
{
// Only include valid characters
$chrThisChar=substr($strRawText,$iCharPos,1);
if (strspn($chrThisChar,$strClean,0,strlen($strClean))>0) {
$strCleanedText=$strCleanedText . $chrThisChar;
}
else if ($bolHighOrder==true) {
// Fix to allow accented characters and most high order bit chars which are harmless
if (bin2hex($chrThisChar)>=191) {
$strCleanedText=$strCleanedText . $chrThisChar;
}
}
$iCharPos=$iCharPos+1;
}
while ($iCharPos= 191)
{
$strCleanedText = $strCleanedText . $chrThisChar;
}
}
$iCharPos = $iCharPos + 1;
}
return $strCleanedText;
}
// Function to check validity of email address entered in form fields
function is_valid_email($email) {
$result = TRUE;
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) {
$result = FALSE;
}
return $result;
}
/*************************************************************
Send a post request with cURL
$url = URL to send request to
$data = POST data to send (in URL encoded Key=value pairs)
*************************************************************/
function requestPost($url, $data){
// Set a one-minute timeout for this script
set_time_limit(60);
// Initialise output variable
$output = array();
// Open the cURL session
$curlSession = curl_init();
// Set the URL
curl_setopt ($curlSession, CURLOPT_URL, $url);
// No headers, please
curl_setopt ($curlSession, CURLOPT_HEADER, 0);
// It's a POST request
curl_setopt ($curlSession, CURLOPT_POST, 1);
// Set the fields for the POST
curl_setopt ($curlSession, CURLOPT_POSTFIELDS, $data);
// Return it direct, don't print it out
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER,1);
// This connection will timeout in 30 seconds
curl_setopt($curlSession, CURLOPT_TIMEOUT,30);
//The next two lines must be present for the kit to work with newer version of cURL
//You should remove them if you have any problems in earlier versions of cURL
curl_setopt($curlSession, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curlSession, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($curlSession, CURLOPT_SSLVERSION,1);
//Send the request and store the result in an array
$rawresponse = curl_exec($curlSession);
//Store the raw response for later as it's useful to see for integration and understanding
$_SESSION["rawresponse"]=$rawresponse;
//Split response into name=value pairs
$response = split(chr(10), $rawresponse);
// Check that a connection was made
if (curl_error($curlSession)){
// If it wasn't...
$output['Status'] = "FAIL";
$output['StatusDetail'] = curl_error($curlSession);
}
// Close the cURL session
curl_close ($curlSession);
// Tokenise the response
for ($i=0; $i $intMaxLength))
{
return FIELD_INVALID_MAXIMUM_LENGTH_EXCEEDED;
}
elseif ($strInputValue != cleanInput2($strInputValue, $strAllowableChars, $blnAllowAccentedChars))
{
return FIELD_INVALID_BAD_CHARACTERS;
}
elseif (($blnIsRequired == TRUE) && (strlen($strInputValue) < $intMinLength))
{
return FIELD_INVALID_MINIMUM_LENGTH_NOT_MET;
}
elseif (($blnIsRequired == FALSE) && (strlen($strInputValue) > 0) && (strlen($strInputValue) < $intMinLength))
{
return FIELD_INVALID_MINIMUM_LENGTH_NOT_MET;
}
else
{
return FIELD_VALID;
}
}
// A generic function to inspect and validate a string from user input based on a Regular Expression pattern.
// Parameter "strInputValue" is the value to perform validation on.
// Parameter "strRegExPattern" is a Regular Expression string pattern used to validate against "strInputValue".
// Parameter "blnIsRequired" accepts a boolean value which specifies whether "strInputValue" must have a non-null and non-empty value.
// Returns a result from one of the field validation constants that begin with "FIELD_"
function validateStringWithRegExp($strInputValue, $strRegExPattern, $blnIsRequired)
{
if ($blnIsRequired == TRUE && strlen($strInputValue) == 0)
{
return FIELD_INVALID_REQUIRED_INPUT_VALUE_MISSING;
}
elseif (strlen($strInputValue) > 0)
{
if (preg_match($strRegExPattern, $strInputValue)) {
return FIELD_VALID;
} else {
return FIELD_INVALID_BAD_FORMAT;
}
}
else
{
return FIELD_VALID;
}
}
// Maps a Field Validation constant value to a string representing a user friendly validation error message.
// Parameter "strFieldLabelName" is the display name of the form field to use in the returned message.
function getValidationMessage($fieldValidationCode, $strFieldLabelName)
{
$strReturn = "";
switch ($fieldValidationCode)
{
case FIELD_INVALID_BAD_CHARACTERS:
$strReturn = "Please correct " . $strFieldLabelName . " as it contains disallowed characters.";
break;
case FIELD_INVALID_BAD_FORMAT:
$strReturn = "Please correct " . $strFieldLabelName . " as the format is invalid.";
break;
case FIELD_INVALID_MINIMUM_LENGTH_NOT_MET:
$strReturn = "Please correct " . $strFieldLabelName . " as the value is not long enough.";
break;
case FIELD_INVALID_MAXIMUM_LENGTH_EXCEEDED:
$strReturn = "Please correct " . $strFieldLabelName . " as the value is too long.";
break;
case FIELD_INVALID_REQUIRED_INPUT_VALUE_MISSING:
$strReturn = "Please enter a value for " . $strFieldLabelName . " where requested below.";
break;
case FIELD_INVALID_REQUIRED_INPUT_VALUE_NOT_SELECTED:
$strReturn = "Please select a value for " . $strFieldLabelName . " where requested below.";
break;
}
return $strReturn;
}
/************ Global definitions ***************/
// Defines filter types used for a parameter in the cleanInput() function.
Define("CLEAN_INPUT_FILTER_ALPHABETIC", "alpha");
Define("CLEAN_INPUT_FILTER_ALPHABETIC_AND_ACCENTED", "alpha and accented");
Define("CLEAN_INPUT_FILTER_ALPHANUMERIC", "alphaNumeric");
Define("CLEAN_INPUT_FILTER_ALPHANUMERIC_AND_ACCENTED", "alphaNumeric and accented");
Define("CLEAN_INPUT_FILTER_NUMERIC", "numeric");
Define("CLEAN_INPUT_FILTER_TEXT", "text");
Define("CLEAN_INPUT_FILTER_WIDEST_ALLOWABLE_CHARACTER_RANGE", "text");
// Defines a set of values used as outcomes in field validation functions such as isValidAddressField.
Define("FIELD_VALID", "valid");
Define("FIELD_INVALID", "invalid");
Define("FIELD_INVALID_BAD_CHARACTERS", "bad characters");
Define("FIELD_INVALID_BAD_FORMAT", "bad format");
Define("FIELD_INVALID_MAXIMUM_LENGTH_EXCEEDED", "maximum exceeded");
Define("FIELD_INVALID_MINIMUM_LENGTH_NOT_MET", "minimum not met");
Define("FIELD_INVALID_REQUIRED_INPUT_VALUE_MISSING", "missing required value");
Define("FIELD_INVALID_REQUIRED_INPUT_VALUE_NOT_SELECTED", "required value not selected");
?>
Order Now|SnoreWizard
Copyright SnoreWizard 2025. Registered in England No. 1744352. Fast Systems Ltd, West Suite, Building 5, Withy Copse, Horsepond Road, Kidmore End, RG4 9HNL