Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Module for "Visa Only"


hubby2debbie

Recommended Posts

Is there a way that I can make a copy of the "cc" or credit card payment module, and rename it "Visa"? I've tried to do this but without success. I've gotten as far as having the module work in the shopping area, but it fails to write the credit card number and other information to the database. I have a situation where I need to allow some credit cards for some zones, and others for other zones, and I figured the easiest way to do this is to create separate modules for each credit card. I think the difficulty is knowing what needs to be changed and what doesn't need to be changed.

 

Peter Anderson

Link to comment
Share on other sites

  • 2 weeks later...

Hello Peter,

 

Im happy you have the answer. I cant find any documentation regarding the credit card module.

 

Can you write please, how do I create another credit card module using my old module?

 

(What do you mean "time-frame" ?)

 

 

Thanks,

 

Eilon

Link to comment
Share on other sites

Easiest way is to use the default CC module and modify includes/classes/cc_validation.php by changing these lines:

 

	  if (ereg('^4[0-9]{12}([0-9]{3})?$', $this->cc_number)) {
	$this->cc_type = 'Visa';
  } elseif (ereg('^5[1-5][0-9]{14}$', $this->cc_number)) {
	$this->cc_type = 'Master Card';
  } elseif (ereg('^3[47][0-9]{13}$', $this->cc_number)) {
	$this->cc_type = 'American Express';
  } elseif (ereg('^3(0[0-5]|[68][0-9])[0-9]{11}$', $this->cc_number)) {
	$this->cc_type = 'Diners Club';
  } elseif (ereg('^6011[0-9]{12}$', $this->cc_number)) {
	$this->cc_type = 'Discover';
  } elseif (ereg('^(3[0-9]{4}|2131|1800)[0-9]{11}$', $this->cc_number)) {
	$this->cc_type = 'JCB';
  } elseif (ereg('^5610[0-9]{12}$', $this->cc_number)) { 
	$this->cc_type = 'Australian BankCard';
  } else {
	return -1;
  }

 

to look like this:

	  if (ereg('^4[0-9]{12}([0-9]{3})?$', $this->cc_number)) {
	$this->cc_type = 'Visa';
  } else {
	return -1;
  }

Please use the forums for support! I am happy to help you here, but I am unable to offer free technical support over instant messenger or e-mail.

Link to comment
Share on other sites

Hi,

 

That is verry helpful, and i appreciate your help.

 

 

I just want to add another module, with the exact same capabilities that my cc.php has.

I will then edit the new module (lets call it ccc.php) and change the number of installments (payments).

 

That way i will have two credit card modules, one that supports up to 3 installments, and the other supports up

to 36 installments.

 

Thanks for all the help,

 

 

Eilon

Link to comment
Share on other sites

Hello Peter,

 

Im happy you have the answer. I cant find any documentation regarding the credit card module.

 

Can you write please, how do I create another credit card module using my old module?

 

(What do you mean "time-frame" ?)

Thanks,

 

Eilon

 

 

How soon would you need it?

Link to comment
Share on other sites

to look like this:

	  if (ereg('^4[0-9]{12}([0-9]{3})?$', $this->cc_number)) {
	$this->cc_type = 'Visa';
  } else {
	return -1;
  }

 

 

Yes...that's the easy part...but when you need 2 or more separate modules, you need to modify the copy of includes/modules/payment/cc.php and includes/classes/modules/payment/cc.php as well.

Link to comment
Share on other sites

in includes/modules/payment/ccc.php, use the following, but search and replace occurrences of "visa" with "ccc". (It is important that you do each search and replace as a case-sensitive search...visa to ccc, Visa to whatever you want to call the module in the shopping cart, and VISA to CCC)

 

<?php

/*

$Id: visa.php,v 1.10 2002/11/01 05:14:11 hpdl Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2002 osCommerce

 

Released under the GNU General Public License

*/

 

define('MODULE_PAYMENT_VISA_TEXT_TITLE', 'Visa');

define('MODULE_PAYMENT_VISA_TEXT_DESCRIPTION', 'Visa Test Info:<br><br>VISA#: 4111111111111111<br>Expiry: Any');

define('MODULE_PAYMENT_VISA_TEXT_CREDIT_CARD_TYPE', 'Credit Card Type:');

define('MODULE_PAYMENT_VISA_TEXT_CREDIT_CARD_OWNER', 'Credit Card Owner:');

define('MODULE_PAYMENT_VISA_TEXT_CREDIT_CARD_NUMBER', 'Credit Card Number:');

define('MODULE_PAYMENT_VISA_TEXT_CREDIT_CARD_EXPIRES', 'Credit Card Expiry Date:');

define('MODULE_PAYMENT_VISA_TEXT_JS_CC_OWNER', '* The owner\'s name of the credit card must be at least ' . CC_OWNER_MIN_LENGTH . ' characters.\n');

