"; #print_r($_SESSION); /************************************************************************************************** * Useful functions for all pages in this kit ***************************************************************************************************/ //Function to sagepay_redirect browser to a specific page function sagepay_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..." VSP 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\n"; $output .= " // Data & function(s) for ISO 3166-1 country names and codes \n"; $output .= " // Get HTML for a list of Select options of ISO 3166-1 country names and codes. \n"; $output .= " // eg \" \n"; $output .= " // \" \n"; $output .= " // Parameters: strSelectedValue is a value that will be marked as \"SELECTED\" \n"; $output .= " // if it is found in the options list \n"; $output .= " function getCountryOptionsListHtml(strSelectedValue) { \n"; $output .= " var strCountryOptionsList = '\\n'; \n"; $output .= " for (var i = 0; i < countries.length; i++) { \n"; $output .= " strCountryOptionsList += '\\n\"; \n"; $output .= " } \n"; $output .= " return strCountryOptionsList; \n"; $output .= " } \n"; $output .= " \n"; $output .= " \n"; $output .= " // Get the country name for a given code. \n"; $output .= " function getCountryName(strCountryCode) { \n"; $output .= " for (var i = 0; i < countries.length; i++) { \n"; $output .= " if (strCountryCode == countries[i].code) { \n"; $output .= " return countries[i].name; \n"; $output .= " } \n"; $output .= " } \n"; $output .= " return \"\"; \n"; $output .= " } \n"; $output .= " \n"; $output .= " \n"; $output .= " // ISO 3166-1 country names and codes from http://opencountrycodes.appspot.com/javascript \n"; $output .= " countries = [ \n"; $output .= " {code: \"GB\", name: \"United Kingdom\"}, \n"; $output .= " {code: \"AF\", name: \"Afghanistan\"}, \n"; $output .= " {code: \"AX\", name: \"Aland Islands\"}, \n"; $output .= " {code: \"AL\", name: \"Albania\"}, \n"; $output .= " {code: \"DZ\", name: \"Algeria\"}, \n"; $output .= " {code: \"AS\", name: \"American Samoa\"}, \n"; $output .= " {code: \"AD\", name: \"Andorra\"}, \n"; $output .= " {code: \"AO\", name: \"Angola\"}, \n"; $output .= " {code: \"AI\", name: \"Anguilla\"}, \n"; $output .= " {code: \"AQ\", name: \"Antarctica\"}, \n"; $output .= " {code: \"AG\", name: \"Antigua and Barbuda\"}, \n"; $output .= " {code: \"AR\", name: \"Argentina\"}, \n"; $output .= " {code: \"AM\", name: \"Armenia\"}, \n"; $output .= " {code: \"AW\", name: \"Aruba\"}, \n"; $output .= " {code: \"AU\", name: \"Australia\"}, \n"; $output .= " {code: \"AT\", name: \"Austria\"}, \n"; $output .= " {code: \"AZ\", name: \"Azerbaijan\"}, \n"; $output .= " {code: \"BS\", name: \"Bahamas\"}, \n"; $output .= " {code: \"BH\", name: \"Bahrain\"}, \n"; $output .= " {code: \"BD\", name: \"Bangladesh\"}, \n"; $output .= " {code: \"BB\", name: \"Barbados\"}, \n"; $output .= " {code: \"BY\", name: \"Belarus\"}, \n"; $output .= " {code: \"BE\", name: \"Belgium\"}, \n"; $output .= " {code: \"BZ\", name: \"Belize\"}, \n"; $output .= " {code: \"BJ\", name: \"Benin\"}, \n"; $output .= " {code: \"BM\", name: \"Bermuda\"}, \n"; $output .= " {code: \"BT\", name: \"Bhutan\"}, \n"; $output .= " {code: \"BO\", name: \"Bolivia\"}, \n"; $output .= " {code: \"BA\", name: \"Bosnia and Herzegovina\"}, \n"; $output .= " {code: \"BW\", name: \"Botswana\"}, \n"; $output .= " {code: \"BV\", name: \"Bouvet Island\"}, \n"; $output .= " {code: \"BR\", name: \"Brazil\"}, \n"; $output .= " {code: \"IO\", name: \"British Indian Ocean Territory\"}, \n"; $output .= " {code: \"BN\", name: \"Brunei Darussalam\"}, \n"; $output .= " {code: \"BG\", name: \"Bulgaria\"}, \n"; $output .= " {code: \"BF\", name: \"Burkina Faso\"}, \n"; $output .= " {code: \"BI\", name: \"Burundi\"}, \n"; $output .= " {code: \"KH\", name: \"Cambodia\"}, \n"; $output .= " {code: \"CM\", name: \"Cameroon\"}, \n"; $output .= " {code: \"CA\", name: \"Canada\"}, \n"; $output .= " {code: \"CV\", name: \"Cape Verde\"}, \n"; $output .= " {code: \"KY\", name: \"Cayman Islands\"}, \n"; $output .= " {code: \"CF\", name: \"Central African Republic\"}, \n"; $output .= " {code: \"TD\", name: \"Chad\"}, \n"; $output .= " {code: \"CL\", name: \"Chile\"}, \n"; $output .= " {code: \"CN\", name: \"China\"}, \n"; $output .= " {code: \"CX\", name: \"Christmas Island\"}, \n"; $output .= " {code: \"CC\", name: \"Cocos (Keeling) Islands\"}, \n"; $output .= " {code: \"CO\", name: \"Colombia\"}, \n"; $output .= " {code: \"KM\", name: \"Comoros\"}, \n"; $output .= " {code: \"CG\", name: \"Congo\"}, \n"; $output .= " {code: \"CD\", name: \"Congo, The Democratic Republic of the\"}, \n"; $output .= " {code: \"CK\", name: \"Cook Islands\"}, \n"; $output .= " {code: \"CR\", name: \"Costa Rica\"}, \n"; $output .= " {code: \"CI\", name: \"Côte d'Ivoire\"}, \n"; $output .= " {code: \"HR\", name: \"Croatia\"}, \n"; $output .= " {code: \"CU\", name: \"Cuba\"}, \n"; $output .= " {code: \"CY\", name: \"Cyprus\"}, \n"; $output .= " {code: \"CZ\", name: \"Czech Republic\"}, \n"; $output .= " {code: \"DK\", name: \"Denmark\"}, \n"; $output .= " {code: \"DJ\", name: \"Djibouti\"}, \n"; $output .= " {code: \"DM\", name: \"Dominica\"}, \n"; $output .= " {code: \"DO\", name: \"Dominican Republic\"}, \n"; $output .= " {code: \"EC\", name: \"Ecuador\"}, \n"; $output .= " {code: \"EG\", name: \"Egypt\"}, \n"; $output .= " {code: \"SV\", name: \"El Salvador\"}, \n"; $output .= " {code: \"GQ\", name: \"Equatorial Guinea\"}, \n"; $output .= " {code: \"ER\", name: \"Eritrea\"}, \n"; $output .= " {code: \"EE\", name: \"Estonia\"}, \n"; $output .= " {code: \"ET\", name: \"Ethiopia\"}, \n"; $output .= " {code: \"FK\", name: \"Falkland Islands (Malvinas)\"}, \n"; $output .= " {code: \"FO\", name: \"Faroe Islands\"}, \n"; $output .= " {code: \"FJ\", name: \"Fiji\"}, \n"; $output .= " {code: \"FI\", name: \"Finland\"}, \n"; $output .= " {code: \"FR\", name: \"France\"}, \n"; $output .= " {code: \"GF\", name: \"French Guiana\"}, \n"; $output .= " {code: \"PF\", name: \"French Polynesia\"}, \n"; $output .= " {code: \"TF\", name: \"French Southern Territories\"}, \n"; $output .= " {code: \"GA\", name: \"Gabon\"}, \n"; $output .= " {code: \"GM\", name: \"Gambia\"}, \n"; $output .= " {code: \"GE\", name: \"Georgia\"}, \n"; $output .= " {code: \"DE\", name: \"Germany\"}, \n"; $output .= " {code: \"GH\", name: \"Ghana\"}, \n"; $output .= " {code: \"GI\", name: \"Gibraltar\"}, \n"; $output .= " {code: \"GR\", name: \"Greece\"}, \n"; $output .= " {code: \"GL\", name: \"Greenland\"}, \n"; $output .= " {code: \"GD\", name: \"Grenada\"}, \n"; $output .= " {code: \"GP\", name: \"Guadeloupe\"}, \n"; $output .= " {code: \"GU\", name: \"Guam\"}, \n"; $output .= " {code: \"GT\", name: \"Guatemala\"}, \n"; $output .= " {code: \"GG\", name: \"Guernsey\"}, \n"; $output .= " {code: \"GN\", name: \"Guinea\"}, \n"; $output .= " {code: \"GW\", name: \"Guinea-Bissau\"}, \n"; $output .= " {code: \"GY\", name: \"Guyana\"}, \n"; $output .= " {code: \"HT\", name: \"Haiti\"}, \n"; $output .= " {code: \"HM\", name: \"Heard Island and McDonald Islands\"}, \n"; $output .= " {code: \"VA\", name: \"Holy See (Vatican City State)\"}, \n"; $output .= " {code: \"HN\", name: \"Honduras\"}, \n"; $output .= " {code: \"HK\", name: \"Hong Kong\"}, \n"; $output .= " {code: \"HU\", name: \"Hungary\"}, \n"; $output .= " {code: \"IS\", name: \"Iceland\"}, \n"; $output .= " {code: \"IN\", name: \"India\"}, \n"; $output .= " {code: \"ID\", name: \"Indonesia\"}, \n"; $output .= " {code: \"IR\", name: \"Iran, Islamic Republic of\"}, \n"; $output .= " {code: \"IQ\", name: \"Iraq\"}, \n"; $output .= " {code: \"IE\", name: \"Ireland\"}, \n"; $output .= " {code: \"IM\", name: \"Isle of Man\"}, \n"; $output .= " {code: \"IL\", name: \"Israel\"}, \n"; $output .= " {code: \"IT\", name: \"Italy\"}, \n"; $output .= " {code: \"JM\", name: \"Jamaica\"}, \n"; $output .= " {code: \"JP\", name: \"Japan\"}, \n"; $output .= " {code: \"JE\", name: \"Jersey\"}, \n"; $output .= " {code: \"JO\", name: \"Jordan\"}, \n"; $output .= " {code: \"KZ\", name: \"Kazakhstan\"}, \n"; $output .= " {code: \"KE\", name: \"Kenya\"}, \n"; $output .= " {code: \"KI\", name: \"Kiribati\"}, \n"; $output .= " {code: \"KP\", name: \"Korea, Democratic People's Republic of\"}, \n"; $output .= " {code: \"KR\", name: \"Korea, Republic of\"}, \n"; $output .= " {code: \"KW\", name: \"Kuwait\"}, \n"; $output .= " {code: \"KG\", name: \"Kyrgyzstan\"}, \n"; $output .= " {code: \"LA\", name: \"Lao People's Democratic Republic\"}, \n"; $output .= " {code: \"LV\", name: \"Latvia\"}, \n"; $output .= " {code: \"LB\", name: \"Lebanon\"}, \n"; $output .= " {code: \"LS\", name: \"Lesotho\"}, \n"; $output .= " {code: \"LR\", name: \"Liberia\"}, \n"; $output .= " {code: \"LY\", name: \"Libyan Arab Jamahiriya\"}, \n"; $output .= " {code: \"LI\", name: \"Liechtenstein\"}, \n"; $output .= " {code: \"LT\", name: \"Lithuania\"}, \n"; $output .= " {code: \"LU\", name: \"Luxembourg\"}, \n"; $output .= " {code: \"MO\", name: \"Macao\"}, \n"; $output .= " {code: \"MK\", name: \"Macedonia, The Former Yugoslav Republic of\"}, \n"; $output .= " {code: \"MG\", name: \"Madagascar\"}, \n"; $output .= " {code: \"MW\", name: \"Malawi\"}, \n"; $output .= " {code: \"MY\", name: \"Malaysia\"}, \n"; $output .= " {code: \"MV\", name: \"Maldives\"}, \n"; $output .= " {code: \"ML\", name: \"Mali\"}, \n"; $output .= " {code: \"MT\", name: \"Malta\"}, \n"; $output .= " {code: \"MH\", name: \"Marshall Islands\"}, \n"; $output .= " {code: \"MQ\", name: \"Martinique\"}, \n"; $output .= " {code: \"MR\", name: \"Mauritania\"}, \n"; $output .= " {code: \"MU\", name: \"Mauritius\"}, \n"; $output .= " {code: \"YT\", name: \"Mayotte\"}, \n"; $output .= " {code: \"MX\", name: \"Mexico\"}, \n"; $output .= " {code: \"FM\", name: \"Micronesia, Federated States of\"}, \n"; $output .= " {code: \"MD\", name: \"Moldova\"}, \n"; $output .= " {code: \"MC\", name: \"Monaco\"}, \n"; $output .= " {code: \"MN\", name: \"Mongolia\"}, \n"; $output .= " {code: \"ME\", name: \"Montenegro\"}, \n"; $output .= " {code: \"MS\", name: \"Montserrat\"}, \n"; $output .= " {code: \"MA\", name: \"Morocco\"}, \n"; $output .= " {code: \"MZ\", name: \"Mozambique\"}, \n"; $output .= " {code: \"MM\", name: \"Myanmar\"}, \n"; $output .= " {code: \"NA\", name: \"Namibia\"}, \n"; $output .= " {code: \"NR\", name: \"Nauru\"}, \n"; $output .= " {code: \"NP\", name: \"Nepal\"}, \n"; $output .= " {code: \"NL\", name: \"Netherlands\"}, \n"; $output .= " {code: \"AN\", name: \"Netherlands Antilles\"}, \n"; $output .= " {code: \"NC\", name: \"New Caledonia\"}, \n"; $output .= " {code: \"NZ\", name: \"New Zealand\"}, \n"; $output .= " {code: \"NI\", name: \"Nicaragua\"}, \n"; $output .= " {code: \"NE\", name: \"Niger\"}, \n"; $output .= " {code: \"NG\", name: \"Nigeria\"}, \n"; $output .= " {code: \"NU\", name: \"Niue\"}, \n"; $output .= " {code: \"NF\", name: \"Norfolk Island\"}, \n"; $output .= " {code: \"MP\", name: \"Northern Mariana Islands\"}, \n"; $output .= " {code: \"NO\", name: \"Norway\"}, \n"; $output .= " {code: \"OM\", name: \"Oman\"}, \n"; $output .= " {code: \"PK\", name: \"Pakistan\"}, \n"; $output .= " {code: \"PW\", name: \"Palau\"}, \n"; $output .= " {code: \"PS\", name: \"Palestinian Territory, Occupied\"}, \n"; $output .= " {code: \"PA\", name: \"Panama\"}, \n"; $output .= " {code: \"PG\", name: \"Papua New Guinea\"}, \n"; $output .= " {code: \"PY\", name: \"Paraguay\"}, \n"; $output .= " {code: \"PE\", name: \"Peru\"}, \n"; $output .= " {code: \"PH\", name: \"Philippines\"}, \n"; $output .= " {code: \"PN\", name: \"Pitcairn\"}, \n"; $output .= " {code: \"PL\", name: \"Poland\"}, \n"; $output .= " {code: \"PT\", name: \"Portugal\"}, \n"; $output .= " {code: \"PR\", name: \"Puerto Rico\"}, \n"; $output .= " {code: \"QA\", name: \"Qatar\"}, \n"; $output .= " {code: \"RE\", name: \"Réunion\"}, \n"; $output .= " {code: \"RO\", name: \"Romania\"}, \n"; $output .= " {code: \"RU\", name: \"Russian Federation\"}, \n"; $output .= " {code: \"RW\", name: \"Rwanda\"}, \n"; $output .= " {code: \"BL\", name: \"Saint Barthélemy\"}, \n"; $output .= " {code: \"SH\", name: \"Saint Helena\"}, \n"; $output .= " {code: \"KN\", name: \"Saint Kitts and Nevis\"}, \n"; $output .= " {code: \"LC\", name: \"Saint Lucia\"}, \n"; $output .= " {code: \"MF\", name: \"Saint Martin\"}, \n"; $output .= " {code: \"PM\", name: \"Saint Pierre and Miquelon\"}, \n"; $output .= " {code: \"VC\", name: \"Saint Vincent and the Grenadines\"}, \n"; $output .= " {code: \"WS\", name: \"Samoa\"}, \n"; $output .= " {code: \"SM\", name: \"San Marino\"}, \n"; $output .= " {code: \"ST\", name: \"Sao Tome and Principe\"}, \n"; $output .= " {code: \"SA\", name: \"Saudi Arabia\"}, \n"; $output .= " {code: \"SN\", name: \"Senegal\"}, \n"; $output .= " {code: \"RS\", name: \"Serbia\"}, \n"; $output .= " {code: \"SC\", name: \"Seychelles\"}, \n"; $output .= " {code: \"SL\", name: \"Sierra Leone\"}, \n"; $output .= " {code: \"SG\", name: \"Singapore\"}, \n"; $output .= " {code: \"SK\", name: \"Slovakia\"}, \n"; $output .= " {code: \"SI\", name: \"Slovenia\"}, \n"; $output .= " {code: \"SB\", name: \"Solomon Islands\"}, \n"; $output .= " {code: \"SO\", name: \"Somalia\"}, \n"; $output .= " {code: \"ZA\", name: \"South Africa\"}, \n"; $output .= " {code: \"GS\", name: \"South Georgia and the South Sandwich Islands\"}, \n"; $output .= " {code: \"ES\", name: \"Spain\"}, \n"; $output .= " {code: \"LK\", name: \"Sri Lanka\"}, \n"; $output .= " {code: \"SD\", name: \"Sudan\"}, \n"; $output .= " {code: \"SR\", name: \"Suriname\"}, \n"; $output .= " {code: \"SJ\", name: \"Svalbard and Jan Mayen\"}, \n"; $output .= " {code: \"SZ\", name: \"Swaziland\"}, \n"; $output .= " {code: \"SE\", name: \"Sweden\"}, \n"; $output .= " {code: \"CH\", name: \"Switzerland\"}, \n"; $output .= " {code: \"SY\", name: \"Syrian Arab Republic\"}, \n"; $output .= " {code: \"TW\", name: \"Taiwan, Province of China\"}, \n"; $output .= " {code: \"TJ\", name: \"Tajikistan\"}, \n"; $output .= " {code: \"TZ\", name: \"Tanzania, United Republic of\"}, \n"; $output .= " {code: \"TH\", name: \"Thailand\"}, \n"; $output .= " {code: \"TL\", name: \"Timor-Leste\"}, \n"; $output .= " {code: \"TG\", name: \"Togo\"}, \n"; $output .= " {code: \"TK\", name: \"Tokelau\"}, \n"; $output .= " {code: \"TO\", name: \"Tonga\"}, \n"; $output .= " {code: \"TT\", name: \"Trinidad and Tobago\"}, \n"; $output .= " {code: \"TN\", name: \"Tunisia\"}, \n"; $output .= " {code: \"TR\", name: \"Turkey\"}, \n"; $output .= " {code: \"TM\", name: \"Turkmenistan\"}, \n"; $output .= " {code: \"TC\", name: \"Turks and Caicos Islands\"}, \n"; $output .= " {code: \"TV\", name: \"Tuvalu\"}, \n"; $output .= " {code: \"UG\", name: \"Uganda\"}, \n"; $output .= " {code: \"UA\", name: \"Ukraine\"}, \n"; $output .= " {code: \"AE\", name: \"United Arab Emirates\"}, \n"; $output .= " {code: \"GB\", name: \"United Kingdom\"}, \n"; $output .= " {code: \"US\", name: \"United States\"}, \n"; $output .= " {code: \"UM\", name: \"United States Minor Outlying Islands\"}, \n"; $output .= " {code: \"UY\", name: \"Uruguay\"}, \n"; $output .= " {code: \"UZ\", name: \"Uzbekistan\"}, \n"; $output .= " {code: \"VU\", name: \"Vanuatu\"}, \n"; $output .= " {code: \"VE\", name: \"Venezuela\"}, \n"; $output .= " {code: \"VN\", name: \"Viet Nam\"}, \n"; $output .= " {code: \"VG\", name: \"Virgin Islands, British\"}, \n"; $output .= " {code: \"VI\", name: \"Virgin Islands, U.S.\"}, \n"; $output .= " {code: \"WF\", name: \"Wallis and Futuna\"}, \n"; $output .= " {code: \"EH\", name: \"Western Sahara\"}, \n"; $output .= " {code: \"YE\", name: \"Yemen\"}, \n"; $output .= " {code: \"ZM\", name: \"Zambia\"}, \n"; $output .= " {code: \"ZW\", name: \"Zimbabwe\"} \n"; $output .= " ]; \n"; $output .= " \n"; return Keep($output); } /************************************************************************************************** * Sagepay Markups **************************************************************************************************/ /* SagepayProduct */ Markup('SagepayProduct', 'inline', '/\\(:SagepayProduct (.*?):\\)/e', 'fSagepay_Product("$1")'); /* SagepayCustomerDetails */ Markup('SagepayCustomerDetails', 'inline', '/\\(:SagepayCustomerDetails (.*?):\\)/e', 'fSagepay_CustomerDetails("$1")'); /* SagepayOrderConfirmation */ Markup('SagepayOrderConfirmation', 'inline', '/\\(:SagepayOrderConfirmation (.*?):\\)/e', 'fSagepay_OrderConfirmation("$1")'); /* SagepayOrderSuccessful */ Markup('SagepayOrderSuccessful', 'inline', '/\\(:SagepayOrderSuccessful (.*?):\\)/e', 'fSagepay_OrderSuccessful("$1")'); /* SagepayOrderFailed */ Markup('SagepayOrderFailed', 'inline', '/\\(:SagepayOrderFailed (.*?):\\)/e', 'fSagepay_OrderFailed("$1")'); /**************************************************************************************************/ /* Sagepay Functions */ /**************************************************************************************************/ /**************************************************************************************************/ /* fSagepay_Product */ /**************************************************************************************************/ function fSagepay_Product($opts) { global $SagePayDefaults; $args = ParseArgs($opts); $value = $args['value']; $name = $args['name']; // create a random number to use as the form name, so more than one form can be placed on each page $formname = "formref" .rand(1, 999); #$output = "debug fSagepay_Product.
name: " . $name . ".
value: " . $value . ".
"; $output = ""; $output .= "
\n"; $output .= "\n"; $output .= "\n"; $output .= " " .$name . " - "; $output .= "Email us about this trip \n"; $output .= " - "; $output .= "Book this trip"; $output .= "
"; return Keep($output); } /**************************************************************************************************/ /* fSagepay_CustomerDetails */ /**************************************************************************************************/ function fSagepay_CustomerDetails($opts) { global $SagePayDefaults; // Check for the proceed button click, and if so, go validate the order // this means the form was just submitted if ($_REQUEST['navigate']=="proceed") { #echo "

