hubby2debbie Posted October 23, 2006 Share Posted October 23, 2006 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 Quote Link to comment Share on other sites More sharing options...
eilonfulman Posted November 6, 2006 Share Posted November 6, 2006 Hi, I also need to copy my cc module and have two modules for credit card. How do I copy the cc.php file into something like ccc.php ? what do i need to edit inside ccc.php so a new object will be created/used? thanks for the help Eilon Quote Link to comment Share on other sites More sharing options...
hubby2debbie Posted November 6, 2006 Author Share Posted November 6, 2006 I believe that I've figured out how to do this, but I will need to put a mod together for it. What time-frame are you looking at? Peter Quote Link to comment Share on other sites More sharing options...
eilonfulman Posted November 6, 2006 Share Posted November 6, 2006 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 Quote Link to comment Share on other sites More sharing options...
dynamoeffects Posted November 6, 2006 Share Posted November 6, 2006 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; } Quote 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 More sharing options...
eilonfulman Posted November 6, 2006 Share Posted November 6, 2006 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 Quote Link to comment Share on other sites More sharing options...
hubby2debbie Posted November 6, 2006 Author Share Posted November 6, 2006 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? Quote Link to comment Share on other sites More sharing options...
hubby2debbie Posted November 6, 2006 Author Share Posted November 6, 2006 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. Quote Link to comment Share on other sites More sharing options...
dynamoeffects Posted November 6, 2006 Share Posted November 6, 2006 Ah, excuse me, I missed the zone part. Quote 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 More sharing options...
hubby2debbie Posted November 6, 2006 Author Share Posted November 6, 2006 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!'); ?> Quote Link to comment Share on other sites More sharing options...
hubby2debbie Posted November 6, 2006 Author Share Posted November 6, 2006 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'); } } ?> Quote Link to comment Share on other sites More sharing options...
hubby2debbie Posted November 6, 2006 Author Share Posted November 6, 2006 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. Quote Link to comment Share on other sites More sharing options...
eilonfulman Posted November 7, 2006 Share Posted November 7, 2006 Many Many Many Thanks. I will get to test it today and again, I would like to say thank you for your help. Eilon Quote Link to comment Share on other sites More sharing options...
etzeppy Posted November 27, 2006 Share Posted November 27, 2006 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 Quote Link to comment Share on other sites More sharing options...
hubby2debbie Posted November 27, 2006 Author Share Posted November 27, 2006 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 Quote Link to comment Share on other sites More sharing options...
etzeppy Posted November 27, 2006 Share Posted November 27, 2006 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 I must be blind and/or stupid cause it worked for me the on the 2nd try. Thanks the reply. Keith Quote Link to comment Share on other sites More sharing options...
duzao7667 Posted January 26, 2007 Share Posted January 26, 2007 Hi! Somebody send this module to me please??? [email protected] Tnks very much. ^^ Quote Link to comment Share on other sites More sharing options...
hubby2debbie Posted January 26, 2007 Author Share Posted January 26, 2007 Hi!Somebody send this module to me please??? [email protected] Tnks very much. ^^ The full code and instructions are in posts 11 and 12 of this thread. Peter Anderson Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.