Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Great CREDIT CARD validation scripts (php)-but I'm stuck!


Guest

Recommended Posts

Posted

Hope I don't break any "longest post" records - but I read this post by mickm - Mick. "Australian Bankcard fix......". It attracted no replies and only 8 views. I've found a code which could help him and many other people out with this problem (not only Aus Bankcard validators). For me, I'm really going to need some help to get this thing running!!! :?

 

Firstly mickm's post read:

Hi everyone.

 

I'm definately new to all this and after downloading/installing oscommerce I have found it's everything that I could ask for.

 

My only problem seems to be getting the program to accept credit card payments from an Australian Bankcard. Everything else seems to work. I have had a look through the forums and found various solutions to the question, however, they all seem to relate to the file ccval.php. I don't have this file in the snapshot that I had downloaded. The file that I found is called cc_validation.php. In there is the following code:

Code:

 

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

} else {

return -1;

 

Is there anyone who can help me with the lines to input for acceptance of Australian Bankcard? I have tried a few options, but I really think that this is above me. It's the only thing stopping me from getting the store going. Everything else is great.

 

Also... what code do I remove if I don't wish to accept cards like JCB, Discover, Diners and American Express?

 

Hoping someone can help.

 

....So I searched and found the source below on the net and will try to set it up. If someone else knows exactly what to do with this information or gets it going - they will help me out greatly.

 

I want to define my cards to - Visa, Mastercard, Australian Bankcard, JCB and American Express. I don't know if completely removing the non wanted card types will affect the running of the script or not? (Does anyone out there know?)

 

Anyway the information and the code(s) I found is this:

Credit Card Validation Solution (PHP Edition)

Version 4.6

Ensures credit card numbers are keyed in correctly. Includes checks that the length is correct, the first four digits are within accepted ranges, the number passes the Mod 10 Checksum and that you accept the given type of card. Just to be clear, this process does not check with banks or credit card companies to see if the card number given is actually associated with a good account. It just checks to see if the number matches the expected format.

 

The Credit Card Validation Solution is also available in Perl, JSP, Visual Basic and as a method in our Form Solution PHP class. Having the various languages available provides an excellent tutorial on Object Oriented Programming in different environments.

 

Before calling the function, you need to both have the object variable CCVSNumber set to the credit card number you want to check and create the array you'll use for the $Accepted argument. See the example at the bottom for clarification.

 

If the number passes all tests, the function returns TRUE after setting the CCVSType object variable to the name of the credit card company. Note: CCVSType is automatically determined from the first four digits of the card number. But, if a test fails, the function immediately returns FALSE and the CCVSError object variable will contain an explanation for the rejection.

 

In addition, this procedure cleans the CCVSNumber variable of all non-numeric characters, including whitespace. Plus, it creates the CCVSNumberLeft and CCVSNumberRight variables in the object which are handy when you want to securely save or display the account number without revealing the whole thing.

 

Warning: this function uses exact number ranges as part of the validation process. These ranges are current as of 20 October 1999. If presently undefined ranges come into use in the future, this program will improperly deject card numbers in such ranges, rendering an error message entitled "First four digits indicate we don't accept that type of card." If this happens while entering a card and type you KNOW are valid, please contact us so we can update the ranges.

 

Here's a list of card types this function checks. Note: these names are used both for the $Accepted array and the CCVSType.

 

American Express

Australian BankCard

Carte Blanche

Diners Club

Discover/Novus

JCB

MasterCard

Visa

Several people deserve praise for the Credit Card Validation Solution. I learned of the Mod 10 Algorithm in some Perl code, entitled "The Validator," available on Matt's Script Archive, http://www.scriptarchive.com/ccver.html. That code was written by David Paris, who based it on material Melvyn Myers reposted from an unknown author. Paris credits Aries Solis for tracking down the data underlying the algorithm. I then pruned down the algorithm to it's core components, making things smaller, cleaner and more flexible. My first attemts at this were in Visual Basic, on which Allen Browne and Rico Zschau assisted. Neil Fraser helped a bit on the Perl version. Steve Horsley, Roedy Green and Jon Skeet assisted on the JSP Edition.

 

<?php

 

# ------------------------------------------------------------------------

# Credit Card Validation Solution, version 4.6 PHP Edition

# 30 July 2002

#

# COPYRIGHT NOTICE:

# a) This code is property of The Analysis and Solutions Company.

# B) It is being distributed free of charge and on an "as is" basis.

# c) Use of this code, or any part thereof, is contingent upon leaving

# this copyright notice, name and address information in tact.

# d) Written permission must be obtained from us before this code, or any

# part thereof, is sold or used in a product which is sold.

# e) By using this code, you accept full responsibility for its use

# and will not hold the Analysis and Solutions Company, its employees

# or officers liable for damages of any sort.

# f) This code is not to be used for illegal purposes.

# g) Please email us any revisions made to this code.

# h) This code can not be reposted. Sites such as code repositories

# need to provide a link directly to our URI, below.

#

# Copyright 2002 http://www.AnalysisAndSolutions.com/code/ccvs-ph.htm

# The Analysis and Solutions Company [email protected]

#

# ------------------------------------------------------------------------

# DESCRIPTION:

# Ensures credit card numbers are keyed in correctly. Includes checks that

# the length is correct, the first four digits are within accepted ranges,

# the number passes the Mod 10 Checksum and that you accept the given type

# of card.

#

# A version of this function is integrated into our Form Solution class:

# http://www.FormSolution.info/

# ------------------------------------------------------------------------

 

 

class CreditCardValidationSolution {

 

function CCValidationSolution($Accepted) {

 

$this->CCVSNumberLeft = '';

$this->CCVSNumberRight = '';

 

# Avoid script dumping due to programming errors.

if ( !is_array($Accepted) ) {

$this->CCVSError = 'The programmer improperly used the Accepted argument.';

return FALSE;

}

 

# Catch malformed input.

if ( empty($this->CCVSNumber) OR !is_string($this->CCVSNumber) ) {

$this->CCVSNumber = '';

$this->CCVSError = "The number submitted wasn't a string.";

return FALSE;

}

 

# Ensure number doesn't overflow.

$this->CCVSNumber = substr($this->CCVSNumber, 0, 30);

 

# Remove non-numeric characters.

$this->CCVSNumber = ereg_replace('[^0-9]', '', $this->CCVSNumber);

 

# Set up variables.

$this->CCVSNumberLeft = substr($this->CCVSNumber, 0, 4);

$this->CCVSNumberRight = substr($this->CCVSNumber, -4);

$NumberLength = strlen($this->CCVSNumber);

 

# Determine the card type and appropriate length.

if ($this->CCVSNumberLeft >= 3000 and $this->CCVSNumberLeft <= 3059) {

$this->CCVSType = 'Diners Club';

$ShouldLength = 14;

} elseif ($this->CCVSNumberLeft >= 3600 and $this->CCVSNumberLeft <= 3699) {

$this->CCVSType = 'Diners Club';

$ShouldLength = 14;

} elseif ($this->CCVSNumberLeft >= 3800 and $this->CCVSNumberLeft <= 3889) {

$this->CCVSType = 'Diners Club';

$ShouldLength = 14;

 

} elseif ($this->CCVSNumberLeft >= 3400 and $this->CCVSNumberLeft <= 3499) {

$this->CCVSType = 'American Express';

$ShouldLength = 15;

} elseif ($this->CCVSNumberLeft >= 3700 and $this->CCVSNumberLeft <= 3799) {

$this->CCVSType = 'American Express';

$ShouldLength = 15;

 

} elseif ($this->CCVSNumberLeft >= 3528 and $this->CCVSNumberLeft <= 3589) {

$this->CCVSType = 'JCB';

$ShouldLength = 16;

 

} elseif ($this->CCVSNumberLeft >= 3890 and $this->CCVSNumberLeft <= 3899) {

$this->CCVSType = 'Carte Blanche';

$ShouldLength = 14;

 

} elseif ($this->CCVSNumberLeft >= 4000 and $this->CCVSNumberLeft <= 4999) {

$this->CCVSType = 'Visa';

if ($NumberLength > 14) {

$ShouldLength = 16;

} elseif ($NumberLength < 14) {

$ShouldLength = 13;

} else {

$this->CCVSError = 'Visa usually has 16 or 13 digits. You entered 14.';

return FALSE;

}

 

} elseif ($this->CCVSNumberLeft >= 5100 and $this->CCVSNumberLeft <= 5599) {

$this->CCVSType = 'MasterCard';

$ShouldLength = 16;

 

} elseif ($this->CCVSNumberLeft == 5610) {

$this->CCVSType = 'Australian BankCard';

$ShouldLength = 16;

 

} elseif ($this->CCVSNumberLeft == 6011) {

$this->CCVSType = 'Discover/Novus';

$ShouldLength = 16;

 

} else {

$this->CCVSType = '';

$this->CCVSError = "First four digits, $this->CCVSNumberLeft, indicate we don't accept that type of card.";

return FALSE;

}

 

# Do you accpet this type of card?

if ($Accepted[0] != 'All') {

$Accept = 0;

while ( list(,$Type) = each($Accepted) ) {

if ($Type == $this->CCVSType) {

$Accept = 1;

}

}

if (!$Accept) {

$this->CCVSError = "We don't accept $this->CCVSType cards.";

return FALSE;

}

}

 

# Is the length correct?

if ($NumberLength <> $ShouldLength) {

$Missing = $NumberLength - $ShouldLength;

if ($Missing < 0) {

$this->CCVSError = 'Number is missing ' . abs($Missing) . ' digit(s).';

} else {

$this->CCVSError = "Number has $Missing too many digit(s).";

}

return FALSE;

}

 

# Start the Mod10 checksum process...

$Checksum = 0;

 

# Add even digits in even length strings

# or odd digits in odd length strings.

for ($Location = 1 - ($NumberLength % 2); $Location < $NumberLength; $Location += 2) {

$Checksum += substr($this->CCVSNumber, $Location, 1);

}

 

# Analyze odd digits in even length strings

# or even digits in odd length strings.

for ($Location = ($NumberLength % 2); $Location < $NumberLength; $Location += 2) {

$Digit = substr($this->CCVSNumber, $Location, 1) * 2;

if ($Digit < 10) {

$Checksum += $Digit;

} else {

$Checksum += $Digit - 9;

}

}

 

# If the checksum is divisible by 10, the number passes.

if ($Checksum % 10 == 0) {

$this->CCVSError = '';

return TRUE;

} else {

$this->CCVSError = 'Card failed the checksum test.';

return FALSE;

}

}

}

 

 

 

 

# ------------------------------------------------------------------------

# ------------------------------------------------------------------------

#

# Example of how to use the Credit Card Validation Solution.

#

# Make sure the code from above is in (or included in) your

# script and then do this...

 

?>

<html>

<head>

<title>Credit Card Validation Solution: Test PHP Edition</title>

</head>

<body>

<?php

 

$Form = new CreditCardValidationSolution;

 

if ( empty($HTTP_POST_VARS['Number']) ) {

$Form->CCVSNumber = '4002417016240182';

 

} else {

$Form->CCVSNumber = $HTTP_POST_VARS['Number'];

 

# Put the names of the card types you accept in here.

# If you want to accept all card types, just put 'All'.

$Accept = array('Visa', 'American Express', 'Australian BankCard');

 

if ( !$Form->CCValidationSolution($Accept) ) {

echo " <p>PROBLEM: $Form->CCVSError</p>";

} else {

echo " <p>That $Form->CCVSType card number seems good.</p>";

}

}

 

?>

 

<form method="post">

<input type="text" name="Number" value="<?php echo $Form->CCVSNumber; ?>" />

<input type="submit" name="Submit" value="Test" />

</form>

</body>

</html>

 

 

--------------------------------------------------------------------------------

 

The Analysis and Solutions Company. More than just answers. Solutions.SM

 

v: 718-854-0335 f: 718-854-0409

w: www.analysisandsolutions.com e: [email protected]

m: 4015 7th Ave Apt 4AJ, Brooklyn NY 11232-3715

 

I guess I turn the first bit of code into cc_validation.php. I am not sure where to place the second piece of script - ie which file to use or do I make a new one??

 

Don't even know if it will work with oscom. I thought if I bring the code - someone may bring the brains - Any help greatly appreciated.

Posted

First you must ask the author if he is willing to release his source under the terms of the GNU/GPL. The current copyright notices and restrictions of use are incompatible with the GNU/GPL - the license we use for osCommerce. So currently we cannot use this sourec code.

 

Should I work on that part? ;-)

