Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Commweb Module - order id question


jodes

Recommended Posts

Hi there,

 

I've added the commweb module to my website - was given the lastest oscommerce module from commonwealth bank. But they won't assist me with modifications. Basically when a transaction goes through it is using a date time stamp instead of the customers order number - so i can't tell who's order is who's which would make it nearly impossible to use. (it doesn't provide the customers name or anything).

 

I have pinpointed the line that i need to change (highlighted in red) but i can't seem to get it to display the customers order number - i was wondering if anyone might be able to help me.

 

Here's the code

 

<?php

/*

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

 

Update: CommWeb Payment Module version 1.0

Date: November 30, 2004

 

*/

 

class commweb {

var $code, $title, $description, $enabled;

 

// class constructor

function commweb() {

global $order;

 

$this->code = 'commweb';

$this->title = MODULE_PAYMENT_COMMWEB_TEXT_TITLE;

$this->description = MODULE_PAYMENT_COMMWEB_TEXT_DESCRIPTION;

$this->sort_order = MODULE_PAYMENT_COMMWEB_SORT_ORDER;

$this->accepted_cc = MODULE_PAYMENT_COMMWEB_ACCEPTED_CARDS;

$this->enabled = ((MODULE_PAYMENT_COMMWEB_STATUS == 'True') ? true : false);

 

if ((int)MODULE_PAYMENT_COMMWEB_ORDER_STATUS_ID > 0) {

$this->order_status = MODULE_PAYMENT_COMMWEB_ORDER_STATUS_ID;

}

 

if (is_object($order)) $this->update_status();

}

 

// class methods

function update_status() {

global $order;

if ( ($this->enabled == true) && (MODULE_PAYMENT_COMMWEB_CURRENCY <> $order->info['currency']) ) {

$this->enabled = false;

}

}

 

function javascript_validation() {

if ((MODULE_PAYMENT_COMMWEB_TYPE == "Merchant Hosted Payments") || (MODULE_PAYMENT_COMMWEB_TYPE == "CommWeb Authenticated Payments")) {

$js = ' if (payment_value == "' . $this->code . '") {' . "\n" .

' var commweb_cc_number = document.checkout_payment.commweb_cc_number.value;' . "\n" .

' if (commweb_cc_number == "" || commweb_cc_number.length < ' . MODULE_PAYMENT_COMMWEB_CC_NUMBER_MIN_LENGTH . ') {' . "\n" .

' commweb_error_message = commweb_error_message + "' . MODULE_PAYMENT_COMMWEB_TEXT_JS_CC_NUMBER . '";' . "\n" .

' error = 1;' . "\n" .

' }' . "\n" .

' }' . "\n";

} else {

$js = "";

}

return $js;

}

 

function selection() {

global $order;

 

if ((MODULE_PAYMENT_COMMWEB_TYPE == "Merchant Hosted Payments") || (MODULE_PAYMENT_COMMWEB_TYPE == "CommWeb Authenticated Payments")) {

// Credit card pulldown list

$allowed_types = array();

$cc_array = explode(',', MODULE_PAYMENT_COMMWEB_ACCEPTED_CARDS);

while (list($key, $value) = each($cc_array)) {

$value=trim($value);

switch (strtoupper($value)) {

case 'VISA':

$allowed_types['Visa'] = MODULE_PAYMENT_COMMWEB_TEXT_VISA; break;

case 'MASTERCARD':

$allowed_types['Mastercard'] = MODULE_PAYMENT_COMMWEB_TEXT_MASTERCARD; break;

case 'BANKCARD':

$allowed_types['Bankcard'] = MODULE_PAYMENT_COMMWEB_TEXT_BANKCARD; break;

case 'AMEX':

$allowed_types['Amex'] = MODULE_PAYMENT_COMMWEB_TEXT_AMEX; break;

case 'AMERICANEXPRESS':

$allowed_types['Amex'] = MODULE_PAYMENT_COMMWEB_TEXT_AMEX; break;

case 'AMERICAN EXPRESS':

$allowed_types['Amex'] = MODULE_PAYMENT_COMMWEB_TEXT_AMEX; break;

case 'DINERS':

$allowed_types['Dinersclub'] = MODULE_PAYMENT_COMMWEB_TEXT_DINERS; break;

case 'DINERSCLUB':

$allowed_types['Dinersclub'] = MODULE_PAYMENT_COMMWEB_TEXT_DINERS; break;

case 'DINERS CLUB':

$allowed_types['Dinersclub'] = MODULE_PAYMENT_COMMWEB_TEXT_DINERS; break;

case 'JCB':

$allowed_types['JCB'] = MODULE_PAYMENT_COMMWEB_TEXT_JCB; break;

case 'DISCOVER':

$allowed_types['Discover'] = MODULE_PAYMENT_COMMWEB_TEXT_DISCOVER; break;

}

}

 

while (list($key, $value) = each($allowed_types)) {

$card_menu[] = array('id' => $key, 'text' => $value);

}

 

for ($i=1; $i<13; $i++) {

$expires_month[] = array('id' => sprintf('%02d', $i), 'text' => strftime('%B',mktime(0,0,0,$i,1,2000)));

}

 

$today = getdate();

for ($i=$today['year']; $i < $today['year']+10; $i++) {

$expires_year[] = array('id' => strftime('%y',mktime(0,0,0,1,1,$i)), 'text' => strftime('%Y',mktime(0,0,0,1,1,$i)));

}

 

$selection = array('id' => $this->code,

'module' => $this->title,

'fields' => array(array('title' => MODULE_PAYMENT_COMMWEB_TEXT_CREDIT_CARD_TYPE,

'field' => tep_draw_pull_down_menu('commweb_cc_type', $card_menu)),

array('title' => MODULE_PAYMENT_COMMWEB_TEXT_CREDIT_CARD_OWNER,

'field' => tep_draw_input_field('commweb_cc_owner')),

array('title' => MODULE_PAYMENT_COMMWEB_TEXT_CREDIT_CARD_NUMBER,

'field' => tep_draw_input_field('commweb_cc_number')),

array('title' => MODULE_PAYMENT_COMMWEB_TEXT_CREDIT_CARD_EXPIRES,

'field' => tep_draw_pull_down_menu('commweb_cc_expiry_month', $expires_month) . ' ' . tep_draw_pull_down_menu('commweb_cc_expiry_year', $expires_year)),

array('title' => MODULE_PAYMENT_COMMWEB_TEXT_CREDIT_CARD_CVV,

'field' => tep_draw_input_field('commweb_cc_cvv') . ' <a onclick="window.open(\'' . tep_href_link('cvv2.html') . '\',\'popupWindow\',\'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,res

izable=no,copyhistory=no,width=558,height=295,screenX=150,screenY=150,top=150,lef

t=150\')"><font size="1"><em><u>' . MODULE_PAYMENT_COMMWEB_TEXT_CREDIT_CARD_CVV_LINK . '</em></u></font></a>')));

} else {

$selection = array('id' => $this->code,

'module' => $this->title);

}

return $selection;

}

 

function pre_confirmation_check() {

global $HTTP_POST_VARS;

if ((MODULE_PAYMENT_COMMWEB_TYPE == "Merchant Hosted Payments") || (MODULE_PAYMENT_COMMWEB_TYPE == "CommWeb Authenticated Payments")) {

$validation = new commweb_validation();

$result = $validation->validate($HTTP_POST_VARS['commweb_cc_number'], $HTTP_POST_VARS['commweb_cc_expiry_month'], $HTTP_POST_VARS['commweb_cc_expiry_year'], $HTTP_POST_VARS['commweb_cc_cvv']);

 

$error = '';

switch ($result) {

case -1:

case -2:

case -3:

$error = MODULE_PAYMENT_COMMWEB_INVALID_EXPIRY;

break;

case -4:

$error = MODULE_PAYMENT_COMMWEB_INVALID_CVV;

break;

case false:

$error = MODULE_PAYMENT_COMMWEB_INVALID_NUMBER;

break;

}

 

if ($validation->cc_type != $HTTP_POST_VARS['commweb_cc_type']) {

$result = -5;

$error = MODULE_PAYMENT_COMMWEB_UNSUPPORTED_CARD;

}

 

if ( ($result == false) || ($result < 1) ) {

$payment_error_return = 'payment_error=' . $this->code . '&error=' . urlencode($error) . '&commweb_cc_owner=' . $HTTP_POST_VARS['commweb_cc_owner'] . '&commweb_cc_number=' . $HTTP_POST_VARS['commweb_cc_number'] . '&commweb_cc_expiry_month=' . $HTTP_POST_VARS['commweb_cc_expiry_month'] . '&commweb_cc_cvv=' . $HTTP_POST_VARS['commweb_cc_cvv'] . '&commweb_cc_expiry_year=' . $HTTP_POST_VARS['commweb_cc_expiry_year'] . '&commweb_cc_type=' . $HTTP_POST_VARS['commweb_cc_type'];

tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, $payment_error_return, 'SSL', true, false));

}

$this->cc_card_type = $validation->cc_type;

}

}

 