navigate is proceed"; // Validate and clean the user input here $strBillingFirstnames = cleaninput($_REQUEST["BillingFirstnames"], "Text"); $strBillingSurname = cleaninput($_REQUEST["BillingSurname"], "Text"); $strBillingAddress1 = cleaninput($_REQUEST["BillingAddress1"], "Text"); $strBillingAddress2 = cleaninput($_REQUEST["BillingAddress2"], "Text"); $strBillingCity = cleaninput($_REQUEST["BillingCity"], "Text"); $strBillingPostCode = cleaninput($_REQUEST["BillingPostCode"], "Text"); $strBillingCountry = cleaninput($_REQUEST["BillingCountry"], "Text"); $strBillingState = cleaninput($_REQUEST["BillingState"], "Text"); $strBillingPhone = cleaninput($_REQUEST["BillingPhone"], "Text"); $strCustomerEMail = cleaninput($_REQUEST["CustomerEMail"], "Text"); $strDeliveryFirstnames = cleaninput($_REQUEST["DeliveryFirstnames"], "Text"); $strDeliverySurname = cleaninput($_REQUEST["DeliverySurname"], "Text"); $strDeliveryAddress1 = cleaninput($_REQUEST["DeliveryAddress1"], "Text"); $strDeliveryAddress2 = cleaninput($_REQUEST["DeliveryAddress2"], "Text"); $strDeliveryCity = cleaninput($_REQUEST["DeliveryCity"], "Text"); $strDeliveryPostCode = cleaninput($_REQUEST["DeliveryPostCode"], "Text"); $strDeliveryCountry = cleaninput($_REQUEST["DeliveryCountry"], "Text"); $strDeliveryState = cleaninput($_REQUEST["DeliveryState"], "Text"); $strDeliveryPhone = cleaninput($_REQUEST["DeliveryPhone"], "Text"); if ($_REQUEST["IsDeliverySame"]=="YES") $bIsDeliverySame=true; else $bIsDeliverySame=false; // Validate the compulsory fields if (strlen($strBillingFirstnames)==0) $strPageError="Please enter your Billing First Names(s) where requested below."; else if (strlen($strBillingSurname)==0) $strPageError="Please enter your Billing Surname where requested below."; else if (strlen($strBillingAddress1)==0) $strPageError="Please enter your Billing Address Line 1 where requested below."; else if (strlen($strBillingCity)==0) $strPageError="Please enter your Billing City where requested below."; else if (strlen($strBillingPostCode)==0) $strPageError="Please enter your Billing Post Code where requested below."; else if (strlen($strBillingCountry)==0) $strPageError="Please select your Billing Country where requested below."; else if ((strlen($strBillingState) == 0) and ($strBillingCountry == "US")) $strPageError="Please enter your State code as you have selected United States for billing country."; else if (is_valid_email($strCustomerEMail)==false) $strPageError="The email address entered was invalid."; else if (($bIsDeliverySame==false) and strlen($strDeliveryFirstnames)==0) $strPageError="Please enter your Delivery First Names(s) where requested below."; else if (($bIsDeliverySame==false) and strlen($strDeliverySurname)==0) $strPageError="Please enter your Delivery Surname where requested below."; else if (($bIsDeliverySame==false) and strlen($strDeliveryAddress1)==0) $strPageError="Please enter your Delivery Address Line 1 where requested below."; else if (($bIsDeliverySame==false) and strlen($strDeliveryCity)==0) $strPageError="Please enter your Delivery City where requested below."; else if (($bIsDeliverySame==false) and strlen($strDeliveryPostCode)==0) $strPageError="Please enter your Delivery Post Code where requested below."; else if (($bIsDeliverySame==false) and strlen($strDeliveryCountry)==0) $strPageError="Please select your Delivery Country where requested below."; else if (($bIsDeliverySame==false) and (strlen($strDeliveryState) == 0) and ($strDeliveryCountry == "US")) $strPageError="Please enter your State code as you have selected United States for delivery country."; else { //** All validations have passed, so store the details in the session ** $_SESSION["strBillingFirstnames"] = $strBillingFirstnames; $_SESSION["strBillingSurname"] = $strBillingSurname; $_SESSION["strBillingAddress1"] = $strBillingAddress1; $_SESSION["strBillingAddress2"] = $strBillingAddress2; $_SESSION["strBillingCity"] = $strBillingCity; $_SESSION["strBillingPostCode"] = $strBillingPostCode; $_SESSION["strBillingCountry"] = $strBillingCountry; $_SESSION["strBillingState"] = $strBillingState; $_SESSION["strBillingPhone"] = $strBillingPhone; $_SESSION["strCustomerEMail"] = $strCustomerEMail; $_SESSION["bIsDeliverySame"] = $bIsDeliverySame; if ($bIsDeliverySame == true) { $_SESSION["strDeliveryFirstnames"] = $strBillingFirstnames; $_SESSION["strDeliverySurname"] = $strBillingSurname; $_SESSION["strDeliveryAddress1"] = $strBillingAddress1; $_SESSION["strDeliveryAddress2"] = $strBillingAddress2; $_SESSION["strDeliveryCity"] = $strBillingCity; $_SESSION["strDeliveryPostCode"] = $strBillingPostCode; $_SESSION["strDeliveryCountry"] = $strBillingCountry; $_SESSION["strDeliveryState"] = $strBillingState; $_SESSION["strDeliveryPhone"] = $strBillingPhone; } else { $_SESSION["strDeliveryFirstnames"] = $strDeliveryFirstnames; $_SESSION["strDeliverySurname"] = $strDeliverySurname; $_SESSION["strDeliveryAddress1"] = $strDeliveryAddress1; $_SESSION["strDeliveryAddress2"] = $strDeliveryAddress2; $_SESSION["strDeliveryCity"] = $strDeliveryCity; $_SESSION["strDeliveryPostCode"] = $strDeliveryPostCode; $_SESSION["strDeliveryCountry"] = $strDeliveryCountry; $_SESSION["strDeliveryState"] = $strDeliveryState; $_SESSION["strDeliveryPhone"] = $strDeliveryPhone; } // We're all good, data has been written to the session // Now go to the order confirmation page ob_end_flush(); #echo "