You can't have everything. That's why trains have difficulty crossing oceans, and hippos did not adapt to fly. -- from the OpenBSD mailinglist.

Posted

What do you think, is it a workable piece of information that everyone can benefit from? My understanding is that Me personally can use this code in any of my scripts as long as I don't sell it. From your point of view I can see the conflict, but there's no transaction so I would think they'd find it OK. Is pursuing this for the GNU/GPL something you believe is worthwhile for the OS community?

Posted

Having more source code under GNU/GPL is always good ;-)

 

If we should think about including that cod ein osCommerce we certainly need it to be under GNU/GPL. And if the author does not want that to happen we will have to look for something else. Or keep the current code.

You can't have everything. That's why trains have difficulty crossing oceans, and hippos did not adapt to fly. -- from the OpenBSD mailinglist.

Posted

Can I personally use it! Am I allowed to ask for help to get it running in this forum?

Posted

You can peronally use it. You can ask for help. But you may not distribute your solution.

You can't have everything. That's why trains have difficulty crossing oceans, and hippos did not adapt to fly. -- from the OpenBSD mailinglist.

Posted

osCommerce was using an older script version which Ken posted in his message.

 

I was in contact with the authors regarding permission to use it in the project and after receiving "we havent forgotten, we'll reply again soon" I did not hear from them again so the script was replaced with what's currently in CVS.

 