function confirmation() {

global $HTTP_POST_VARS;

 

if ((MODULE_PAYMENT_COMMWEB_TYPE == "Merchant Hosted Payments") || (MODULE_PAYMENT_COMMWEB_TYPE == "CommWeb Authenticated Payments")) {

$confirmation = array('title' => $this->title,

'fields' => array(array('title' => MODULE_PAYMENT_COMMWEB_TEXT_CREDIT_CARD_TYPE,

'field' => $this->cc_card_type),

array('title' => MODULE_PAYMENT_COMMWEB_TEXT_CREDIT_CARD_NUMBER,

'field' => substr($HTTP_POST_VARS['commweb_cc_number'], 0, 4) . str_repeat('X', (strlen($HTTP_POST_VARS['commweb_cc_number']) - 8)) . substr($HTTP_POST_VARS['commweb_cc_number'], -4)),

array('title' => MODULE_PAYMENT_COMMWEB_TEXT_CREDIT_CARD_EXPIRES,

'field' => strftime('%B, %Y', mktime(0,0,0,$HTTP_POST_VARS['commweb_cc_expiry_month'], 1, '20' . $HTTP_POST_VARS['commweb_cc_expiry_year']))),

array('title' => MODULE_PAYMENT_COMMWEB_TEXT_CREDIT_CARD_CVV,

'field' => $HTTP_POST_VARS['commweb_cc_cvv'])));

} else {

$confirmation = array('title' => $this->title);

}

return $confirmation;

}

 

