function _valid_card_number in Ubercart 5
Same name and namespace in other branches
- 6.2 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 - uc_payment_method_credit_form in payment/
uc_credit/ uc_credit.module
File
- payment/
uc_credit/ uc_credit.module, line 1669 - 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;
}
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;
}