If you can find out the format of how the Australian Bankcard number is generated, a regular expression can be made to add to the validation logic.

:heart:, osCommerce

Posted

I'm just taking a guess here, but would the following code work?

 

 

} elseif (ereg('^5610[0-9]{12}$', $this->cc_number)) { 

$this->cc_type = 'Australian BankCard';



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

} else { 

return -1;

"The price of success is perseverance. The price of failure comes much cheaper."

Posted
I'm just taking a guess here, but would the following code work?

 

} elseif (ereg('^5610[0-9]{12}$', $this->cc_number)) { 

$this->cc_type = 'Australian BankCard';

 

Yes :D

:heart:, osCommerce

Posted

Whoops!

I forgot to mention that the code I entered previously isn't in the correct order.

The correct order is to enter the code somewhere AFTER the first IF statement since it's and ELSEIF, and not an IF statement itself.

 

Example:

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('^5610[0-9]{12}$', $this->cc_number)) { 

$this->cc_type = 'Australian BankCard';



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

} else { 

return -1;

 

Also, can someone please shed some light on the format of the calculations performed?

 

In the following code:

 

} elseif (ereg('^5610[0-9]{12}$', $this->cc_number)) { 

$this->cc_type = 'Australian BankCard';

 

Does the {12} equal 12 variables in ADDITION to 4 constants (5610), or does this equal 12 numbers in total?

An Australian Bankcard uses 16 numbers, so I've just taken a guess that it equals the 12 in addition to the 4 constants in my example code.

 

Thanks,

Tony

"The price of success is perseverance. The price of failure comes much cheaper."

Posted
In the following code:

 

} elseif (ereg('^5610[0-9]{12}$', $this->cc_number)) { 

$this->cc_type = 'Australian BankCard';

 

Does the {12} equal 12 variables in ADDITION to 4 constants (5610)

 

It means twelve times the preceding item, which is [0-9] meaning any digit.

 

So the expression will match '5' immediately followed by '6', '1' and '0' then 12 digits.

Christian Lescuyer

Posted

Thanks Christian!

 

I'm starting to get the hang of this PHP code! :D

 

So, there we have it... a way to validate an Australian BankCard.

"The price of success is perseverance. The price of failure comes much cheaper."

Posted

As I peeked my head in to see if there was a reply to my question, I noticed Tony's entry...

 

All I can say is THANK YOU GUYS!!! It worked a treat :) as I breathe a sigh of relief as I put my credit card in for validation and it worked!!!

 