sent to orderConfirmationPage page by fSagepay_CustomerDetails"; sagepay_redirect($SagePayDefaults['OrderConfirmationPage']); } } else { // this means they just arrived at the page, so it the details are in the session we can populate the form // Populate customer details from the session if they are there $strBillingFirstnames = $_SESSION["strBillingFirstnames"]; $strBillingSurname = $_SESSION["strBillingSurname"]; $strBillingAddress1 = $_SESSION["strBillingAddress1"]; $strBillingAddress2 = $_SESSION["strBillingAddress2"]; $strBillingCity = $_SESSION["strBillingCity"]; $strBillingPostCode = $_SESSION["strBillingPostCode"]; $strBillingCountry = $_SESSION["strBillingCountry"]; $strBillingState = $_SESSION["strBillingState"]; $strBillingPhone = $_SESSION["strBillingPhone"]; $strCustomerEMail = $_SESSION["strCustomerEMail"]; $bIsDeliverySame = $_SESSION["bIsDeliverySame"]; $strDeliveryFirstnames = $_SESSION["strDeliveryFirstnames"]; $strDeliverySurname = $_SESSION["strDeliverySurname"]; $strDeliveryAddress1 = $_SESSION["strDeliveryAddress1"]; $strDeliveryAddress2 = $_SESSION["strDeliveryAddress2"]; $strDeliveryCity = $_SESSION["strDeliveryCity"]; $strDeliveryPostCode = $_SESSION["strDeliveryPostCode"]; $strDeliveryCountry = $_SESSION["strDeliveryCountry"]; $strDeliveryState = $_SESSION["strDeliveryState"]; $strDeliveryPhone = $_SESSION["strDeliveryPhone"]; } // write from the session to local vars $strProductName = $_SESSION["strProductName"]; if (strlen($strProductName)==0) { // the session value is empty, so we'll read in the URL // Store the purchase info in a local var $strProductName = $_REQUEST["ProductName"]; // check it is not empty from the request, if it is, it means they have not bough anything yet // so we'll send them back home if (strlen($strProductName)==0) { #echo "