define('MODULE_PAYMENT_VISA_TEXT_JS_CC_NUMBER', '* The credit card number must be at least ' . CC_NUMBER_MIN_LENGTH . ' characters.\n');

define('MODULE_PAYMENT_VISA_TEXT_ERROR', 'Credit Card Error!');

?>

Link to comment
Share on other sites

in includes/modules/payment/ccc.php:

(The same instructions apply as for the previous one) visa becomes ccc, VISA becomes CCC

 

<?php

/*

$Id: visa.php,v 1.53 2003/02/04 09:55:01 project3000 Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

*/

 

class visa {

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

 

// class constructor

function visa() {

global $order;

 

$this->code = 'visa';

$this->title = MODULE_PAYMENT_VISA_TEXT_TITLE;

$this->description = MODULE_PAYMENT_VISA_TEXT_DESCRIPTION;

$this->sort_order = MODULE_PAYMENT_VISA_SORT_ORDER;

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

 

if ((int)MODULE_PAYMENT_VISA_ORDER_STATUS_ID > 0) {

$this->order_status = MODULE_PAYMENT_VISA_ORDER_STATUS_ID;

}

 

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

}

 

// class methods

function update_status() {

global $order;

 

if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_VISA_ZONE > 0) ) {

$check_flag = false;

$check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_VISA_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");

while ($check = tep_db_fetch_array($check_query)) {

if ($check['zone_id'] < 1) {

$check_flag = true;

break;

} elseif ($check['zone_id'] == $order->billing['zone_id']) {

$check_flag = true;

break;

}

}

 

if ($check_flag == false) {

$this->enabled = false;

}

}

}

 

function javascript_validation() {

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

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

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

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

' error_message = error_message + "' . MODULE_PAYMENT_VISA_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_VISA_TEXT_JS_CC_OWNER . '";' . "\n" .

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

' }' . "\n" .

' }' . "\n";

 

return $js;

}

 

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

}

 

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

'module' => $this->title,

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

'field' => tep_draw_input_field('cc_owner', $order->billing['firstname'] . ' ' . $order->billing['lastname'], $parameters='id="visa_owner"')),

array('title' => MODULE_PAYMENT_VISA_TEXT_CREDIT_CARD_NUMBER,

'field' => tep_draw_input_field('cc_number', '', $parameters='id="visa_number"')),

array('title' => MODULE_PAYMENT_VISA_TEXT_CREDIT_CARD_EXPIRES,

'field' => tep_draw_pull_down_menu('cc_expires_month', $expires_month, '', $parameters='id="visa_expires_month"') . ' ' . tep_draw_pull_down_menu('cc_expires_year', $expires_year, '', $parameters='id="visa_expires_year"'))));

 

return $selection;

}

 