function process_button() {

global $order,$HTTP_POST_VARS;

$process_button_string = tep_draw_hidden_field('commweb_cc_owner', $order->info['commweb_cc_owner']) .

tep_draw_hidden_field('cc_expires', $HTTP_POST_VARS['commweb_cc_expiry_month'] . $HTTP_POST_VARS['commweb_cc_expiry_year']) .

tep_draw_hidden_field('commweb_cc_expiry_month', $HTTP_POST_VARS['commweb_cc_expiry_month']) .

tep_draw_hidden_field('commweb_cc_expiry_year', $HTTP_POST_VARS['commweb_cc_expiry_year']) .

tep_draw_hidden_field('commweb_cc_type', $this->cc_card_type) .

tep_draw_hidden_field('commweb_cc_number', $order->info['commweb_cc_number']) .

tep_draw_hidden_field('commweb_cc_cvv', $HTTP_POST_VARS['commweb_cc_cvv']);

return $process_button_string;

}

 

function before_process() {

global $order, $osCsid, $HTTP_POST_VARS, $HTTP_GET_VARS;

 

if (MODULE_PAYMENT_COMMWEB_TYPE == "Merchant Hosted Payments") {

$this->do2PartyPayment();

} else {

if (strlen($HTTP_GET_VARS['DR']) > 0) {

$this->decrypt_digital_receipt();

} else {

$this->create_digital_order();

}

}

}

 

function after_process() {

global $insert_id;

 

$message = 'Order No' . $insert_id . "\n\n";

tep_mail('', MODULE_PAYMENT_COMMWEB_EMAIL, 'Extra Order Info: #' . $insert_id, $message, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);

}

 

function get_error() {

global $HTTP_GET_VARS;

 

$error = array('title' => MODULE_PAYMENT_COMMWEB_TEXT_ERROR,

'error' => stripslashes(urldecode($HTTP_GET_VARS['error'])));

 

return $error;

}

 

function check() {

if (!isset($this->_check)) {

$check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_COMMWEB_STATUS'");

$this->_check = tep_db_num_rows($check_query);

}

return $this->_check;

}

 

function install() {

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Credit Card Module', 'MODULE_PAYMENT_COMMWEB_STATUS', 'True', 'Do you want to accept credit card payments using the CommWeb Payment Client?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");

tep_db_query("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_COMMWEB_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0' , now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Transaction Type', 'MODULE_PAYMENT_COMMWEB_TYPE', 'CommWeb Hosted Payments', 'The type of payment to be used by this module.', '6', '0', 'tep_cfg_select_option(array(\'CommWeb Hosted Payments\', \'CommWeb Authenticated Payments\', \'Merchant Hosted Payments\'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Currency', 'MODULE_PAYMENT_COMMWEB_CURRENCY', 'AUD', 'Only enable this payment method for the currency specified', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Currency Exponent', 'MODULE_PAYMENT_COMMWEB_EXPONENT', '2', 'The number of decimal places used in the currency specified for this module', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Accepted Credit Cards', 'MODULE_PAYMENT_COMMWEB_ACCEPTED_CARDS', 'MasterCard,Visa,Bankcard,American Express,Diners Club', 'A comma separated list of the credit cards you will be processing payments for, e.g. MasterCard,Visa,Bankcard,Amex,Diners Club,JCB', '6', '0', now())");

tep_db_query("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_COMMWEB_ORDER_STATUS_ID', '0', 'Set the status of orders made with this payment module to this value', '6', '0', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Merchant ID', 'MODULE_PAYMENT_COMMWEB_MERCHANTID', '', 'The Merchant ID to be used to process payments', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Payment Client Host Name or IP Address', 'MODULE_PAYMENT_COMMWEB_IP_ADDRESS', '127.0.0.1', 'The IP address or Host Name of the machine hosting the Payment Client', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Payment Client Port', 'MODULE_PAYMENT_COMMWEB_PORT', '9050', 'The Port that the Payment Client is listening on', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Minimum Credit Card Length', 'MODULE_PAYMENT_COMMWEB_CC_NUMBER_MIN_LENGTH', '15', 'The minimum length for a card number', '6', '0', now())");

}

 

