Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Credit card payment order status still "pending"


v-funk

Recommended Posts

Hi all,

 

My credit card payment module does not have the "Set Order Status" feature so the order status is saying "pending" on the credit card payments - even though the payment has been processed.

 

Can anyone tell me how do I add the "Set Order Status" option to the following payment module??

 

Thanks in advance, any help would be very much appreciated.....the site has to go live in 3 days!!

 

<?php

/*

 

Logiccommerce <[email protected]>

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2002 osCommerce

 

Released under the GNU General Public License

*/

 

class eterminal1 {

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

 

// class constructor

function eterminal1() {

$this->code = 'eterminal1';

$this->title = MODULE_PAYMENT_eterminal1_TEXT_TITLE;

$this->description = MODULE_PAYMENT_eterminal1_TEXT_DESCRIPTION;

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

}

 

// class methods

// this method returns the javascript that will validate the form entry

function javascript_validation() {

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

' var cc_owner = document.checkout_payment.eterminal_cc_owner.value;' . "\n" .

' var cc_number = document.checkout_payment.eterminal_cc_number.value;' . "\n" .

' if (cc_owner == "" || cc_owner.length < ' . CC_OWNER_MIN_LENGTH . ') {' . "\n" .

' error_message = error_message + "' . MODULE_PAYMENT_eterminal1_TEXT_JS_CC_OWNER . '";' . "\n" .

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

' }' . "\n" .

' if (cc_number == "" || cc_number.length < ' . CC_NUMBER_MIN_LENGTH . ') {' . "\n" .

' error_message = error_message + "' . MODULE_PAYMENT_eterminal1_TEXT_JS_CC_NUMBER . '";' . "\n" .

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

' }' . "\n" .

' }' . "\n";

 

return $js;

}

 

// this method returns the html that creates the input form

function selection() {

global $order;

 

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)));

}

 

$card_types[] = array('id' => 'Visa', 'text' => 'Visa');

$card_types[] = array('id' => 'Mastercard', 'text' => 'Mastercard');

$card_types[] = array('id' => 'Bankcard', 'text' => 'Bankcard');

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

'module' => $this->title,

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

'field' => tep_draw_input_field('eterminal_cc_owner', $order->billing['firstname'] . ' ' . $order->billing['lastname'])),

array('title' => MODULE_PAYMENT_eterminal1_TEXT_CREDIT_CARD_NUMBER,

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

array('title' => MODULE_PAYMENT_eterminal1_TEXT_CREDIT_CARD_TYPE,

'field' => tep_draw_pull_down_menu('eterminal_cc_type', $card_types)),

array('title' => MODULE_PAYMENT_eterminal1_TEXT_CREDIT_CARD_EXPIRES,

'field' => tep_draw_pull_down_menu('eterminal_cc_expires_month', $expires_month) . ' ' . tep_draw_pull_down_menu('eterminal_cc_expires_year', $expires_year))));

 

return $selection;

}

 

// this method is called before the data is sent to the credit card processor

// here you can do any field validation that you need to do

// we also set the global variables here from the form values

function pre_confirmation_check() {

global $HTTP_POST_VARS;

 

include(DIR_WS_CLASSES . 'cc_validation.php');

 

$cc_validation = new cc_validation();

$result = $cc_validation->validate($HTTP_POST_VARS['eterminal_cc_number'], $HTTP_POST_VARS['eterminal_cc_expires_month'], $HTTP_POST_VARS['eterminal_cc_expires_year']);

 

$error = '';

switch ($result) {

case -1:

$error = sprintf(TEXT_CCVAL_ERROR_UNKNOWN_CARD, substr($cc_validation->cc_number, 0, 4));

break;

case -2:

case -3:

case -4:

$error = TEXT_CCVAL_ERROR_INVALID_DATE;

break;

case false:

$error = TEXT_CCVAL_ERROR_INVALID_NUMBER;

break;

}

 

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

$payment_error_return = 'payment_error=' . $this->code . '&error=' . urlencode($error) . '&eterminal_cc_owner=' . urlencode($HTTP_POST_VARS['eterminal_cc_owner']) . '&eterminal_cc_type=' . urlencode($HTTP_POST_VARS['eterminal_cc_type']) . '&eterminal_cc_expires_month=' . $HTTP_POST_VARS['eterminal_cc_expires_month'] . '&eterminal_cc_expires_year=' . $HTTP_POST_VARS['eterminal_cc_expires_year'];

 

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

}

 

$this->cc_card_owner = $HTTP_POST_VARS['eterminal_cc_owner'];

$this->cc_card_type = $HTTP_POST_VARS['eterminal_cc_type'];

$this->cc_card_number = $cc_validation->cc_number;

$this->cc_expiry_month = $cc_validation->cc_expiry_month;

$this->cc_expiry_year = $cc_validation->cc_expiry_year;

}

 

// this method returns the data for the confirmation page

function confirmation() {

global $HTTP_POST_VARS;

 

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

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

'field' => $HTTP_POST_VARS['eterminal_cc_owner']),

array('title' => MODULE_PAYMENT_eterminal1_TEXT_TYPE,

'field' => $HTTP_POST_VARS['eterminal_cc_type']),