sent to welcomePage page by fSagepay_CustomerDetails, no strProductName"; sagepay_redirect($SagePayDefaults['welcomePage']); } // and in the session $_SESSION["strProductName"] = $strProductName; #echo "

session empty, got from request
"; } else { // it was in the session #echo "

session ok, saved to var
"; } // write from the session to local vars $strProductValue = $_SESSION["strProductValue"]; if (strlen($strProductValue)==0) { // the session value is empty, so we'll read in the URL // Store the purchase info in a local var $strProductValue = $_REQUEST["ProductValue"]; // check it is not empty from the request, if it is, it means they have not bough anything yet // so we'll send them back home if (strlen($strProductValue)==0) { #echo "

sent to welcomePage page by fSagepay_CustomerDetails, no strProductValue"; sagepay_redirect($SagePayDefaults['welcomePage']); } // and in the session $_SESSION["strProductValue"] = $strProductValue; #echo "

session empty, got from request
"; } else { // it was in the session #echo "

session ok, saved to var
"; } $output = "\n"; $output .= fSagepay_countrycodes(); $output .= " \n"; $output .= "\n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= "

\n"; $output .= "
Your Details
\n"; $output .= "
\n"; $output .= " Please complete the form below. Fields with an asterisk (*) are required.

\n"; $output .= " Purchase details: " . $strProductName . ", value " . $strProductValue . $SagePayDefaults['strCurrency'] .".
\n"; $output .= "
\n"; $output .= " \n"; $output .= " \n"; if (strlen($strPageError) > 0) { $output .= " \n"; $output .= " \n"; $output .= " \n"; } $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= "


