alesmith Posted August 30, 2008 Posted August 30, 2008 I found lots of threads discussing the fact that the credit card types in the standard cc_validate.php class (used by the cc.php payment module) were out of date but no solutions on how to bring it up to date Below is some revised code which adds checks for Visa Electron, Maestro, and Solo Warning: the data used for the card prefixes came from wikipedia [ http://en.wikipedia.org/wiki/Credit_card_numbers ] so I cannot certify that the number ranges are actually correct If you do not wish to accept some of the cards listed then comment out the appropriate lines Note that the order of the checks are important since some number ranges overlap with the Visa prefix of '4' Someone more competent than me with regular expressions could probably reduce the number of checks but this code worked for me so in the spirit of "if it ain't bust don't fix it" I left it as it is. To add the code go to /includes/classes/cc_validation.php and look for the validate() function around line 16. Inside that function replace the block of ereg checks with the checks below. All done! if (ereg('^491(7|3)[0-9]{12}$', $this->cc_number)) { $this->cc_type = 'Visa Electron'; } elseif (ereg('^4508[0-9]{12}$', $this->cc_number)) { $this->cc_type = 'Visa Electron'; } elseif (ereg('^4844[0-9]{12}$', $this->cc_number)) { $this->cc_type = 'Visa Electron'; } elseif (ereg('^417500[0-9]{10}$', $this->cc_number)) { $this->cc_type = 'Visa Electron'; } elseif (ereg('^(4903|4905|4911|4936|6333|6759)[0-9]{12}$', $this->cc_number)) { $this->cc_type = 'Maestro'; } elseif (ereg('^(4903|4905|4911|4936|6333|6759)[0-9]{14}$', $this->cc_number)) { $this->cc_type = 'Maestro'; } elseif (ereg('^(4903|4905|4911|4936|6333|6759)[0-9]{15}$', $this->cc_number)) { $this->cc_type = 'Maestro'; } elseif (ereg('^(564182|633110)[0-9]{10}$', $this->cc_number)) { $this->cc_type = 'Maestro'; } elseif (ereg('^(564182|633110)[0-9]{12}$', $this->cc_number)) { $this->cc_type = 'Maestro'; } elseif (ereg('^(564182|633110)[0-9]{13}$', $this->cc_number)) { $this->cc_type = 'Maestro'; } elseif (ereg('^4[0-9]{12}([0-9]{3})?$', $this->cc_number)) { $this->cc_type = 'Visa'; } elseif (ereg('^50(20|38)[0-9]{12}$', $this->cc_number)) { $this->cc_type = 'Maestro'; } elseif (ereg('^50(20|38)[0-9]{14}$', $this->cc_number)) { $this->cc_type = 'Maestro'; } elseif (ereg('^67(59|61)[0-9]{12}$', $this->cc_number)) { $this->cc_type = 'Maestro'; } elseif (ereg('^67(59|61)[0-9]{14}$', $this->cc_number)) { $this->cc_type = 'Maestro'; } elseif (ereg('^6304[0-9]{12}$', $this->cc_number)) { $this->cc_type = 'Maestro'; } elseif (ereg('^6304[0-9]{14}$', $this->cc_number)) { $this->cc_type = 'Maestro'; } elseif (ereg('^6(334|767)[0-9]{12}$', $this->cc_number)) { $this->cc_type = 'Solo'; } elseif (ereg('^6(334|767)[0-9]{14}$', $this->cc_number)) { $this->cc_type = 'Solo'; } elseif (ereg('^6(334|767)[0-9]{15}$', $this->cc_number)) { $this->cc_type = 'Solo'; } 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('^65[0-9]{14}$', $this->cc_number)) { $this->cc_type = 'Discover'; } 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; }
day2 Posted September 10, 2008 Posted September 10, 2008 Hi, Thanks for the info. I got issue with master card, where in my country, the master card Number start with 5400, but it can't be validated by this file, How do it change this?? } elseif (ereg('^5[1-5][0-9]{14}$', $this->cc_number)) { $this->cc_type = 'Master Card';
Recommended Posts
Archived
This topic is now archived and is closed to further replies.