function remove() {

tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");

}

 

function keys() {

return array('MODULE_PAYMENT_COMMWEB_STATUS', 'MODULE_PAYMENT_COMMWEB_SORT_ORDER', 'MODULE_PAYMENT_COMMWEB_TYPE', 'MODULE_PAYMENT_COMMWEB_CURRENCY', 'MODULE_PAYMENT_COMMWEB_EXPONENT', 'MODULE_PAYMENT_COMMWEB_ACCEPTED_CARDS', 'MODULE_PAYMENT_COMMWEB_ORDER_STATUS_ID', 'MODULE_PAYMENT_COMMWEB_MERCHANTID', 'MODULE_PAYMENT_COMMWEB_IP_ADDRESS', 'MODULE_PAYMENT_COMMWEB_PORT', 'MODULE_PAYMENT_COMMWEB_CC_NUMBER_MIN_LENGTH');

}

 

function do2PartyPayment() {

global $order, $HTTP_POST_VARS;

 

// Get the summary information into the format needed to process the payment

//$amount = (int) ($order->info['total'] * pow(10,MODULE_PAYMENT_COMMWEB_EXPONENT));

 

if($_SESSION['shipping']['cost']>0) {

$ship_cost_tax=tep_round(($_SESSION['shipping']['cost']*10)/100,2);

$the_new_total=$order->info['total']+$ship_cost_tax;

} else {

$the_new_total=$order->info['total'];

}

 

$amount = (int) ($the_new_total * pow(10,MODULE_PAYMENT_COMMWEB_EXPONENT));

 

$card_expiry = $HTTP_POST_VARS['commweb_cc_expiry_year'] . $HTTP_POST_VARS['commweb_cc_expiry_month'];

 

// Setup the variables that are needed throughout the function

$SHORT_SOCKET_TIMEOUT = 5;

$LONG_SOCKET_TIMEOUT = 100;

$OK = "1";

$cmdResponse = "";

$errorExists = false;

$socketCreated = true;

$receiptNo = "";

$responseCode = "";

 

// Set order details

$cc_number = trim($HTTP_POST_VARS['commweb_cc_number']);

$order->info['cc_owner'] = trim($HTTP_POST_VARS['commweb_cc_owner']);

$order->info['cc_type'] = trim($HTTP_POST_VARS['commweb_cc_type']);

$order->info['cc_number'] = substr($cc_number, 0, 4) . str_repeat('X', (strlen($cc_number) - 8)) . substr($cc_number, -4);

$order->info['cc_expiry_month'] = trim($HTTP_POST_VARS['commweb_cc_expiry_month']);

$order->info['cc_expiry_year'] = trim($HTTP_POST_VARS['commweb_cc_expiry_year']);

$order->info['cc_expires'] = $order->info['cc_expiry_month'] . $order->info['cc_expiry_year'];

 

// Initialise the Payment Client socket connection

$payClientSocket = -1;

 

// create the socket connection

$host = MODULE_PAYMENT_COMMWEB_IP_ADDRESS;

$port = (int)MODULE_PAYMENT_COMMWEB_PORT;

if (strlen($host) > 0 && $port > 0) {

$payClientSocket = fsockopen($host, $port, $errno, $errstr, (float)$SHORT_SOCKET_TIMEOUT);

} else {

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_SOCKET . $errstr;

$errorExists = true;

$socketCreated = false;

}

 

if (!$errorExists && $payClientSocket < 1) {

// The socket connection failed

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_SOCKET;

$errorExists = true;

$socketCreated = false;

}

 

if (!$errorExists) {

$cmdResponse = $this->sendCommand($payClientSocket,"1,Test",$SHORT_SOCKET_TIMEOUT);

if (substr($cmdResponse,2) != "echo:Test") {

// Communication to the Payment Client failed

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_ECHO;

$errorExists = true;

}

}

 

if (!$errorExists) {

$cmdResponse = $this->sendCommand($payClientSocket, "7,CardNum," . ereg_replace('[^0-9]', '', $cc_number) . ",",$SHORT_SOCKET_TIMEOUT);

if (substr($cmdResponse,0,1) != $OK) {

// Display an error message as the command failed

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_CARDNUM;

$errorExists = true;

}

}

 

if (!$errorExists) {

$cmdResponse = $this->sendCommand($payClientSocket, "7,CardExp," . $card_expiry . ",",$SHORT_SOCKET_TIMEOUT);

if (substr($cmdResponse,0,1) != $OK) {

// Display an error message as the command failed

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_CARDEXP;

$errorExists = true;

}

}

 

if (!$errorExists) {

$cmdResponse = $this->sendCommand($payClientSocket, "7,CardSecureCode," . $HTTP_POST_VARS['commweb_cc_cvv'] . ",",$SHORT_SOCKET_TIMEOUT);

if (substr($cmdResponse,0,1) != $OK) {

// Display an error message as the command failed

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_CARDCVV;

$errorExists = true;

}

}

 

if (!$errorExists) {

// (This primary command also receives the encrypted Digital Receipt)

$cmdResponse = $this->sendCommand($payClientSocket,"6," . date("YmdHis") . "," . MODULE_PAYMENT_COMMWEB_MERCHANTID . "," . $amount . ",en,,",$LONG_SOCKET_TIMEOUT);

if (substr($cmdResponse,0,1) != $OK) {

// The command failed

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_PAY . substr($this->sendCommand($payClientSocket, "4,PaymentClient.Error,",$SHORT_SOCKET_TIMEOUT),2);

$errorExists = true;

}

}

 

if (!$errorExists) {

$cmdResponse = $this->sendCommand($payClientSocket, "5,",$SHORT_SOCKET_TIMEOUT);

if (substr($cmdResponse,0,1) != $OK) {

// Display an error message as the command failed

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_NEXT;

$errorExists = true;

}

}

 

if (!$errorExists) {

$cmdResponse = $this->sendCommand($payClientSocket, "4,DigitalReceipt.QSIResponseCode,",$SHORT_SOCKET_TIMEOUT);

if (substr($cmdResponse,0,1) != $OK) {

// Display an error message as the command failed

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_RECEIPT;

$errorExists = true;

} else {

$responseCode = substr($cmdResponse,0,1) == $OK ? substr($cmdResponse,2) : "No Value Returned";

$message = $this->getResponseDescription($responseCode);

}

}

 

if (!$errorExists) {

$cmdResponse = $this->sendCommand($payClientSocket, "4,DigitalReceipt.ReceiptNo,",$SHORT_SOCKET_TIMEOUT);

if (substr($cmdResponse,0,1) != $OK) {

// Display an error message as the command failed

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_RECEIPT;

$errorExists = true;

} else {

$receiptNo = substr($cmdResponse,0,1) == $OK ? substr($cmdResponse,2) : "No Value Returned";

}

}

 

if ($socketCreated) {

$this->close($payClientSocket);

}

 

if (!$errorExists && $responseCode == "0") {

// Save the Receipt Number (RRN) as a comment) for fiture reference

$order->info['comments'] = MODULE_PAYMENT_COMMWEB_ORDER_RECEIPTNUMBER . $receiptNo . "\n\n" . $order->info['comments'];

} else {

$payment_error_return = 'payment_error=' . $this->code . '&error=' . urlencode($message) . '&commweb_cc_owner=' . $order->info['cc_owner'] . '&commweb_cc_number=' . $cc_number . '&commweb_cc_expiry_month=' . $order->info['cc_expiry_month'] . '&commweb_cc_expiry_year=' . $order->info['cc_expiry_year'] . '&commweb_cc_cvv=' . $HTTP_POST_VARS['commweb_cc_cvv'] . '&commweb_cc_type=' . $order->info['cc_type'];

tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, $payment_error_return, 'SSL', true, false));

}

}

 