Again thanks for your input...

 

P.S.

 

If I don't want to have one of the cards (for example American Express) in there do I just delete the entry for that?

 

Thanks in advance...

Mick

Posted

Yep,

Just delete the associated AMEX code and the card will return a non-valid value, therefore won't be validated.

(At least this is the logical way I see it... please let me know if I'm wrong)

 

Just remember to remove the correct lines of code with each card you want to remove, as you can see the lines are bit upside down with the card calculations above the card named.

 

Example:

Removing the following lines will remove American Express and Diners Club from the validation script.

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

"The price of success is perseverance. The price of failure comes much cheaper."

Posted

If you wanted you might want to prepare your file so that you may take on other cards in the future and rather than delete anything just // it out for now:

//( ($NumberLeft >= 3000) && ($NumberLeft <= 3059) ) {

// $CardName = 'Diners Club';

// $ShouldLength = 14;

// } elseif ( ($NumberLeft >= 3600) && ($NumberLeft <= 3699) ) {

// $CardName = 'Diners Club';

// $ShouldLength = 14;

// } elseif ( ($NumberLeft >= 3800) && ($NumberLeft <= 3889) ) {

// $CardName = 'Diners Club';

// $ShouldLength = 14;

if ( ($NumberLeft >= 3400) && ($NumberLeft <= 3499) ) {

$CardName = 'American Express';

$ShouldLength = 15;

} elseif ( ($NumberLeft >= 3700) && ($NumberLeft <= 3799) ) {

$CardName = 'American Express';

$ShouldLength = 15;

} elseif ( ($NumberLeft >= 3528) && ($NumberLeft <= 3589) ) {

$CardName = 'JCB';

$ShouldLength = 16;

// } elseif ( ($NumberLeft >= 3890) && ($NumberLeft <= 3899) ) {

// $CardName = 'Carte Blache';

// $ShouldLength = 14;

} elseif ( ($NumberLeft >= 4000) && ($NumberLeft <= 4999) ) {

$CardName = 'Visa';

if ($NumberLength > 14) {

$ShouldLength = 16;

} elseif ($NumberLength < 14) {

$ShouldLength = 13;

}

} elseif ( ($NumberLeft >= 5100) && ($NumberLeft <= 5599) ) {

$CardName = 'MasterCard';

$ShouldLength = 16;

} elseif ($NumberLeft == 5610) {

$CardName = 'Australian BankCard';

$ShouldLength = 16;

// } elseif ($NumberLeft == 6011) {

// $CardName = 'Discover/Novus';

// $ShouldLength = 16;

} else {

$cc_val = sprintf(TEXT_CCVAL_ERROR_UNKNOWN_CARD, $NumberLeft);

return $cc_val;

}

ie: I've removed Diners but might have them soon as they are reasonably popular. I won't need Discover/Novus or Carte Blanche now. Note: I've had to move the "IF" statement down.

  • 3 months later...
Posted

I've just stumbled across this thread and read through it twice..

 

I have a problem with a customers mastercard (Its American)

 

The first 4 digits are 5491 and oscommerce rejects the card as if we do not accept it... Now from what I have read the first 4 digits tells us what type of card it is and lets oscommerce know if its accepted or not...

 

How do I change my current settings to accept this (and possibly other) cards that are currently not accepted..

 

Apologies if the answer is staring me right in the face and am still a little new to all this...

Posted

John,

According to the cc_validation.php file, your card should already be accepted.

 

Try the following and see if this make a difference.

To use the American Mastercard with the validation script, add the following code to your 'catalog/includes/classes/cc_validation.php' file.

 

} elseif (ereg('^5491[0-9]{12}$', $this->cc_number)) { 

$this->cc_type = 'Master Card';

 

So your entire cc_validation.php file will now look like:

<?php

/*

 $Id: cc_validation.php,v 1.1 2002/11/01 02:13:21 hpdl Exp $



 osCommerce, Open Source E-Commerce Solutions

 http://www.oscommerce.com



 Copyright (c) 2002 osCommerce



 Released under the GNU General Public License

*/

/*

Modifications listed:

Australian BankCard

American Mastercard

*/





 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[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('^5491[0-9]{12}$', $this->cc_number)) { 

       $this->cc_type = 'Master Card';

     } elseif (ereg('^5610[0-9]{12}$', $this->cc_number)) {

       $this->cc_type = 'Australian BankCard';

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

     } 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();

   }



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

   }

 }