\"Warning\"
" . $strPageError . "


Please enter your Billing details below
*First Name(s):
*Surname:
*Address Line 1:
Address Line 2:
*City:
*Post/Zip Code:
*Country:\n"; $output .= " \n"; $output .= "
State Code (U.S. only): (*State Code for U.S. customers only)
Phone:
*e-Mail Address:


Please enter your Delivery details below
Same as Billing Details?:
*First Name(s):
*Surname:
*Address Line 1:
Address Line 2:
*City:
*Post/Zip Code:
*Country:\n"; $output .= " \n"; $output .= "
State Code (U.S. only): (*State Code for U.S. customers only)
Phone:
\n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= "\n"; $output .= "
\n"; $output .= " \"Go\n"; $output .= "
\n"; $output .= "
\n"; $output .= "
\n"; $output .= "\n"; return Keep($output); } /**************************************************************************************************/ /* fSagepay_OrderConfirmation */ /**************************************************************************************************/ function fSagepay_OrderConfirmation($opts) { global $SagePayDefaults; // Check we have a billing address in the session. If not, go back to the customerDetails page to get one if (strlen($_SESSION["strBillingAddress1"])==0) { ob_end_flush(); sagepay_redirect($SagePayDefaults['welcomePage']); #echo "sent to welcomePage page by fSagepay_OrderConfirmation because no strBillingAddress1"; } // Check we have a strProductName in the session. If not, go back to the customerDetails page to get one if (strlen($_SESSION["strProductName"])==0) { ob_end_flush(); sagepay_redirect($SagePayDefaults['welcomePage']); #echo "sent to welcomePage page by fSagepay_OrderConfirmation because no strProductName"; } //** Gather customer details from the session ** $strCustomerEMail = $_SESSION["strCustomerEMail"]; $strBillingFirstnames = $_SESSION["strBillingFirstnames"]; $strBillingSurname = $_SESSION["strBillingSurname"]; $strBillingAddress1 = $_SESSION["strBillingAddress1"]; $strBillingAddress2 = $_SESSION["strBillingAddress2"]; $strBillingCity = $_SESSION["strBillingCity"]; $strBillingPostCode = $_SESSION["strBillingPostCode"]; $strBillingCountry = $_SESSION["strBillingCountry"]; $strBillingState = $_SESSION["strBillingState"]; $strBillingPhone = $_SESSION["strBillingPhone"]; $bIsDeliverySame = $_SESSION["bIsDeliverySame"]; $strDeliveryFirstnames = $_SESSION["strDeliveryFirstnames"]; $strDeliverySurname = $_SESSION["strDeliverySurname"]; $strDeliveryAddress1 = $_SESSION["strDeliveryAddress1"]; $strDeliveryAddress2 = $_SESSION["strDeliveryAddress2"]; $strDeliveryCity = $_SESSION["strDeliveryCity"]; $strDeliveryPostCode = $_SESSION["strDeliveryPostCode"]; $strDeliveryCountry = $_SESSION["strDeliveryCountry"]; $strDeliveryState = $_SESSION["strDeliveryState"]; $strDeliveryPhone = $_SESSION["strDeliveryPhone"]; $strProductName = $_SESSION["strProductName"]; $strProductValue = $_SESSION["strProductValue"]; /** Okay, build the crypt field for VSP Form using the information in our session ** *** First we need to generate a unique VendorTxCode for this transaction ** *** We're using VendorName, time stamp and a random element. You can use different methods if you wish ** *** but the VendorTxCode MUST be unique for each transaction you send to VSP Server **/ $intRandNum = rand(0,32000)*rand(0,32000); $strVendorTxCode = $SagePayDefaults['strVSPVendorName'] . $intRandNum; /* Now set the basket */ $sngTotal = number_format($strProductValue,2); $strBasket = "" . $strProductName . ":1:" . $sngTotal . ":-:" . $sngTotal . ":" . $sngTotal; // Now to build the VSP Form crypt field. For more details see the VSP Form Protocol 2.23 $strPost = "VendorTxCode=" . $strVendorTxCode; /** As generated above **/ // Optional: If you are a Protx Partner and wish to flag the transactions with your unique partner id, it should be passed here if (strlen($SagePayDefaults['strPartnerID']) > 0) $strPost = $strPost . "&ReferrerID=" . $SagePayDefaults['strPartnerID']; $strPost = $strPost . "&Amount=" . number_format($sngTotal,2); // Formatted to 2 decimal places with leading digit $strPost = $strPost . "&Currency=" . $SagePayDefaults['strCurrency']; // Up to 100 chars of free format description $strPost = $strPost . "&Description=" . $SagePayDefaults['strVendorDescription']; /* The SuccessURL is the page to which VSP Form returns the customer if the transaction is successful ** You can change this for each transaction, perhaps passing a session ID or state flag if you wish */ $strPost = $strPost . "&SuccessURL=" . $SagePayDefaults['strYourSiteFQDN'] . $SagePayDefaults['strVirtualDir'] . $SagePayDefaults['OrderSuccessfulPage']; /* The FailureURL is the page to which VSP Form returns the customer if the transaction is unsuccessful ** You can change this for each transaction, perhaps passing a session ID or state flag if you wish */ $strPost = $strPost . "&FailureURL=" . $SagePayDefaults['strYourSiteFQDN'] . $SagePayDefaults['strVirtualDir'] . $SagePayDefaults['OrderFailedPage']; // This is an Optional setting. Here we are just using the Billing names given. $strPost = $strPost . "&CustomerName=" . $strBillingFirstnames . " " . $strBillingSurname; if (strlen($strCustomerEMail) > 0) $strPost = $strPost . "&CustomerEMail=" . $strCustomerEMail; // This is an Optional setting if (($SagePayDefaults['strVendorEMail'] <> "[your e-mail address]") && ($SagePayDefaults['strVendorEMail'] <> "")) $strPost = $strPost . "&VendorEMail=" . $SagePayDefaults['strVendorEMail']; // This is an Optional setting $strPost=$strPost . "&eMailMessage="; // Billing Details: $strPost=$strPost . "&BillingFirstnames=" . $strBillingFirstnames; $strPost=$strPost . "&BillingSurname=" . $strBillingSurname; $strPost=$strPost . "&BillingAddress1=" . $strBillingAddress1; if (strlen($strBillingAddress2) > 0) $strPost=$strPost . "&BillingAddress2=" . $strBillingAddress2; $strPost=$strPost . "&BillingCity=" . $strBillingCity; $strPost=$strPost . "&BillingPostCode=" . $strBillingPostCode; $strPost=$strPost . "&BillingCountry=" . $strBillingCountry; if (strlen($strBillingState) > 0) $strPost=$strPost . "&BillingState=" . $strBillingState; if (strlen($strBillingPhone) > 0) $strPost=$strPost . "&BillingPhone=" . $strBillingPhone; // Delivery Details: $strPost=$strPost . "&DeliveryFirstnames=" . $strDeliveryFirstnames; $strPost=$strPost . "&DeliverySurname=" . $strDeliverySurname; $strPost=$strPost . "&DeliveryAddress1=" . $strDeliveryAddress1; if (strlen($strDeliveryAddress2) > 0) $strPost=$strPost . "&DeliveryAddress2=" . $strDeliveryAddress2; $strPost=$strPost . "&DeliveryCity=" . $strDeliveryCity; $strPost=$strPost . "&DeliveryPostCode=" . $strDeliveryPostCode; $strPost=$strPost . "&DeliveryCountry=" . $strDeliveryCountry; if (strlen($strDeliveryState) > 0) $strPost=$strPost . "&DeliveryState=" . $strDeliveryState; if (strlen($strDeliveryPhone) > 0) $strPost=$strPost . "&DeliveryPhone=" . $strDeliveryPhone; $strPost=$strPost . "&Basket=1:" . $strBasket; // As created above // For charities registered for Gift Aid, set to 1 to display the Gift Aid check box on the payment pages $strPost=$strPost . "&AllowGiftAid=0"; /* Allow fine control over AVS/CV2 checks and rules by changing this value. 0 is Default ** It can be changed dynamically, per transaction, if you wish. See the VSP Server Protocol document */ if ($SagePayDefaults['strTransactionType']!=="AUTHENTICATE") $strPost=$strPost . "&ApplyAVSCV2=0"; /* Allow fine control over 3D-Secure checks and rules by changing this value. 0 is Default ** It can be changed dynamically, per transaction, if you wish. See the VSP Server Protocol document */ $strPost=$strPost . "&Apply3DSecure=0"; // Encrypt the plaintext string for inclusion in the hidden field $strCrypt = base64Encode(SimpleXor($strPost,$SagePayDefaults['strEncryptionPassword'])); $output = "\n"; $output .= fSagepay_countrycodes(); $output .= "
Review And Confirm Your Order
\n"; $output .= "
\n"; $output .= "

