/**************************************************************************************************
* Form PHP Kit Includes File
**************************************************************************************************
**************************************************************************************************
* Change history
* ==============
*
* 10/02/2009 - Simon Wolfe - Updated for protocol 2.23
* 18/10/2007 - Nick Selby - New kit version
**************************************************************************************************
* Description
* ===========
*
* Page with no visible content, but defines the constants and functions used in other pages in the
* kit. It can also be used to open database connections to the database and defines record sets for later use.
* It is included at the top of every other page in the kit and is paried with the closedown scipt.
**************************************************************************************************/
ob_start();
/**************************************************************************************************
* Values for you to update
**************************************************************************************************/
$strConnectTo="SIMULATOR"; //Set to SIMULATOR for the Simulator expert system, TEST for the Test Server and LIVE in the live environment
$strVirtualDir=""; //Change if you have created a Virtual Directory in IIS with a different name
/** IMPORTANT. Set the strYourSiteFQDN value to the Fully Qualified Domain Name of your server. **
** This should start http:// or https:// and should be the name by which our servers can call back to yours **
** i.e. it MUST be resolvable externally, and have access granted to the Sage Pay servers **
** examples would be https://www.mysite.com or http://212.111.32.22/ **
** NOTE: You should leave the final / in place. **/
$strYourSiteFQDN="http://development.mzuridesign.co.uk/callaghans/";
$strVendorName="mzuridesign"; /** Set this value to the Vendor Name assigned to you by Sage Pay or chosen when you applied **/
$strEncryptionPassword="7rO6JhBdfs6NAzHt"; /** Set this value to the XOR Encryption password assigned to you by Sage Pay **/
$strCurrency="GBP"; /** Set this to indicate the currency in which you wish to trade. You will need a merchant number in this currency **/
$strTransactionType="PAYMENT"; /** This can be DEFERRED or AUTHENTICATE if your Sage Pay account supports those payment types **/
$strPartnerID=""; /** Optional setting. If you are a Sage Pay Partner and wish to flag the transactions with your unique partner id set it here. **/
/* Optional setting.
** 0 = Do not send either customer or vendor e-mails,
** 1 = Send customer and vendor e-mails if address(es) are provided(DEFAULT).
** 2 = Send Vendor Email but not Customer Email. If you do not supply this field, 1 is assumed and e-mails are sent if addresses are provided. **/
$bSendEMail=0;
$strVendorEMail="pault@mzuridesign.co.uk"; /** Optional setting. Set this to the mail address which will receive order confirmations and failures **/
/**************************************************************************************************
* Global Definitions for this site
**************************************************************************************************/
$strProtocol="2.23";
if ($strConnectTo=="LIVE")
$strPurchaseURL="https://live.sagepay.com/gateway/service/vspform-register.vsp";
elseif ($strConnectTo=="TEST")
$strPurchaseURL="https://test.sagepay.com/gateway/service/vspform-register.vsp";
else
$strPurchaseURL="https://test.sagepay.com/simulator/vspformgateway.asp";
/**************************************************************************************************
* Useful functions for all pages in this kit
***************************************************************************************************/
//Function to redirect browser to a specific page
function redirect($url) {
if (!headers_sent())
header('Location: '.$url);
else {
echo '';
echo '';
}
}
/* The getToken function. **
** NOTE: A function of convenience that extracts the value from the "name=value&name2=value2..." reply string **
** Works even if one of the values is a URL containing the & or = signs. */
function getToken($thisString) {
// List the possible tokens
$Tokens = array(
"Status",
"StatusDetail",
"VendorTxCode",
"VPSTxId",
"TxAuthNo",
"Amount",
"AVSCV2",
"AddressResult",
"PostCodeResult",
"CV2Result",
"GiftAid",
"3DSecureStatus",
"CAVV",
"AddressStatus",
"CardType",
"Last4Digits",
"PayerStatus","CardType");
// Initialise arrays
$output = array();
$resultArray = array();
// Get the next token in the sequence
for ($i = count($Tokens)-1; $i >= 0 ; $i--){
// Find the position in the string
$start = strpos($thisString, $Tokens[$i]);
// If it's present
if ($start !== false){
// Record position and token name
$resultArray[$i]->start = $start;
$resultArray[$i]->token = $Tokens[$i];
}
}
// Sort in order of position
sort($resultArray);
// Go through the result array, getting the token values
for ($i = 0; $istart + strlen($resultArray[$i]->token) + 1;
// Get the length of the value
if ($i==(count($resultArray)-1)) {
$output[$resultArray[$i]->token] = substr($thisString, $valueStart);
} else {
$valueLength = $resultArray[$i+1]->start - $resultArray[$i]->start - strlen($resultArray[$i]->token) - 2;
$output[$resultArray[$i]->token] = substr($thisString, $valueStart, $valueLength);
}
}
// Return the ouput array
return $output;
}
// 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