?>

 

Let me know how you go...

 

Hope this helps,

Tony

"The price of success is perseverance. The price of failure comes much cheaper."

Posted

Hey Tony..

 

Where do I find cc_validation.php ? All I can find is cc.php in includes/modules/payments ??

 

I am using 2.2 MS1

 

 

 

Thanks again.

Posted

Found it...Duh

 

I'll let you know... Thanks

Posted

I did a copy and paste of the code you posted and my mastercard still works (it always did though). I guess I wait and see if anyone else has problems...

 

Thanks for the help Tony... It is appreciated !!!

  • 1 month later...
Posted

If we are using Authorize.net...can we just comment out the credit card types and let them all pass through and simply let Authorize.net do the validation?

Posted
If we are using Authorize.net...can we just comment out the credit card types and let them all pass through and simply let Authorize.net do the validation?

 

I'm getting this error no matter what CC I enter

"The first four digits of the number entered are: <br>If that number is correct, we do not accept that type of credit card.<br>If it is wrong, please try again."

 

I like to skip CC validation for now

Posted

Okay...I had a customer with a '4366xxx' credit card number in the US.

 

It is a valid card number. I have attempted several modifications to catalog/includ/classes/cc_validation.php with the ereg commands, but the card number still was not accepted.

 

I figured, from similar postings that this had to do with the Luhn/Mod10 check (thanks Mattice) which is located towards the bottom. I hate hard coding and this may not work for someone else, but orders are still coming in. (see edits below)

 