Please review purchases and contact details before payment.\n"; $output .= " Payment is via SagePay secure payment gateway, Sage is one of the UK most trusted business brands,\n"; $output .= " click here more details.\n"; $output .= " For guaranteed security, we do not store card numbers.
\n"; $output .= "
\n"; if ($SagePayDefaults['strConnectTo']!=="LIVE") { $output .= "

\n"; $output .= " Because you are in " . $SagePayDefaults['strConnectTo'] . " mode, the unencrypted contents of the crypt field are also\n"; $output .= " displayed below, allowing you to check the contents. When you are in Live mode, you will only\n"; $output .= " see the order confirmation boxes.\n"; } $output .= "

\n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= "


Your Order
TitlePrice
". $strProductName ."". $strProductValue ."
Total:" . number_format($strProductValue,2) . " " . $SagePayDefaults['strCurrency'] . "
\n"; $output .= "
\n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= "
Your Billing Details
Name:" . $strBillingFirstnames . " " . $strBillingSurname . "
Address Details:\n"; $output .= " " . $strBillingAddress1 . "
\n"; if (strlen(strBillingAddress2)>0) $output .= " " . $strBillingAddress2 . "
\n"; $output .= " " . $strBillingCity . " \n"; if (strlen(strBillingState)>0) $output .= " " . $strBillingState . "
\n"; $output .= " " . $strBillingPostCode . "
\n"; $output .= " \n"; $output .= "
Phone Number:" . $strBillingPhone . " 
e-Mail Address:" . $strCustomerEMail . " 
\n"; $output .= "
\n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= "
Your Delivery Details
Name:" . $strDeliveryFirstnames . " " . $strDeliverySurname . "
Address Details:\n"; $output .= " " . $strDeliveryAddress1 . "
\n"; if (strlen($strDeliveryAddress2)>0) $output .= " " . $strDeliveryAddress2 . "
\n"; $output .= " " . $strDeliveryCity . " \n"; if (strlen($strDeliveryState)>0) $output .= " " . $strDeliveryState . "
\n"; $output .= " " . $strDeliveryPostCode . "
\n"; $output .= " \n"; $output .= "
Phone Number:" . $strDeliveryPhone . " 
\n"; $output .= "
\n"; if ( $SagePayDefaults['strConnectTo'] !== "LIVE" ) { $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= "
Your VSP Form Crypt Post Contents
The box below shows the unencrypted contents of the VSP Form\n"; $output .= " Crypt field. This will not be displayed in LIVE mode. If you wish to view the encrypted and encoded\n"; $output .= " contents view the source of this page and scroll to the bottom. You'll find the submission FORM there.\n"; $output .= "
Note: this long string will cause layout problems in some browsers.
" . $strPost . "
\n"; } $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= "
"; $output .= " \"Go\n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= "
\n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= "
\n"; $output .= " \n"; $output .= "
\n"; $output .= "\n"; $output .= "\n\n"; return Keep($output); } /**************************************************************************************************/ /* fSagepay_OrderSuccessful */ /**************************************************************************************************/ function fSagepay_OrderSuccessful($opts) { global $SagePayDefaults; // Check for the proceed button click, and if so, go to the buildOrder page if ($_REQUEST["navigate"]=="proceed") { ob_end_flush(); // sagepay_redirect to next page sagepay_redirect($SagePayDefaults['welcomePage']); } // Now check we have a Crypt field passed to this page $strCrypt=$_REQUEST["crypt"]; if (strlen($strCrypt)==0) { ob_end_flush(); sagepay_redirect($SagePayDefaults['welcomePage']); } // Now decode the Crypt field and extract the results $strDecoded=simpleXor(Base64Decode($strCrypt),$SagePayDefaults['strEncryptionPassword']); $values = getToken($strDecoded); // Split out the useful information into variables we can use $strStatus=$values['Status']; $strStatusDetail=$values['StatusDetail']; $strVendorTxCode=$values["VendorTxCode"]; $strVPSTxId=$values["VPSTxId"]; $strTxAuthNo=$values["TxAuthNo"]; $strAmount=$values["Amount"]; $strAVSCV2=$values["AVSCV2"]; $strAddressResult=$values["AddressResult"]; $strPostCodeResult=$values["PostCodeResult"]; $strCV2Result=$values["CV2Result"]; $strGiftAid=$values["GiftAid"]; $str3DSecureStatus=$values["3DSecureStatus"]; $strCAVV=$values["CAVV"]; $strCardType=$values["CardType"]; $strLast4Digits=$values["Last4Digits"]; $strAddressStatus=$values["AddressStatus"]; // PayPal transactions only $strPayerStatus=$values["PayerStatus"]; // PayPal transactions only // values from the session $strCustomerEMail = $_SESSION["strCustomerEMail"]; $strBillingFirstnames = $_SESSION["strBillingFirstnames"]; $strBillingSurname = $_SESSION["strBillingSurname"]; $strBillingAddress1 = $_SESSION["strBillingAddress1"]; $strBillingAddress2 = $_SESSION["strBillingAddress2"]; $strBillingCity = $_SESSION["strBillingCity"]; $strBillingPostCode = $_SESSION["strBillingPostCode"]; $strBillingCountry = $_SESSION["strBillingCountry"]; $strBillingState = $_SESSION["strBillingState"]; $strBillingPhone = $_SESSION["strBillingPhone"]; $bIsDeliverySame = $_SESSION["bIsDeliverySame"]; $strDeliveryFirstnames = $_SESSION["strDeliveryFirstnames"]; $strDeliverySurname = $_SESSION["strDeliverySurname"]; $strDeliveryAddress1 = $_SESSION["strDeliveryAddress1"]; $strDeliveryAddress2 = $_SESSION["strDeliveryAddress2"]; $strDeliveryCity = $_SESSION["strDeliveryCity"]; $strDeliveryPostCode = $_SESSION["strDeliveryPostCode"]; $strDeliveryCountry = $_SESSION["strDeliveryCountry"]; $strDeliveryState = $_SESSION["strDeliveryState"]; $strDeliveryPhone = $_SESSION["strDeliveryPhone"]; $strProductName = $_SESSION["strProductName"]; $strProductValue = $_SESSION["strProductValue"]; // Empty the cart, we're done with it now because the order is successful $_SESSION["strProductValue"] = ""; $_SESSION["strProductName"] = ""; $output = "\n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= "

