Zen Follower
- Join Date:
- Dec 2005
- Posts:
- 451
- Plugin Contributions:
- 0
Protx Form for 1.2.7 - not pulling Delivery details for 1.3.7
I am trying to fix the Protx Form for 1.2.7 to work on 1.3.7
From my testing the Delivery address, postcode fields are not being pulled from the $order string, I have looked at the other payment modules and they are still using the same field names.
But yet all the other fields and working fine eg billing.
I don't know what has changed in the checkout process from 1.2.7 to 1.3.7, Any advice would be appreciated or pointers in the right direction.
<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003 The zen-cart developers |
// | |
// | http://www.zen-cart.com/index.php |
// | |
// | Portions Copyright (c) 2003 osCommerce |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | http://www.zen-cart.com/license/2_0.txt. |
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to |
// | [email protected] so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// $Id: protx_form.php,v 1.1 2004/08/11 20:45:00 networkdad Exp $
//
class protx_form {
var $code, $title, $description, $enabled;
// class constructor
function protx_form() {
global $order;
$this->code = 'protx_form';
$this->title = MODULE_PAYMENT_PROTX_FORM_TEXT_TITLE;
$this->description = MODULE_PAYMENT_PROTX_FORM_TEXT_DESCRIPTION;
$this->enabled = ((MODULE_PAYMENT_PROTX_FORM_STATUS == 'True') ? true : false);
$this->sort_order = MODULE_PAYMENT_PROTX_FORM_SORT_ORDER;
if ((int)MODULE_PAYMENT_PROTX_FORM_ORDER_STATUS_ID > 0) {
$this->order_status = MODULE_PAYMENT_PROTX_FORM_ORDER_STATUS_ID;
}
if (is_object($order)) $this->update_status();
if (MODULE_PAYMENT_PROTX_FORM_TEST_STATUS == 'true') {
$this->form_action_url = 'https://ukvpstest.protx.com/vps2form/submit.asp';
} else {
$this->form_action_url = 'https://ukvps.protx.com/vps2form/submit.asp';
}
}
// class methods
function update_status() {
global $order, $db;
if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_PROTX_FORM_ZONE > 0) ) {
$check_flag = false;
$check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" .
MODULE_PAYMENT_PROTX_FORM_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
while (!$check->EOF) {
if ($check->fields['zone_id'] < 1) {
$check_flag = true;
break;
} elseif ($check->fields['zone_id'] == $order->billing['zone_id']) {
$check_flag = true;
break;
}
$check->MoveNext();
}
if ($check_flag == false) {
$this->enabled = false;
}
}
}
function javascript_validation() {
return false;
}
function simpleXor($InString, $Key) {
$KeyList = array();
$output = "";
for($i = 0; $i < strlen($Key); $i++){
$KeyList[$i] = ord(substr($Key, $i, 1));
}
for($i = 0; $i < strlen($InString); $i++) {
$output.= chr(ord(substr($InString, $i, 1)) ^ ($KeyList[$i % strlen($Key)]));
}
return $output;
}
function getToken($thisString) {
$Tokens = array("Status","StatusDetail","VendorTxCode","VPSTxID","TxAuthNo","Amount","AVSCV2");
$output = array();
$resultArray = array();
for ($i = count($Tokens)-1; $i >= 0 ; $i--){
$start = strpos($thisString, $Tokens[$i]);
if ($start !== false){
$resultArray[$i]->start = $start;
$resultArray[$i]->token = $Tokens[$i];
}
}
sort($resultArray);
for ($i = 0; $i<count($resultArray); $i++){
$valueStart = $resultArray[$i]->start + strlen($resultArray[$i]->token) + 1;
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 $output;
}
function selection() {
return array('id' => $this->code,
'module' => $this->title);
}
function pre_confirmation_check() {
return false;
}
function confirmation() {
return false;
}
function process_button() {
global $order, $currencies, $currency;
switch (MODULE_PAYMENT_PROTX_FORM_CURRENCY) {
case 'Default Currency':
$protx_currency = DEFAULT_CURRENCY;
break;
case 'Any Currency':
default:
$protx_currency = $currency;
break;
}
$plain = "VendorTxCode=" . date('Ymdhis') . "&";
$plain .= "Amount=" . number_format($order->info['total'] * $currencies->get_value($protx_currency),
$currencies->get_decimal_places($protx_currency)) . "&";
$plain .= "Currency=" . $protx_currency . "&";
$plain .= "Description='' &";
$plain .= "SuccessURL=" . zen_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL', true) . "&";
$plain .= "FailureURL=" . zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true) . "&";
$plain .= "CustomerName=" . $order->billing['firstname'] . ' ' . $order->billing['lastname'] . "&";
$plain .= "CustomerEmail=" . $order->customer['email_address'] . "&";
$plain .= "VendorEMail=" . STORE_OWNER_EMAIL_ADDRESS . "& \n";
// $plain .= "eMailMessage=''&";
$plain .= "DeliveryAddress=" . $order->delivery['street_address']. "\n" .
$order->delivery['suburb'] . "\n" .
$order->delivery['city'] . "\n" .
$order->delivery['state'] . "\n" .
$order->delivery['country']['title'] . "&";
$plain .= "DeliveryPostCode=" . $order->delivery['postcode'] . "&";
$plain .= "BillingAddress=" . $order->billing['street_address'] . "\n" .
$order->billing['suburb'] . "\n" .
$order->billing['city'] . "\n" .
$order->billing['state'] . "\n" .
$order->billing['country']['title'] ."&";
$plain .= "BillingPostCode=" . $order->billing['postcode'] . "&";
$plain .= "ContactNumber=" . $order->customer['telephone'] . "&";
$plain .= "ContactFax=" . $order->customer['telephone'] . "&";
$plain .= "AllowGiftAid='0'&";
$plain .= "ApplyAVSCV2='0'&";
$plain .= "Apply3DSecure='0'&";
// For Testing to print file format to txt file
$file_loco = "protx.txt";
$file_handle = fopen($file_loco,'w');
fwrite($file_handle,$plain);
fclose($file_handle);
// eof testing
$crypt = base64_encode($this->SimpleXor($plain, MODULE_PAYMENT_PROTX_FORM_PASSWORD));
//// PA Evers Added for Pre-Authorisation selection
if (MODULE_PAYMENT_PROTX_FORM_PREAUTH == 'true') {
$transaction_type = 'PREAUTH';
} else {
$transaction_type = 'PAYMENT';
}
//// EOF: PA Evers Added for Pre-Authorisation selection
$process_button_string = zen_draw_hidden_field('VPSProtocol', '2.22') .
// zen_draw_hidden_field('TxType', 'PAYMENT') . // CHANGED FOR PRE-AUTH BELOW
zen_draw_hidden_field('TxType', $transaction_type) .
zen_draw_hidden_field('Vendor', MODULE_PAYMENT_PROTX_FORM_VENDOR_NAME) .
zen_draw_hidden_field('Crypt', $crypt);
return $process_button_string;
}
function before_process() {
global $_POST, $crypt;
if (is_null($crypt)) {
$crypt = $_GET['crypt'];
}
$Decoded = $this->SimpleXor(base64_decode($crypt),MODULE_PAYMENT_PROTX_FORM_PASSWORD);
$values = $this->getToken($Decoded);
$Status = $values['Status'];
$StatusDetail = $values['StatusDetail'];
if ($Status != 'OK') {
zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, zen_session_name() . '=' . $_POST[zen_session_name()] .
'&error_message=' . urlencode($StatusDetail), 'SSL', false, false));
}
}
function after_process() {
return false;
}
function get_error() {
global $_GET;
if (isset($_GET['message']) && (strlen($_GET['message']) > 0)) {
$error = stripslashes(urldecode($_GET['message']));
} else {
$error = MODULE_PAYMENT_PROTX_FORM_TEXT_ERROR_MESSAGE;
}
return array('title' => MODULE_PAYMENT_PROTX_FORM_TEXT_ERROR,
'error' => $error);
}
function check() {
global $db;
if (!isset($this->_check)) {
$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key =
'MODULE_PAYMENT_PROTX_FORM_STATUS'");
$this->_check = $check_query->RecordCount();
}
return $this->_check;
}
function install() {
global $db;
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value,
configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Protx Form Module',
'MODULE_PAYMENT_PROTX_FORM_STATUS', 'True', 'Do you want to accept Protx Form payments?', '6', '1',
'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value,
configuration_description, configuration_group_id, sort_order, date_added) values ('Merchant ID',
'MODULE_PAYMENT_PROTX_FORM_VENDOR_NAME', 'testvendor', 'Vendor Name to use with the Protx Form service', '6', '2', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value,
configuration_description, configuration_group_id, sort_order, date_added) values ('Password',
'MODULE_PAYMENT_PROTX_FORM_PASSWORD', 'testvendor', 'Password to use with the Protx Form service', '6', '2', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value,
configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Transaction Mode',
'MODULE_PAYMENT_PROTX_FORM_TEST_STATUS', 'true', 'Use Test Mode?', '6', '4', 'zen_cfg_select_option(array(\'true\',
\'false\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value,
configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Use Pre-Authorisation',
'MODULE_PAYMENT_PROTX_FORM_PREAUTH', 'true', 'Use Pre-Authorisation for all transactions?', '6', '5',
'zen_cfg_select_option(array(\'true\', \'false\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value,
configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Transaction Currency',
'MODULE_PAYMENT_PROTX_FORM_CURRENCY', 'Any Currency', 'The currency to use for credit card transactions', '6', '3',
'zen_cfg_select_option(array(\'Any Currency\', \'Default Currency\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value,
configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.',
'MODULE_PAYMENT_PROTX_FORM_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value,
configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Payment
Zone', 'MODULE_PAYMENT_PROTX_FORM_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6',
'2', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value,
configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Order
Status', 'MODULE_PAYMENT_PROTX_FORM_ORDER_STATUS_ID', '0', 'Set the status of orders made with this payment module to this
value', '6', '0', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");
}
function remove() {
global $db;
$db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) .
"')");
}
function keys() {
return array('MODULE_PAYMENT_PROTX_FORM_STATUS', 'MODULE_PAYMENT_PROTX_FORM_VENDOR_NAME',
'MODULE_PAYMENT_PROTX_FORM_PASSWORD', 'MODULE_PAYMENT_PROTX_FORM_TEST_STATUS', 'MODULE_PAYMENT_PROTX_FORM_PREAUTH',
'MODULE_PAYMENT_PROTX_FORM_CURRENCY', 'MODULE_PAYMENT_PROTX_FORM_SORT_ORDER', 'MODULE_PAYMENT_PROTX_FORM_ZONE',
'MODULE_PAYMENT_PROTX_FORM_ORDER_STATUS_ID');
}
}
?>
File output to Protx before encryption
VendorTxCode=20070506080217&Amount=109.82&Currency=GBP&Description=''
&SuccessURL=http://localhost/zen-cart-v1.3.7-full-fileset-12302006/index.php?main_page=checkout_process
&FailureURL=http://localhost/zen-cart-v1.3.7-full-fileset-12302006/index.php?main_page=checkout_payment&
CustomerName=jjj kkk&CustomerEmail=[email protected]&VendorEMail=[email protected]&
DeliveryAddress=&DeliveryPostCode=&BillingAddress=100 high street
town
county
United Kingdom&BillingPostCode=dn1 5pu&ContactNumber=0123456789&ContactFax=0123456789
&AllowGiftAid='0'&ApplyAVSCV2='0'&Apply3DSecure='0'&