I use Authorize.net to validate the numbers. I did, however, leave in the credit card exp date validity check.

 

Please save your original file as cc_validation_original.php

 

Here is what I did to the cc_validation.php file. My changes are in red (not using the code tags so as to highlight in color):

-----------------------------------------------------------------------

 

<?php

/*

$Id: cc_validation.php,v 1.1 2002/11/01 02:13:21 hpdl Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2002 osCommerce

 

Released under the GNU General Public License

*/

/*

Modifications listed:

Australian BankCard

American Mastercard

*/

 

 

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[0-9]{12}([0-9]{3})?$', $this->cc_number)) {

$this->cc_type = 'Visa';

} elseif (ereg('^4366[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('^5491[0-9]{12}$', $this->cc_number)) {

$this->cc_type = 'Master Card';

} elseif (ereg('^5610[0-9]{12}$', $this->cc_number)) {

$this->cc_type = 'Australian BankCard';

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

// changed the following line so that no '-1' is returned as a reject

$this->cc_type = 'Visa';

//Authorize.net doesn't care what the cc_type is. If you are not using Anet

//you might care

[/color]}

 

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();

}

 

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;

}

// comment out the following line for validation check

// $numSum += $currentNum;

// added the following line to send number through as good

// I will let Authorize.net verify the card

return ($numSum % 10 == 0);

}

 

// If the total has no remainder it's OK

return ($numSum % 10 == 0);

}

}

?>

Posted

While on the subject of Credit card validation, does anybody know the correct regular expressions to use for accepting the UK Debit cards - Switch, Solo and Delta?

 

I am currently using some code from a contribution, but the code is less than elegant and I do not have a lot of faith in it....

 

I have searched and searched on Google but it seems almost impossible to find any scripts or information on validating these debit cards :(

Archived

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

×
×
  • Create New...