function create_digital_order() {

global $order, $osCsid, $HTTP_POST_VARS;

 

// Get the summary information into the format needed to process the payment

 

//$amount = (int) ($order->info['total'] * pow(10,MODULE_PAYMENT_COMMWEB_EXPONENT));

 

if($_SESSION['shipping']['cost']>0) {

$ship_cost_tax=tep_round(($_SESSION['shipping']['cost']*10)/100,2);

$the_new_total=$order->info['total']+$ship_cost_tax;

} else {

$the_new_total=$order->info['total'];

}

 

$amount = (int) ($the_new_total * pow(10,MODULE_PAYMENT_COMMWEB_EXPONENT));

 

$card_expiry = trim($HTTP_POST_VARS['commweb_cc_expiry_year']) . trim($HTTP_POST_VARS['commweb_cc_expiry_month']);

 

// Setup the variables that are needed throughout the script

$SHORT_SOCKET_TIMEOUT = 5;

$LONG_SOCKET_TIMEOUT = 100;

$OK = "1";

$cmdResponse = "";

$errorExists = false;

$socketCreated = true;

$receiptNo = "";

$responseCode = "";

 

// Initialise the Payment Client socket connection

$payClientSocket = -1;

 

// create the socket connection

$host = MODULE_PAYMENT_COMMWEB_IP_ADDRESS;

$port = (int)MODULE_PAYMENT_COMMWEB_PORT;

if (strlen($host) > 0 && $port > 0) {

$payClientSocket = fsockopen($host, $port, $errno, $errstr, (float)$SHORT_SOCKET_TIMEOUT);

} else {

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_SOCKET . $errstr;

$errorExists = true;

$socketCreated = false;

}

 

if (!$errorExists && $payClientSocket < 1) {

// The socket connection failed

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_SOCKET;

$errorExists = true;

$socketCreated = false;

}

 

if (!$errorExists) {

$cmdResponse = $this->sendCommand($payClientSocket,"1,Test",$SHORT_SOCKET_TIMEOUT);

if (substr($cmdResponse,2) != "echo:Test") {

// Communication to the Payment Client failed

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_ECHO;

$errorExists = true;

}

}

 

if (MODULE_PAYMENT_COMMWEB_TYPE == "CommWeb Authenticated Payments") {

if (!$errorExists) {

$cmdResponse = $this->sendCommand($payClientSocket, "7,CardNum," . ereg_replace('[^0-9]', '', trim($HTTP_POST_VARS['commweb_cc_number'])) . ",",$SHORT_SOCKET_TIMEOUT);

if (substr($cmdResponse,0,1) != $OK) {

// Display an error message as the command failed

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_CARDNUM;

$errorExists = true;

}

}

 

if (!$errorExists) {

$cmdResponse = $this->sendCommand($payClientSocket, "7,CardExp," . trim($card_expiry) . ",",$SHORT_SOCKET_TIMEOUT);

if (substr($cmdResponse,0,1) != $OK) {

// Display an error message as the command failed

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_CARDEXP;

$errorExists = true;

}

}

 

if (!$errorExists) {

$cmdResponse = $this->sendCommand($payClientSocket, "7,CardSecurityCode," . trim($HTTP_POST_VARS['commweb_cc_cvv']) . ",",$SHORT_SOCKET_TIMEOUT);

if (substr($cmdResponse,0,1) != $OK) {

// Display an error message as the command failed

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_CARDCVV;

$errorExists = true;

}

}

 

if (!$errorExists) {

$cmdResponse = $this->sendCommand($payClientSocket, "7,gateway,ssl,",$SHORT_SOCKET_TIMEOUT);

if (substr($cmdResponse,0,1) != $OK) {

// Display an error message as the command failed

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_CARDEXP;

$errorExists = true;

}

}

 

if (!$errorExists) {

$cmdResponse = $this->sendCommand($payClientSocket, "7,card," . trim($HTTP_POST_VARS['commweb_cc_type']) . ",",$SHORT_SOCKET_TIMEOUT);

if (substr($cmdResponse,0,1) != $OK) {

// Display an error message as the command failed

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_CARDEXP;

$errorExists = true;

}

}

}

 

// Create the Return URL

$returnURL = tep_href_link(FILENAME_CHECKOUT_PROCESS, tep_session_name() . '=' . tep_session_id() . '&DR=${DR}', 'SSL', true, false);

 

// Create the Digital Order

if (!$errorExists) {

// (This primary command also receives the encrypted Digital Receipt)

$cmdResponse = $this->sendCommand($payClientSocket,"2," . trim(date("YmdHis")) . "," . MODULE_PAYMENT_COMMWEB_MERCHANTID . "," . $amount . ",en," . $returnURL . ",",$LONG_SOCKET_TIMEOUT);

if (substr($cmdResponse,0,1) != $OK) {

// The command failed

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_PAY . substr($this->sendCommand($payClientSocket, "4,PaymentClient.Error,",$SHORT_SOCKET_TIMEOUT),2);

$errorExists = true;

}

}

 

if ($socketCreated) {

$this->close($payClientSocket);

}

 

if (!$errorExists) {

// Perform Redirect

tep_redirect(substr($cmdResponse,2));

} else {

$payment_error_return = 'payment_error=' . $this->code . '&error=' . urlencode($message) . '&commweb_cc_owner=' . trim($HTTP_POST_VARS['commweb_cc_owner']) . '&commweb_cc_number=' . trim($HTTP_POST_VARS['commweb_cc_number']) . '&commweb_cc_expiry_month=' . trim($HTTP_POST_VARS['commweb_cc_expiry_month']) . '&commweb_cc_expiry_year=' . trim($HTTP_POST_VARS['commweb_cc_expiry_year']) . '&commweb_cc_cvv=' . trim($HTTP_POST_VARS['commweb_cc_cvv']) . '&commweb_cc_type=' . trim($HTTP_POST_VARS['commweb_cc_type']);

tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, $payment_error_return, 'SSL', true, false));

}

}

 