function pre_confirmation_check() {

global $HTTP_POST_VARS;

 

include(DIR_WS_CLASSES . 'visa_validation.php');

 

$visa_validation = new visa_validation();

$result = $visa_validation->validate($HTTP_POST_VARS['cc_number'], $HTTP_POST_VARS['cc_expires_month'], $HTTP_POST_VARS['cc_expires_year']);

 

$error = '';

switch ($result) {

case -1:

$error = sprintf(TEXT_CCVAL_ERROR_UNKNOWN_CARD, substr($visa_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) . '&cc_owner=' . urlencode($HTTP_POST_VARS['cc_owner']) . '&cc_expires_month=' . $HTTP_POST_VARS['cc_expires_month'] . '&cc_expires_year=' . $HTTP_POST_VARS['cc_expires_year'];

 

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

}

 

$this->visa_card_type = $visa_validation->cc_type;

$this->visa_card_number = $visa_validation->cc_number;

}

 

function confirmation() {

global $HTTP_POST_VARS;

 

$confirmation = array('title' => $this->title . ': ' . $this->visa_card_type,

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

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

array('title' => MODULE_PAYMENT_VISA_TEXT_CREDIT_CARD_NUMBER,

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

array('title' => MODULE_PAYMENT_VISA_TEXT_CREDIT_CARD_EXPIRES,

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

 

return $confirmation;

}

 

function process_button() {

global $HTTP_POST_VARS;

 

$process_button_string = tep_draw_hidden_field('cc_owner', $HTTP_POST_VARS['cc_owner']) .

tep_draw_hidden_field('cc_expires', $HTTP_POST_VARS['cc_expires_month'] . $HTTP_POST_VARS['cc_expires_year']) .

tep_draw_hidden_field('cc_type', $this->visa_card_type) .

tep_draw_hidden_field('cc_number', $this->visa_card_number);

 

return $process_button_string;

}

 

function before_process() {

global $HTTP_POST_VARS, $order;

 

if ( (defined('MODULE_PAYMENT_VISA_EMAIL')) && (tep_validate_email(MODULE_PAYMENT_VISA_EMAIL)) ) {

$len = strlen($HTTP_POST_VARS['cc_number']);

 

$this->visa_middle = substr($HTTP_POST_VARS['cc_number'], 4, ($len-8));

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

}

}

 

function after_process() {

global $insert_id;

 

if ( (defined('MODULE_PAYMENT_VISA_EMAIL')) && (tep_validate_email(MODULE_PAYMENT_VISA_EMAIL)) ) {

$message = 'Order #' . $insert_id . "\n\n" . 'Middle: ' . $this->visa_middle . "\n\n";

 

tep_mail('', MODULE_PAYMENT_VISA_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_VISA_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_VISA_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_VISA_STATUS', 'True', 'Do you want to accept visa 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 ('Split Credit Card E-Mail Address', 'MODULE_PAYMENT_VISA_EMAIL', '', 'If an e-mail address is entered, the middle digits of the visa number will be sent to the e-mail address (the outside digits are stored in the database with the middle digits censored)', '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_VISA_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, use_function, set_function, date_added) values ('Payment Zone', 'MODULE_PAYMENT_VISA_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '2', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', 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_VISA_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())");

}

 

function remove() {

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

}

 

function keys() {

return array('MODULE_PAYMENT_VISA_STATUS', 'MODULE_PAYMENT_VISA_EMAIL', 'MODULE_PAYMENT_VISA_ZONE', 'MODULE_PAYMENT_VISA_ORDER_STATUS_ID', 'MODULE_PAYMENT_VISA_SORT_ORDER');

}

}

?>

Link to comment
Share on other sites

in includes/classes/

 

make a copy of cc_validation.php, and call it ccc_validation.php

 

The following is necessary only if you are going to have both cc and ccc available at the same time on the same page:

 

in yourdomain/yourcatalogdirectory/checkout_payment.php, add the following javascript code:

 

 

var selected;

var submittedForm;

 

function changeNames(submittedForm) {

var elementCounter;

for (elementCounter = 0; elementCounter < submittedForm.elements.length; elementCounter ++) {

if ((submittedForm.elements[elementCounter].type=="radio") && (submittedForm.elements[elementCounter].checked==true)) {

var paymentMethodUsed = submittedForm.elements[elementCounter].value;

}

}

for (elementCounter = 0; elementCounter < submittedForm.elements.length; elementCounter ++) {

if ((submittedForm.elements[elementCounter].id.indexOf(paymentMethodUsed) == -1) && (submittedForm.elements[elementCounter].name.indexOf("cc") != -1)) {

submittedForm.elements[elementCounter].name = '';

}

}

}

 

In this same file, find:

 

<?php echo tep_draw_form('checkout_payment', tep_href_link(FILENAME_CHECKOUT_CONFIRMATION, '', 'SSL'), 'post', 'id="checkout_payment" return check_form();"'); ?>

 

and change it to:

 

<?php echo tep_draw_form('checkout_payment', tep_href_link(FILENAME_CHECKOUT_CONFIRMATION, '', 'SSL'), 'post', 'id="checkout_payment" onsubmit="changeNames(this); return check_form();"'); ?>

 

That should do it for you. Install the ccc module as you would the cc module, and you will be able to use them as separate modules.

 

If you want to add others, you will need to add the 3 files, replacing ccc with whatever you wish.

Link to comment
Share on other sites

  • 3 weeks later...
Is there a way that I can make a copy of the "cc" or credit card payment module, and rename it "Visa"? I've tried to do this but without success. I've gotten as far as having the module work in the shopping area, but it fails to write the credit card number and other information to the database. I have a situation where I need to allow some credit cards for some zones, and others for other zones, and I figured the easiest way to do this is to create separate modules for each credit card. I think the difficulty is knowing what needs to be changed and what doesn't need to be changed.

 

Peter Anderson

 

I have a loosely related question that I'm hoping someone can help with. I am only accepting Visa & Mastercard currently. I have modifed the cc_validation.php file and removed the cards I'm not accepting. However, I would also like the add some text in the checkout screen the warn the customer that I only accept Visa & Master Card. I thought I could change the MODULE_PAYMENT_CC_TEXT_TITLE variable from "Credit Card" to "Visa/MasterCard" but that made the Credit Card module disappear in the Admin area.

 

Any tips on how and can change the radio button text from Credit Card to Visa/MasterCard or at least add text next to it.

 

Thanks

 

Keith

Link to comment
Share on other sites

Any tips on how and can change the radio button text from Credit Card to Visa/MasterCard or at least add text next to it.

 

Thanks

 

Keith

 

That should work...I tried it, and it didn't hurt anything. Are you sure that it isn't something else that is causing it?

 

Peter

Link to comment
Share on other sites

  • 1 month later...

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...