SerbanG Posted May 23, 2004 Share Posted May 23, 2004 hello i have noticed that were a lot of discussions on the past about problems of validating visa and mastercard cards using the simple cc module of payment in oscommerce. for those who seek the answer, i pasted the entire code modified, of cc_validation.php: <?php /* $Id: cc_validation.php,v 1.3 2003/02/12 20:43:41 hpdl Exp $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2003 osCommerce Released under the GNU General Public License ###################################### ###################################### #########Serban Gheorghe Ghita######## ######[email protected]###### ####################################### ??FIX?? - for validation of mastercard and visa cards */ class cc_validation { var $cc_type, $cc_number, $cc_expiry_month, $cc_expiry_year; function validate($number, $expiry_m, $expiry_y) { $this->cc_number = ereg_replace('[^0-9]', '', $number); if (ereg('^4(.{12}|.{15})$', $this->cc_number)) { $this->cc_type = 'Visa'; } elseif (ereg('^5[1-5].{14}$', $this->cc_number)) { $this->cc_type = 'Master Card'; } elseif (ereg('^3[47].{13}$', $this->cc_number)) { $this->cc_type = 'American Express'; } elseif (ereg('^3(0[0-5].{11}|[68].{12})$', $this->cc_number)) { $this->cc_type = 'Diners Club'; } elseif (ereg('^6011.{12}$', $this->cc_number)) { $this->cc_type = 'Discover'; } elseif (ereg('^(3.{15}|(2131|1800).{11})$', $this->cc_number)) { $this->cc_type = 'JCB'; } elseif (ereg('^5610.{12}$', $this->cc_number)) { $this->cc_type = 'Australian BankCard'; } else { $this->cc_type = 'Unknown'; } /* class cc_validation { var $cc_type, $cc_number, $cc_expiry_month, $cc_expiry_year; function validate($number, $expiry_m, $expiry_y) { //$this->cc_number = ereg_replace('[^0-9]', '', $number); $this->cc_number = ereg_replace('[^[:digit:]]', '', $number); //if (ereg('^4[0-9]{12}([0-9]{3})?$', $this->cc_number)) { if (ereg('^4.{15}$|^4.{12}$', $this->cc_number)) { //^5[1-5].{14}$ //^4.{15}$|^4.{12}$ //[^[:digit:]] $this->cc_type = 'Visa'; // } elseif (ereg('^5[1-5][0-9]{14}$', $this->cc_number)) { } elseif (ereg('^5[1-5].{14}$', $this->cc_number)) { //} elseif (ereg("^5[0-9]{16}$", $this->cc_number) || eregi("^[0-9{2}/+[0-9]{2}", $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; } */ if (is_numeric($expiry_m) && ($expiry_m > 0) && ($expiry_m < 13)) { $this->cc_expiry_month = $expiry_m; } else { return -2; } $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->cc_expiry_year = $expiry_y; } else { return -3; } if ($expiry_y == $current_year) { if ($expiry_m < date('n')) { return -4; } } //return $this->is_valid(); return true; } /* function is_valid() { $cardNumber = strrev($this->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); } */ } ?> i have test it with numerous cc-s, valids and it works, and it doesn;t create any problems that i had in the past. i really hope this helps for some of you. serban Quote Serban Ghita - my blog Link to comment Share on other sites More sharing options...
stevel Posted May 23, 2004 Share Posted May 23, 2004 Um, so your "fix" is to disable the checksum validation? That doesn't sound like much of a fix to me. (Your fix also removes several card types from recognition - while that may be fine for some, it isn't relevant to the problem you claim to be solving.) Quote Steve Contributions: Country-State Selector Login Page a la Amazon Protection of Configuration Updated spiders.txt Embed Links with SID in Description Link to comment Share on other sites More sharing options...
SerbanG Posted May 24, 2004 Author Share Posted May 24, 2004 nope, my 'fix' is ONLY for that users that seemed to have problems with validating visa and mastercard on their site, i happen to do a lot of tests and it worked for me. IGNORE THIS FIX IF YOU DIDN't HAVE ANY PROBLEMS WITH CC VALIDATION Quote Serban Ghita - my blog Link to comment Share on other sites More sharing options...
stevel Posted May 24, 2004 Share Posted May 24, 2004 I'm sure it did work - you disabled all the validation. The only thing you left in was determinining the card type. Are there really valid Visa/MC cards out there with numbers that fail the checksum test? Seems highly implausible to me. Quote Steve Contributions: Country-State Selector Login Page a la Amazon Protection of Configuration Updated spiders.txt Embed Links with SID in Description Link to comment Share on other sites More sharing options...
John Doswell Posted May 24, 2004 Share Posted May 24, 2004 (edited) post deleted :ph34r: Edited May 24, 2004 by RobinsonDixon Quote Link to comment Share on other sites More sharing options...
davis Posted May 31, 2004 Share Posted May 31, 2004 hi- thank you for the fix, even if overrides the validation. for some reason one of my clients sites has been failing to validate visa and mastercard numbers for the past couple weeks more and more often though it works for me every time i run a test order with both real and random account numbers. i'm guessing it's a browser issue with some clients. anyway, thanks again for posting the scripting adjustment, it's a great solution for those people who proccess the charge at a later point in time anyway, if the card is bogus it will be declined then anyway:) Quote Link to comment Share on other sites More sharing options...
SerbanG Posted June 1, 2004 Author Share Posted June 1, 2004 thanks davis, my clients validate their customers credit cards by telephone or manual methods, si FOR THAT kind of shops is the code above. please leave this post undeleted because some may find it usefull. serban Quote Serban Ghita - my blog Link to comment Share on other sites More sharing options...
TomCavendish Posted June 7, 2004 Share Posted June 7, 2004 How would you add a UK Switch card to that code? Quote Link to comment Share on other sites More sharing options...
SerbanG Posted June 7, 2004 Author Share Posted June 7, 2004 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'; } elseif (ereg('^6759[0-9]{14}$',$this->cc_number)) { $this->cc_type = 'Switch'; } else { $this->cc_type = 'Unknown'; } for all major used cards, hope this helps, if not TomCavendish please show me an example of UK Switch card. serban Quote Serban Ghita - my blog Link to comment Share on other sites More sharing options...
TomCavendish Posted June 8, 2004 Share Posted June 8, 2004 (edited) Many thanks serban. I had a customer who couldn't make an order with a valid Mastercard. I used the code above, he tried again, and it worked! Also, I had a past order which wrongly identified a VISA card as JCB. I did a test order with the number, and it worked correctly as a VISA. Hopefully, Switch will work too. This code needs to be included in OSC. Thanks again. TC. Edited June 8, 2004 by TomCavendish Quote Link to comment Share on other sites More sharing options...
ScorpionWsM Posted June 8, 2004 Share Posted June 8, 2004 Tom, Not sure if you`ve tried it yet, but the Nochex option does every card I think now even credit cards. Your customers dont have to sign up either, they can just pay via it. Another good thing is that there is 0% chargebacks which from anyones point of view is well worth using the system. Worldpay is too expensive and risky as well if you have chargebacks, especially if your just starting off. Right I`m going to stop babbling and goto bed, already on 5 posts in 30 mins ;) Quote Link to comment Share on other sites More sharing options...
stevel Posted June 9, 2004 Share Posted June 9, 2004 The code that detects card type is not magic, and it doesn't change its behavior if you try again. If it is incorrectly determining the card type, then the customer is incorrectly entering the card number. This should be obvious if it works when retried. Quote Steve Contributions: Country-State Selector Login Page a la Amazon Protection of Configuration Updated spiders.txt Embed Links with SID in Description Link to comment Share on other sites More sharing options...
TomCavendish Posted June 18, 2004 Share Posted June 18, 2004 Using the new code, I placed an order with Switch and it was wrongly determined as 'Unknown'. :unsure: Quote Link to comment Share on other sites More sharing options...
stevel Posted June 18, 2004 Share Posted June 18, 2004 That's probably because the number was invalid, and the "new code" disables the validation. What were the first six digits? Quote Steve Contributions: Country-State Selector Login Page a la Amazon Protection of Configuration Updated spiders.txt Embed Links with SID in Description Link to comment Share on other sites More sharing options...
Guest Posted June 24, 2004 Share Posted June 24, 2004 Has anyone found a solution for adding Maestro, Delta, Solo and Switch? The fix is great but I am getting these cards as unknown. I am using the first 6 digits 564182 for Switch any help would be greatly appreciated Quote Link to comment Share on other sites More sharing options...
Guest Posted July 4, 2004 Share Posted July 4, 2004 Hi all on this thread, Slightly off topic, however, as a complete twit when it comes to messing with the coding on OS, rather than validating cards and having a clever module as this is. Is it possible to just add a few fields to this module and remove the validation? For example, how would i add card type drop down, start date, issue number and security code etc as i have to manually perform my credit card payments anyway. Even better still, has anyone any ideas on how to integrate optimal payments (firepay in disguise i think). Sorry if this is a dumb question and i have ruined the thread but i am goosed at the moment with this. I need a shopping cart mechanic part time, any offers? Best Regards and thanks in advance Paul 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.
Note: Your post will require moderator approval before it will be visible.