function decrypt_digital_receipt() {

global $order, $osCsid, $HTTP_POST_VARS, $HTTP_GET_VARS;

 

// Setup the variables that are needed throughout the script

$SHORT_SOCKET_TIMEOUT = 5;

$LONG_SOCKET_TIMEOUT = 100;

$OK = "1";

$cmdResponse = "";

$errorExists = false;

$socketCreated = true;

$receiptNo = "";

$responseCode = "";

 

// Initialise the Payment Client socket connection

$payClientSocket = -1;

 

// create the socket connection

$host = MODULE_PAYMENT_COMMWEB_IP_ADDRESS;

$port = (int)MODULE_PAYMENT_COMMWEB_PORT;

if (strlen($host) > 0 && $port > 0) {

$payClientSocket = fsockopen($host, $port, $errno, $errstr, (float)$SHORT_SOCKET_TIMEOUT);

} else {

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_SOCKET . $errstr;

$errorExists = true;

$socketCreated = false;

}

 

if (!$errorExists && $payClientSocket < 1) {

// The socket connection failed

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_SOCKET;

$errorExists = true;

$socketCreated = false;

}

 

if (!$errorExists) {

$cmdResponse = $this->sendCommand($payClientSocket,"1,Test",$SHORT_SOCKET_TIMEOUT);

if (substr($cmdResponse,2) != "echo:Test") {

// Communication to the Payment Client failed

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_ECHO;

$errorExists = true;

}

}

 

// Decrypt the Digital Receipt

if (!$errorExists) {

// (This primary command also receives the encrypted Digital Receipt)

$cmdResponse = $this->sendCommand($payClientSocket,"3," . $HTTP_GET_VARS['DR'], $LONG_SOCKET_TIMEOUT);

if (substr($cmdResponse,0,1) != $OK) {

// The command failed

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_PAY . substr($this->sendCommand($payClientSocket, "4,PaymentClient.Error,",$SHORT_SOCKET_TIMEOUT),2);

$errorExists = true;

}

}

 

if (!$errorExists) {

$cmdResponse = $this->sendCommand($payClientSocket, "5,",$SHORT_SOCKET_TIMEOUT);

if (substr($cmdResponse,0,1) != $OK) {

// Display an error message as the command failed

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_NEXT;

$errorExists = true;

}

}

 

if (!$errorExists) {

$cmdResponse = $this->sendCommand($payClientSocket, "4,DigitalReceipt.QSIResponseCode,",$SHORT_SOCKET_TIMEOUT);

if (substr($cmdResponse,0,1) != $OK) {

// Display an error message as the command failed

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_RECEIPT;

$errorExists = true;

} else {

$responseCode = substr($cmdResponse,0,1) == $OK ? substr($cmdResponse,2) : "No Value Returned";

$message = $this->getResponseDescription($responseCode);

}

}

 

if (!$errorExists) {

$cmdResponse = $this->sendCommand($payClientSocket, "4,DigitalReceipt.ReceiptNo,",$SHORT_SOCKET_TIMEOUT);

if (substr($cmdResponse,0,1) != $OK) {

// Display an error message as the command failed

$message = MODULE_PAYMENT_COMMWEB_PROCESSING_ERROR_RECEIPT;

$errorExists = true;

} else {

$receiptNo = substr($cmdResponse,0,1) == $OK ? substr($cmdResponse,2) : "No Value Returned";

}

}

 

if ($socketCreated) {

$this->close($payClientSocket);

}

 

if (!$errorExists && $responseCode == "0") {

// Save the Receipt Number (RRN) as a comment) for fiture reference

$order->info['comments'] = MODULE_PAYMENT_COMMWEB_ORDER_RECEIPTNUMBER . $receiptNo . "\n\n" . $order->info['comments'];

} else {

$payment_error_return = 'payment_error=' . $this->code . '&error=' . urlencode($message);

tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, $payment_error_return, 'SSL', true, false));

}

}

 