\n"; $output .= "
\"Success\"
Your order has been Successful

\n"; $output .= " Your transaction has completed successfully, thank you for your order.
\n"; $output .= "
\n"; $output .= " Your order reference number is: " . $strVendorTxCode . "
\n"; $output .= "
\n"; $output .= " You should quote this in all correspondence with " . $SagePayDefaults['strVendorDescription'] . ".
\n"; $output .= "
\n"; if ($SagePayDefaults['strConnectTo']!=="LIVE") { $output .= "\n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= "
Details sent back by VSP Form
VendorTxCode:" . $strVendorTxCode . "
Status:" . $strStatus . "
StatusDetail:" . $strStatusDetail . "
Amount:" . $strAmount . " " . $SagePayDefaults['strCurrency'] . "
VPSTxId:" . $strVPSTxId . "
VPSAuthCode (TxAuthNo):" . $strTxAuthNo . "
AVSCV2 Results:" . $strAVSCV2 . " - Address:" . $strAddressResult . ", Post Code:" . $strPostCodeResult . ", CV2:" . $strCV2Result . "
Gift Aid Transaction?:\n"; if ($strGiftAid=="1") { $output .= " Yes\n"; } else { $output .= " No\n"; } $output .= "  
3D-Secure Status:" . $str3DSecureStatus ."
CAVV:" . $strCAVV . "
CardType:" . $strCardType . "
Last4Digits:" . $strLast4Digits . "
AddressStatus:*PayPal transactions only" . $strAddressStatus . "
PayerStatus:*PayPal transactions only" . $strPayerStatus . "
\n"; } $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= "
Click Home to go back to the Home Page to start another transaction.
\n"; $output .= " \"Click\n"; $output .= "
\n"; $output .= "
\n"; $output .= "\n"; $output .= "\n\n"; /* Email for Successful Transaction */ $to = $SagePayDefaults['strVendorEMail']; $subject = "Payment Successful"; $headers = "From:" . $SagePayDefaults['strVendorEMail'] . " \r\n" . "X-Mailer: php"; $body = "PAYMENT SUCCESSFUL.\r\n\r\nTransaction Details:\r\n\r\n"; $body .= "Customer Ref: " . $strVendorTxCode . "\r\n"; $body .= "\r\n"; $body .= "Customer Name: " . $strBillingFirstnames . " ". $strBillingSurname ."\r\n"; $body .= "Customer eMail: " . $strCustomerEMail . "\r\n"; $body .= "Billing First names: " . $strBillingFirstnames . "\r\n"; $body .= "Billing Surname: " . $strBillingSurname . "\r\n"; $body .= "Billing Address 1: " . $strBillingAddress1 . "\r\n"; $body .= "Billing Address 2: " . $strBillingAddress2 . "\r\n"; $body .= "Billing City: " . $strBillingCity . "\r\n"; $body .= "Billing Post Code: " . $strBillingPostCode . "\r\n"; $body .= "Billing Country: " . $strBillingCountry . "\r\n"; $body .= "Billing State: " . $strBillingState . "\r\n"; $body .= "Billing Phone: " . $strBillingPhone . "\r\n"; $body .= "Delivery First names: " . $strDeliveryFirstnames . "\r\n"; $body .= "Delivery Surname: " . $strDeliverySurname . "\r\n"; $body .= "Delivery Address 1: " . $strDeliveryAddress1 . "\r\n"; $body .= "Delivery Address 2: " . $strDeliveryAddress2 . "\r\n"; $body .= "Delivery City: " . $strDeliveryCity . "\r\n"; $body .= "Delivery Post Code: " . $strDeliveryPostCode . "\r\n"; $body .= "Delivery Country: " . $strDeliveryCountry . "\r\n"; $body .= "Delivery State: " . $strDeliveryState . "\r\n"; $body .= "Delivery Phone: " . $strDeliveryPhone . "\r\n"; $body .= "\r\n"; $body .= "Product Name: " . $strProductName . "\r\n"; $body .= "Product Value: " . $strProductValue . "\r\n"; $body .= "\r\n"; $body .= "Status: " . $strStatus . "\r\n"; $body .= "StatusDetail: " . $strStatusDetail . "\r\n"; $body .= "Amount: " . $strAmount . "\r\n"; $body .= "VPSTxId: " . $strVPSTxId . "\r\n"; $body .= "TxAuthNo: " . $strTxAuthNo . "\r\n"; $body .= "AVSCV2 Results: " . $strAVSCV2 . ". - Address:" . $strAddressResult . ", Post Code:" . $strPostCodeResult . ", CV2:" . $strCV2Result . "\r\n"; $body .= "Gift Aid: " . $strGiftAid . ", 1=yes, 0=no\r\n"; $body .= "3D-Secure Status: " . $str3DSecureStatus . "\r\n"; $body .= "CAVV: " . $strCAVV . "\r\n"; $body .= "CardType: " . $strCardType . "\r\n"; $body .= "Last4Digits: " . $strLast4Digits . "\r\n"; $body .= "AddressStatus: " . $strAddressStatus . ", (PayPal transactions only)\r\n"; $body .= "PayerStatus: " . $PayerStatus . ", (PayPal transactions only)\r\n"; $body .= "Date and time: " . date('h:i:s A, l jS \of F Y') . "\r\n"; if (mail($to, $subject, $body, $headers)) { #echo "Message sent
"; } else { #echo "Message failed
"; } #echo "Content:
" . $body . ".

