Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Credit card error... occasionally


smartwork

Recommended Posts

Posted

We've had a few customers have a problem with submitting Visa numbers. As mentioned in another thread, I'm wondering if it's limited to debit cards.

 

Can someone break this code down and teach me what each part is validating:

 

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

 

We're only running the standard cc module - no other payment modules. I realize it's checking for the 4 as the 1st number, but can you tell me how the code works that validates the rest of the number. I thought that perhaps the [0-9]{12} meant that the next 12 digits can be 0-9, but then so can the last 3 so I wasn't sure why they're broken down into 2 groupings. Also, I noticed that the ? follows but it doesn't for the other card brand validations. Are those last 3 digits optional? Has Visa not always been 16 digits?

 

Once I know that, I can perhaps translate that into how the problem is happening with the numbers I've been given.

 

I've also read about issue with the standard cc module but I've not found the threads that were mentioned in regard to explaining those issues. Anyone know where that thread is?

 

Thanks!

Posted

There is a fairly lucid explanation of the regular expression syntax here:

http://www.phpbuilder.com/columns/dario19990616.php3

 

But I really don't believe there is any flaw in the code you snipped, as it is working fine for thousands of installations that accept VISA credit and debit cards.

 

If most VISA numbers are successful but there are isolated failures, take a more careful look at the details of the failures and errors reported.

Posted

Cool. Thanks for the link. After searching here on OSC, it appears that the error is not rare at all. It seems that a lot of people have this error and have varied solutions. The scary part is that most installations probably don't know of the occurrence until a customer emails them. As listed in one thread, just think of the sales lost due to the customer leaving and not contacting the company = no sale, and no feedback that the error appeared. Other threads indicate various Visa And Mastercard number configurations that were reported to give problems. Fortunately, we had been notified by customers or else we too would not have known about it.

 

Thanks again!

  • 2 weeks later...
Posted

What's the supposed problem? This pattern matches either 13 or 16 digits starting with 4, which is the format Visa has always used (going back to its BankAmericard days.)

 

Note that this pattern doesn't do anything more than detect it's a Visa. There's later code that validates the checksum - again, an algorithm that has never changed (I remember coding to it back in 1977.)

Posted

I searched here on OSC and found that there were quite a few people that had some whacked results even though the validation should be an easy condition to pass or fail. As for us, we were having Visa problems and others reported Visa and MC problems. If you search you can read the details on the digits that were giving each a problem. The bad part is that nobody probably realizes it until a customer reports it - which is how we discovered it.

 

Here is a solution that someone posted... which we are currently using:

 

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

    }  

  • 1 month later...

Archived

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

×
×
  • Create New...