function _valid_card_number in Ubercart 6.2
Same name and namespace in other branches
- 5 payment/uc_credit/uc_credit.module \_valid_card_number()
Validates a credit card number during checkout. See: http://www.merriampark.com/anatomycc.htm
2 calls to _valid_card_number()
- uc_payment_method_credit in payment/
uc_credit/ uc_credit.module - Callback function for the Credit Card payment method.
- uc_payment_method_credit_form in payment/
uc_credit/ uc_credit.module - Displays the credit card details form on the checkout screen.
File
- payment/
uc_credit/ uc_credit.module, line 1428 - Defines the credit card payment method and hooks in payment gateways.
Code
function _valid_card_number($number) {
$id = substr($number, 0, 1);
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) || !ctype_digit($number)) {
return FALSE;
}
$total = 0;
for ($i = 0; $i < strlen($number); $i++) {
$digit = substr($number, $i, 1);
if ((strlen($number) - $i - 1) % 2) {
$digit *= 2;
if ($digit > 9) {
$digit -= 9;
}
}
$total += $digit;
}
if ($total % 10 != 0) {
return FALSE;
}
return TRUE;
}