Code:
<?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: EPDQ_form.php,v 1.1 2005/03/08 10:20:00 jennweir
//
class epdq_form {
var $code, $title, $description, $enabled;
// class constructor
function epdq_form() {
global $order;
$this->code = 'epdq_form';
$this->title = MODULE_PAYMENT_EPDQ_FORM_TEXT_TITLE;
$this->description = MODULE_PAYMENT_EPDQ_FORM_TEXT_DESCRIPTION;
$this->enabled = ((MODULE_PAYMENT_EPDQ_FORM_STATUS == 'True') ? true : false);
$this->sort_order = MODULE_PAYMENT_EPDQ_FORM_SORT_ORDER;
if ((int)MODULE_PAYMENT_EPDQ_FORM_ORDER_STATUS_ID > 0) {
$this->order_status = MODULE_PAYMENT_EPDQ_FORM_ORDER_STATUS_ID;
}
if (is_object($order)) $this->update_status();
$this->form_action_url = 'https://secure2.epdq.co.uk/cgi-bin/CcxBarclaysEpdq.e';
}
// class methods
function update_status() {
global $order, $db;
if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_EPDQ_FORM_ZONE > 0) ) {
$check_flag = false;
$check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_EPDQ_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 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, $order_total_modules;
//barclays requires us to send them the order id encrypted
//so we have to save this order in a pending state prior to posting the form to them.
$order_totals = $order_total_modules->pre_confirmation_check();
$order_totals = $order_total_modules->process();
$new_order_id = $order->create($order_totals);
$order->create_add_products($new_order_id, 2);
switch (MODULE_PAYMENT_EPDQ_FORM_CURRENCY) {
case 'Default Currency':
$EPDQ_currency = DEFAULT_CURRENCY;
break;
case 'Any Currency':
default:
$EPDQ_currency = $currency;
break;
}
#the following function performs a HTTP Post and returns the whole response
function pullpage( $host, $usepath, $postdata = "" ) {
# open socket to filehandle(epdq encryption cgi)
$fp = fsockopen( $host, 80, &$errno, &$errstr, 60 );
#check that the socket has been opened successfully
if( !$fp ) {
print "$errstr ($errno)<br>\n";
}
else {
#write the data to the encryption cgi
fputs( $fp, "POST $usepath HTTP/1.0\n");
$strlength = strlen( $postdata );
fputs( $fp, "Content-type: application/x-www-form-urlencoded\n" );
fputs( $fp, "Content-length: ".$strlength."\n\n" );
fputs( $fp, $postdata."\n\n" );
#clear the response data
$output = "";
#read the response from the remote cgi
#while content exists, keep retrieving document in 1K chunks
while( !feof( $fp ) ) {
$output .= fgets( $fp, 1024);
}
#close the socket connection
fclose( $fp);
}
#return the response
return $output;
}
#define the remote cgi in readiness to call pullpage function
$server="secure2.epdq.co.uk";
$url="/cgi-bin/CcxBarclaysEpdqEncTool.e";
$currencycode = 826;
$passphrase = MODULE_PAYMENT_EPDQ_FORM_PASSWORD;
$clientid = MODULE_PAYMENT_EPDQ_FORM_VENDOR_ID;
//// Does this store use preauth
if (MODULE_PAYMENT_EPDQ_FORM_PREAUTH == 'true') {
$transaction_type = 'PreAuth';
} else {
$transaction_type = 'Auth';
}
#the following parameters have been obtained earlier in the merchant's webstore
#clientid, passphrase, oid, currencycode, total
$params="clientid=$clientid";
$params.="&password=$passphrase";
$params.="&oid=$new_order_id";
$params.="&chargetype=$transaction_type";
$params.="¤cycode=$currencycode";
$params.="&total=".number_format($order->info['total'] * $currencies->get_value($EPDQ_currency), $currencies->get_decimal_places($EPDQ_currency)) ;
#perform the HTTP Post
$response = pullpage( $server,$url,$params );
#split the response into separate lines
$response_lines=explode("\n",$response);
#for each line in the response check for the presence of the string 'epdqdata'
#this line contains the encrypted string
$response_line_count=count($response_lines);
for ($i=0;$i<$response_line_count;$i++){
if (preg_match('/epdqdata/',$response_lines[$i])){
$strEPDQ=$response_lines[$i];
}
}
$plain = "VendorTxCode=" . date('Ymdhis') . "&";
$plain .= "Amount=" . number_format($order->info['total'] * $currencies->get_value($EPDQ_currency), $currencies->get_decimal_places($EPDQ_currency)) . "&";
$plain .= "Currency=" . $EPDQ_currency . "&";
$plain .= "Description='" . STORE_NAME . "'&";
$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 . "&";
$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'] . "";
$process_button_string = zen_draw_hidden_field('oid', $new_order_id) .
zen_draw_hidden_field('returnurl', MODULE_PAYMENT_EPDQ_FORM_RETURNURL) .
$strEPDQ .
zen_draw_hidden_field('merchantdisplayname', MODULE_PAYMENT_EPDQ_FORM_VENDOR_NAME);
return $process_button_string;
}
function before_process() {
global $order_total_modules;
// now just need to check here whether we are here because of IPN or auto-return, we cn use the referer variable for that
// If we have come from auto return, check to see wether the order has been created by IPN and if not create it now.
if ($_GET['referer'] == 'epdq_form') {
$_SESSION['cart']->reset(true);
unset($_SESSION['sendto']);
unset($_SESSION['billto']);
unset($_SESSION['shipping']);
unset($_SESSION['payment']);
unset($_SESSION['comments']);
$order_total_modules->clear_posts();//ICW ADDED FOR CREDIT CLASS SYSTEM
zen_redirect(zen_href_link(FILENAME_CHECKOUT_SUCCESS, '', 'SSL'));
} else {
zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
}
}
function check_referrer($zf_domain) {
return true;
}
function after_process() {
$_SESSION['order_created'] = '';
return false;
}
function get_error() {
global $_GET;
if (isset($_GET['message']) && (strlen($_GET['message']) > 0)) {
$error = stripslashes(urldecode($_GET['message']));
} else {
$error = MODULE_PAYMENT_EPDQ_FORM_TEXT_ERROR_MESSAGE;
}
return array('title' => MODULE_PAYMENT_EPDQ_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_EPDQ_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 EPDQ Form Module', 'MODULE_PAYMENT_EPDQ_FORM_STATUS', 'True', 'Do you want to accept EPDQ 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 ('Client ID', 'MODULE_PAYMENT_EPDQ_FORM_VENDOR_ID', '12345', 'Client ID to use with the EPDQ 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 ('Client Name', 'MODULE_PAYMENT_EPDQ_FORM_VENDOR_NAME', 'My Store Name', 'Client Name to use with the EPDQ 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_EPDQ_FORM_PASSWORD', 'testvendor', 'Password to use with the EPDQ 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 ('ReturnURL', 'MODULE_PAYMENT_EPDQ_FORM_RETURNURL', 'http://www.mystore.co.uk/epdq_response.php', 'Return URL to use with the EPDQ 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_EPDQ_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_EPDQ_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_EPDQ_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_EPDQ_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_EPDQ_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_EPDQ_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_EPDQ_FORM_STATUS', 'MODULE_PAYMENT_EPDQ_FORM_VENDOR_ID', 'MODULE_PAYMENT_EPDQ_FORM_VENDOR_NAME', 'MODULE_PAYMENT_EPDQ_FORM_PASSWORD', 'MODULE_PAYMENT_EPDQ_FORM_RETURNURL', 'MODULE_PAYMENT_EPDQ_FORM_TEST_STATUS', 'MODULE_PAYMENT_EPDQ_FORM_PREAUTH', 'MODULE_PAYMENT_EPDQ_FORM_CURRENCY', 'MODULE_PAYMENT_EPDQ_FORM_SORT_ORDER', 'MODULE_PAYMENT_EPDQ_FORM_ZONE', 'MODULE_PAYMENT_EPDQ_FORM_ORDER_STATUS_ID');
}
}
?>
Bookmarks