"; return Keep($output); } /**************************************************************************************************/ /* fSagepay_OrderFailed */ /**************************************************************************************************/ function fSagepay_OrderFailed($opts) { global $SagePayDefaults; // Check for the proceed button click, and if so, go to the buildOrder page if ($_REQUEST["navigate"]=="proceed") { ob_end_flush(); // sagepay_redirect to next page sagepay_redirect($SagePayDefaults['welcomePage']); } // Now check we have a Crypt field passed to this page $strCrypt=$_REQUEST["crypt"]; if (strlen($strCrypt)==0) { ob_end_flush(); sagepay_redirect($SagePayDefaults['welcomePage']); } // Now decode the Crypt field and extract the results $strDecoded=simpleXor(Base64Decode($strCrypt),$SagePayDefaults['strEncryptionPassword']); $values = getToken($strDecoded); // Split out the useful information into variables we can use $strStatus=$values['Status']; $strStatusDetail=$values['StatusDetail']; $strVendorTxCode=$values["VendorTxCode"]; $strVPSTxId=$values["VPSTxId"]; $strTxAuthNo=$values["TxAuthNo"]; $strAmount=$values["Amount"]; $strAVSCV2=$values["AVSCV2"]; $strAddressResult=$values["AddressResult"]; $strPostCodeResult=$values["PostCodeResult"]; $strCV2Result=$values["CV2Result"]; $strGiftAid=$values["GiftAid"]; $str3DSecureStatus=$values["3DSecureStatus"]; $strCAVV=$values["CAVV"]; $strCardType=$values["CardType"]; $strLast4Digits=$values["Last4Digits"]; $strAddressStatus=$values["AddressStatus"]; // PayPal transactions only $strPayerStatus=$values["PayerStatus"]; // PayPal transactions only // values from the session $strCustomerEMail = $_SESSION["strCustomerEMail"]; $strBillingFirstnames = $_SESSION["strBillingFirstnames"]; $strBillingSurname = $_SESSION["strBillingSurname"]; $strBillingAddress1 = $_SESSION["strBillingAddress1"]; $strBillingAddress2 = $_SESSION["strBillingAddress2"]; $strBillingCity = $_SESSION["strBillingCity"]; $strBillingPostCode = $_SESSION["strBillingPostCode"]; $strBillingCountry = $_SESSION["strBillingCountry"]; $strBillingState = $_SESSION["strBillingState"]; $strBillingPhone = $_SESSION["strBillingPhone"]; $bIsDeliverySame = $_SESSION["bIsDeliverySame"]; $strDeliveryFirstnames = $_SESSION["strDeliveryFirstnames"]; $strDeliverySurname = $_SESSION["strDeliverySurname"]; $strDeliveryAddress1 = $_SESSION["strDeliveryAddress1"]; $strDeliveryAddress2 = $_SESSION["strDeliveryAddress2"]; $strDeliveryCity = $_SESSION["strDeliveryCity"]; $strDeliveryPostCode = $_SESSION["strDeliveryPostCode"]; $strDeliveryCountry = $_SESSION["strDeliveryCountry"]; $strDeliveryState = $_SESSION["strDeliveryState"]; $strDeliveryPhone = $_SESSION["strDeliveryPhone"]; $strProductName = $_SESSION["strProductName"]; $strProductValue = $_SESSION["strProductValue"]; // Empty the cart, we're done with it now because the order is successful $_SESSION["strProductValue"] = ""; $_SESSION["strProductName"] = ""; // Determine the reason this transaction was unsuccessful if ($strStatus=="NOTAUTHED") $strReason="You payment was declined by the bank. This could be due to insufficient funds, or incorrect card details. ".$SagePayDefaults['strVendorContactBlurb']; else if ($strStatus=="ABORT") $strReason="You chose to Cancel your order on the payment pages. If you wish to change your order and resubmit it you can do so here. ".$SagePayDefaults['strVendorContactBlurb']; else if ($strStatus=="REJECTED") $strReason="Your order did not meet our minimum fraud screening requirements. If you have questions about our fraud screening rules, or wish to contact us to discuss this. ".$SagePayDefaults['strVendorContactBlurb']; else if ($strStatus=="INVALID" or strStatus=="MALFORMED") $strReason="We could not process your order because we have been unable to register your transaction with our Payment Gateway. " . $SagePayDefaults['strVendorContactBlurb']; else if ($strStatus=="ERROR") $strReason="We could not process your order because our Payment Gateway service was experiencing difficulties. " . $SagePayDefaults['strVendorContactBlurb']; else $strReason="The transaction process failed. Please contact us with the date and time of your order and we will investigate." . $SagePayDefaults['strVendorContactBlurb']; $output = "\n"; $output .= "\n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " "; $output .= " "; $output .= "

\n"; $output .= "
\"Error\"
Your order has NOT been successful

\n"; $output .= " Sorry, your transaction did not complete successfully for the following reason: \n"; $output .= " " . $strReason . "
\n"; $output .= "
\n"; $output .= " Your order reference number is: " . $strVendorTxCode . "\n"; $output .= "

\n"; $output .= " You should quote this in all correspondence with " . $SagePayDefaults['strVendorDescription'] . ".
\n"; $output .= "
\n"; if ($SagePayDefaults['strConnectTo']!=="LIVE") { $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= "
Details sent back by VSP Form
VendorTxCode:" . $strVendorTxCode . " 
Status:" . $strStatus . " 
StatusDetail:" . $strStatusDetail . " 
Amount:" . $strAmount . " " . $SagePayDefaults['strCurrency'] . " 
VPSTxId:" . $strVPSTxId . " 
VPSAuthCode (TxAuthNo):" . $strTxAuthNo . " 
AVSCV2 Results:" . $strAVSCV2 . " - Address:" . $strAddressResult . ", Post Code:" . $strPostCodeResult . ", CV2:" . $strCV2Result . "
Gift Aid Transaction?:"; if ($strGiftAid=="1") { $output .= "Yes"; } else { $output .= "No"; } $output .= "
3D-Secure Status:" . $str3DSecureStatus ." 
CAVV:" . $strCAVV . " 
CardType:" . $strCardType . "
Last4Digits:" . $strLast4Digits . "
AddressStatus:*PayPal transactions only" . $strAddressStatus . "
PayerStatus: *PayPal transactions only" . $strPayerStatus . "
"; } $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= " "; $output .= "
Click Home to go back to the Welcome Page to start another transaction.
\"Click
"; $output .= "
"; $output .= "\n"; $output .= "\n\n"; /* Email for failed Transaction */ $to = $SagePayDefaults['strVendorEMail']; $subject = "Payment Failed"; $headers = "From:" . $SagePayDefaults['strVendorEMail'] . " \r\n" . "X-Mailer: php"; $body = "PAYMENT FAILED.\r\n\r\nTransaction Details:\r\n\r\n"; $body .= "Customer Ref: " . $strVendorTxCode . "\r\n"; $body .= "\r\n"; $body .= "Customer Name: " . $strBillingFirstnames . " ". $strBillingSurname ."\r\n"; $body .= "Customer eMail: " . $strCustomerEMail . "\r\n"; $body .= "Billing First names: " . $strBillingFirstnames . "\r\n"; $body .= "Billing Surname: " . $strBillingSurname . "\r\n"; $body .= "Billing Address 1: " . $strBillingAddress1 . "\r\n"; $body .= "Billing Address 2: " . $strBillingAddress2 . "\r\n"; $body .= "Billing City: " . $strBillingCity . "\r\n"; $body .= "Billing Post Code: " . $strBillingPostCode . "\r\n"; $body .= "Billing Country: " . $strBillingCountry . "\r\n"; $body .= "Billing State: " . $strBillingState . "\r\n"; $body .= "Billing Phone: " . $strBillingPhone . "\r\n"; $body .= "Delivery First names: " . $strDeliveryFirstnames . "\r\n"; $body .= "Delivery Surname: " . $strDeliverySurname . "\r\n"; $body .= "Delivery Address 1: " . $strDeliveryAddress1 . "\r\n"; $body .= "Delivery Address 2: " . $strDeliveryAddress2 . "\r\n"; $body .= "Delivery City: " . $strDeliveryCity . "\r\n"; $body .= "Delivery Post Code: " . $strDeliveryPostCode . "\r\n"; $body .= "Delivery Country: " . $strDeliveryCountry . "\r\n"; $body .= "Delivery State: " . $strDeliveryState . "\r\n"; $body .= "Delivery Phone: " . $strDeliveryPhone . "\r\n"; $body .= "\r\n"; $body .= "Product Name: " . $strProductName . "\r\n"; $body .= "Product Value: " . $strProductValue . "\r\n"; $body .= "\r\n"; $body .= "Status: " . $strStatus . "\r\n"; $body .= "StatusDetail: " . $strStatusDetail . "\r\n"; $body .= "Amount: " . $strAmount . "\r\n"; $body .= "VPSTxId: " . $strVPSTxId . "\r\n"; $body .= "TxAuthNo: " . $strTxAuthNo . "\r\n"; $body .= "AVSCV2 Results: " . $strAVSCV2 . ". - Address:" . $strAddressResult . ", Post Code:" . $strPostCodeResult . ", CV2:" . $strCV2Result . "\r\n"; $body .= "Gift Aid: " . $strGiftAid . ", 1=yes, 0=no\r\n"; $body .= "3D-Secure Status: " . $str3DSecureStatus . "\r\n"; $body .= "CAVV: " . $strCAVV . "\r\n"; $body .= "CardType: " . $strCardType . "\r\n"; $body .= "Last4Digits: " . $strLast4Digits . "\r\n"; $body .= "AddressStatus: " . $strAddressStatus . ", (PayPal transactions only)\r\n"; $body .= "PayerStatus: " . $PayerStatus . ", (PayPal transactions only)\r\n"; $body .= "Date and time: " . date('h:i:s A, l jS \of F Y') . "\r\n"; if (mail($to, $subject, $body, $headers)) { #echo "Message sent
"; } else { #echo "Message failed
"; } #echo "Content:
" . $body . ".

"; return Keep($output); }