4 replies [Last post]
kerunt's picture
Offline
Bug Finder
Joined: 05/05/2008
Juice: 158
Was this information Helpful?

Hi all,

I'm developing a custom payment gateway for a payment provider called "Eigen," and while testing using their supplied credit card numbers I've ran into a problem: some CC numbers they supply are longer than the 16 digits that Ubercart allows.

According to http://www.merriampark.com/anatomycc.htm, "the maximum length of a credit card number is 19 digits."

Thoughts?

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Credit card - maximum length?

The maximum has been updated in 1.3 I believe. If not, it's at 19 now and will be in 1.4.

kerunt's picture
Offline
Bug Finder
Joined: 05/05/2008
Juice: 158
Re: Re: Credit card - maximum length?

Cool, thanks for the info. I guess I'll update my copy to 19 digits then Smiling.

kerunt's picture
Offline
Bug Finder
Joined: 05/05/2008
Juice: 158
kerunt wrote:Cool, thanks
kerunt wrote:

Cool, thanks for the info. I guess I'll update my copy to 19 digits then Smiling.

Changing the maxlength of the field wasn't as easy of a solution as I had hoped Eye-wink. Ubercart complains that the CC number is invalid, which probably means that it's failing the mod10 validation (which, I think, expects the CC number to be no longer than 16 digits in my old version)... the questions is, where is the validation being made? Can't seem to find the darn code Sad

//edit

Found function _valid_card_number($number) in credit.module Smiling. Time to dig in...

//edit 2

Love the comment right above the function Smiling :

<?php
/**
* Validate a credit card number during checkout.
* See: <a href="http://www.merriampark.com/anatomycc.htm
" title="http://www.merriampark.com/anatomycc.htm
">http://www.merriampark.com/anatomycc.htm
</a> */
?>

Same URL as I had posted above Eye-wink

kerunt's picture
Offline
Bug Finder
Joined: 05/05/2008
Juice: 158
Re: kerunt wrote:Cool, thanks

Here is my updated function which properly validates credit cards of all lengths:

<?php
   
function _valid_card_number($number)
    {
       
//don't cast as INT or use intval()! CC numbers are 16-19 digits, larger values
        //than the (2^31 - 1) that INT allows
       
$number = preg_replace('/[^0-9]/', '', $number);
       
       
$id = $number{0};
       
        if ((
$id == 3 && !variable_get('uc_credit_amex',         TRUE)) ||
            (
$id == 4 && !variable_get('uc_credit_visa',         TRUE)) ||
            (
$id == 5 && !variable_get('uc_credit_mastercard',    TRUE)) ||
            (
$id == 6 && !variable_get('uc_credit_discover',     TRUE)) ||
            !
is_numeric($number))
        {
            return
FALSE;
        }

       

$valid         = FALSE;
       
$multiply     = FALSE;
       
$sum         = 0;
       
$len         = strlen($number);

        for(

$i = $len - 1; $i >= 0; $i--)
        {
           
$add = 0;
           
$add = $number{$i} + ($number{$i} * $multiply);    // INT * TRUE = INT; INT * FALSE = 0
       
           
if($add > 9)
            {
               
$add -= 9;
            }
           
           
$sum += $add;
           
           
$multiply = !$multiply;
        }
       
        if(
$sum && $sum % 10 == 0)
        {
           
$valid = TRUE;
        }
       
        return
$valid;       
    }
?>

Might be useful to someone...

//edit
Function works but I just found something weird with my logic... which leads me to question why it works... give me a few min to figure this out Eye-wink

//edit2
Removed an unnecessary line - all is well Smiling.
Note to self: error_reporting(E_ALL); !!!!!!