array('title' => MODULE_PAYMENT_eterminal1_TEXT_CREDIT_CARD_NUMBER,

'field' => substr($this->cc_card_number, 0, 4) . str_repeat('X', (strlen($this->cc_card_number) - 8)) . substr($this->cc_card_number, -4)),

array('title' => MODULE_PAYMENT_eterminal1_TEXT_CREDIT_CARD_EXPIRES,

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

 

return $confirmation;

}

 

// this method performs the authorization by sending the data to the processor, and getting the result

function process_button() {

global $order;

 

$process_button_string = tep_draw_hidden_field('merchant_id', MODULE_PAYMENT_eterminal1_MERCHANT_ID) .

tep_draw_hidden_field('username', MODULE_PAYMENT_eterminal1_USERNAME) .

tep_draw_hidden_field('password', MODULE_PAYMENT_eterminal1_PASSWORD) .

tep_draw_hidden_field('zone_id', MODULE_PAYMENT_eterminal1_ZONE_ID) .

// eterminal wants amount in cents, that's right

// cents! No comma or periods in there either.

tep_draw_hidden_field('amount', number_format(($order->info['total']), 2, '.s', '')) .

tep_draw_hidden_field('ponum', date('Ymdhis')) .

tep_draw_hidden_field('cardnumber', $this->cc_card_number) .

tep_draw_hidden_field('cardholder', $this->cc_card_owner) .

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

tep_draw_hidden_field('exdate1', $this->cc_expiry_month) .

tep_draw_hidden_field('exdate2', substr($this->cc_expiry_year, -2));

 

return $process_button_string;

}

 

// this method gets called after the processing is done but before the app server

// accepts the result. It is used to check for errors.

function before_process() {

global $HTTP_POST_VARS;

 

$urlstring = 'merchant_id=' . $HTTP_POST_VARS['merchant_id'] .

'&username=' . $HTTP_POST_VARS['username'] .

'&password=' . $HTTP_POST_VARS['password'] .

'&zone_id=' . $HTTP_POST_VARS['password'] .

'&cardtype=' . $HTTP_POST_VARS['cardtype'] .

'&currencytype=AUD&invoicenumber=' . $HTTP_POST_VARS['ponum'] .

'&cardnumber=' . $HTTP_POST_VARS['cardnumber'] .

'&cardexpirymonth=' . $HTTP_POST_VARS['exdate1'] .

'&cardexpiryyear=' . $HTTP_POST_VARS['exdate2'] .

'&amount=' . $HTTP_POST_VARS['amount'] .

'&cardholder=' . $HTTP_POST_VARS['cardholder'] ;

 

$url = 'https://client.eterminal.com.au/eterminal/remote/oscommerce/index.cfm';

$ch = curl_init($url);

 

curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $urlstring);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

 

$data = curl_exec($ch);

if (curl_error($ch)) {

$response_message = "Error ". curl_errno($ch). curl_error($ch);

}

curl_close($ch);

 

$codes = split("\n", $data);

foreach($codes as $code)

{

if (strstr($code, "<ACCEPTED>"))

$accept_status = substr($code, strlen("<ACCEPTED>"),1);

if (strstr($code, "<RESPONSEMESSAGE>"))

$response_message = str_replace("</RESPONSEMESSAGE>","",substr($code, strlen("<RESPONSEMESSAGE>")));

}

 

if ($accept_status == "" || $accept_status != 1) {

tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code . '&error=' . urlencode($response_message) . urlencode($response_text), 'SSL', true, false));

}

}

 

function after_process() {

global $insert_id;

 

$message = 'You have received a New Order #' . $insert_id . "\n\n" . "\n\n";

 

tep_mail('', STORE_OWNER_EMAIL_ADDRESS, 'New Order Received: #' . $insert_id, $message, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);

}

 

function get_error() {

global $HTTP_GET_VARS;

 

$msg = "";

if (stripslashes(urldecode($HTTP_GET_VARS['response_text'])) != "")

$msg = stripslashes(urldecode($HTTP_GET_VARS['response_text']));

else if (stripslashes(urldecode($HTTP_GET_VARS['error'])) != "")

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

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

'error' => $msg);

 

return $error;

}

 

function check() {

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

$check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_eterminal1_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 eterminal Module', 'MODULE_PAYMENT_eterminal1_STATUS', 'True', 'Do you want to accept eterminal payments?', '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 ('Merchant ID', 'MODULE_PAYMENT_eterminal1_MERCHANT_ID', 'LCxxxx', 'The Merchant id used for the eterminal service', '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 ('Username', 'MODULE_PAYMENT_eterminal1_USERNAME', '', 'The Username used for eterminal server', '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 ('Password', 'MODULE_PAYMENT_eterminal1_PASSWORD', '', 'The Password used for eterminal server', '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 ('Zone ID', 'MODULE_PAYMENT_eterminal1_ZONE_ID', '0', 'The Zone ID used for eterminal server', '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 ('Sort order of display.', 'MODULE_PAYMENT_eterminal1_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '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_eterminal1_STATUS', 'MODULE_PAYMENT_eterminal1_MERCHANT_ID', 'MODULE_PAYMENT_eterminal1_USERNAME', 'MODULE_PAYMENT_eterminal1_PASSWORD', 'MODULE_PAYMENT_eterminal1_ZONE_ID', 'MODULE_PAYMENT_eterminal1_SORT_ORDER');

}

}

?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...