function sendCommand($payClientSocket, $command, $payClientTimeout) {

 

socket_set_timeout($payClientSocket, $payClientTimeout);

 

// output the data to the socket & read in the response

$buf = $command . "\n";

$response = fputs($payClientSocket, $buf) == strlen($buf);

if (!$response) {

// Display an error as there has been a communication error

return "0";

}

 

// Set the time to stop reading using the globale timeout variable

$stop=time() + $payClientTimeout;

$reply="";

while (!strpos($reply,"\n")) {

// Check to see if we have timed out

if (time() >= $stop) {

return "0";

}

$reply .= fgets($payClientSocket, 4096);

}

 

// return the socket response

return chop($reply);

}

 

function close($payClientSocket) {

$buf = "99";

$response = fputs($payClientSocket, $buf) == strlen($buf);

fclose($payClientSocket);

}

 

function getResponseDescription($responseCode) {

 

switch ($responseCode) {

case "0" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_0; break;

case "?" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_QUESTION; break;

case "1" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_1; break;

case "2" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_2; break;

case "3" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_3; break;

case "4" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_4; break;

case "5" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_5; break;

case "6" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_6; break;

case "7" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_7; break;

case "8" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_8; break;

case "9" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_9; break;

case "A" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_A; break;

case "C" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_C; break;

case "D" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_D; break;

case "F" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_F; break;

case "I" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_I; break;

case "L" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_L; break;

case "N" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_N; break;

case "P" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_P; break;

case "R" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_R; break;

case "S" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_S; break;

case "T" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_T; break;

case "U" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_U; break;

case "V" : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_V; break;

default : $result = MODULE_PAYMENT_COMMWEB_RESPONSE_DEFAULT;

}

return $result;

}

}

 

