chamtech Posted March 29, 2008 Posted March 29, 2008 Hello, I am a new member and I was testing the site for the CC validation and I was wondering how this function "is-valid" in cc_validation.php module validating a Credit Card number? 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); } Thanks
chamtech Posted March 29, 2008 Author Posted March 29, 2008 The reason I added this snipped code here is that I am trying to test my site with a credit card that is bogus and I keep getting an error message stating that this credit card is invalid and I traced it to this module and was surprised with the logic used to validate a credit card number!!
arietis Posted March 30, 2008 Posted March 30, 2008 Hello, I am a new member and I was testing the site for the CC validation and I was wondering how this function "is-valid" in cc_validation.php module validating a Credit Card number? a credit card number isn't just a random sequence of digits. only certain sixteen digit numbers are allowed and they must follow a set of 'rules.' this piece of code knows the rules and checks to see if the cc number entered follows them. they do this so that computer systems can validate whether or not the number is even 'legal' before looking it up in their database. so, knowing these rules, a simple validation can be made to ensure that the person is correctly entering their cc number before osc tries to use it for processing an order. the government does the same thing for social security numbers. in fact, there's more information encoded in a ss number - such as the place of your birth. somewhere i have code that can tell if you were born outside the us, and if inside, which state you were born in. i hope this answers your question.
chamtech Posted March 30, 2008 Author Posted March 30, 2008 Thanks Dave, My sole reason was testing and I found out that the CC test number for oscommerce is 4111111111111111. Cheers
Recommended Posts
Archived
This topic is now archived and is closed to further replies.