class commweb_validation {

var $cc_type, $commweb_cc_number, $commweb_cc_expiry_month, $commweb_cc_expiry_year;

 

function validate($number, $expiry_m, $expiry_y, $cvv) {

$this->commweb_cc_number = ereg_replace('[^0-9]', '', $number);

 

if (ereg('^4[0-9]{12}([0-9]{3})?$', $this->commweb_cc_number)) {

$this->cc_type = 'Visa';

}

elseif (ereg('^5[1-5][0-9]{14}$', $this->commweb_cc_number)) {

$this->cc_type = 'Mastercard';

}

elseif (ereg('^3[47][0-9]{13}$', $this->commweb_cc_number)) {

$this->cc_type = 'Amex';

}

elseif (ereg('^3(0[0-5]|[68][0-9])[0-9]{11}$', $this->commweb_cc_number)) {

$this->cc_type = 'Dinersclub';

}

elseif (ereg('^6011[0-9]{12}$', $this->commweb_cc_number)) {

$this->cc_type = 'Discover';

}

elseif (ereg('^(3[0-9]{4}|2131|1800)[0-9]{11}$', $this->commweb_cc_number)) {

$this->cc_type = 'JCB';

}

elseif (ereg('^5610[0-9]{12}$', $this->commweb_cc_number)) {

$this->cc_type = 'Bankcard';

}

else {

$this->cc_type = 'Other';

}

 

if (is_numeric($expiry_m) && ($expiry_m > 0) && ($expiry_m < 13)) {

$this->commweb_cc_expiry_month = $expiry_m;

}

else {

return -1;

}

 

$current_year = date('Y');

$expiry_y = substr($current_year, 0, 2) . $expiry_y;

if (is_numeric($expiry_y) && ($expiry_y >= $current_year) && ($expiry_y <= ($current_year + 10))) {

$this->commweb_cc_expiry_year = $expiry_y;

} else {

return -2;

}

 

if ($expiry_y == $current_year) {

if ($expiry_m <= date('n')) {

return -3;

}

}

 

$l = strlen($cvv);

switch($this->cc_type) {

case 'Amex':

$len = 4;

break;

case 'Discover':

$len = 3;

break;

case 'Mastercard':

$len = 3;

break;

case 'Visa':

$len = 3;

break;

}

 

if ($len <> $l) {

return -4;

}

 

return $this->is_valid();

}

 

function is_valid() {

$cardNumber = strrev($this->commweb_cc_number);

$numSum = 0;

 

for ($i=0; $i<strlen($cardNumber); $i++) {

$currentNum = substr($cardNumber, $i, 1);

 

// Double every second digit

if ($i % 2 == 1) {

$currentNum *= 2;

}

 

// Add digits of 2-digit numbers together

if ($currentNum > 9) {

$firstNum = $currentNum % 10;

$secondNum = ($currentNum - $firstNum) / 10;

$currentNum = $firstNum + $secondNum;

}

 

$numSum += $currentNum;

}

 

// If the total has no remainder it's OK

return ($numSum % 10 == 0);

}

}

?>

 

Cheers

Jodes xx

Link to comment
Share on other sites

Update:

 

I found out that the data is sent to migs first before the order id is created and that's why my code wasn't working. I asked about using the credit card holder name or something similar for the Order number but apparently it is against migs' policy & procedures.

 

Oh well hopefully the code may be able to help someone else in some way. :-"

 

jodes

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...