You are here

function pay_method_gateway::cc_number_validate in Pay 6

Same name and namespace in other branches
  1. 7 includes/handlers/pay_method_gateway.inc \pay_method_gateway::cc_number_validate()
1 call to pay_method_gateway::cc_number_validate()
pay_method_gateway::pay_method_validate in includes/handlers/pay_method_gateway.inc

File

includes/handlers/pay_method_gateway.inc, line 261
The base class for credit card payment activities.

Class

pay_method_gateway
@file The base class for credit card payment activities.

Code

function cc_number_validate() {
  $number = $this->cc_number;
  if (strlen($number) < 13 || strlen($number) > 19) {
    $this->error_message = t('Invalid credit card number.');
    return FALSE;
  }

  // Mod-10 credit card validation.
  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) {
    $this->error_message = t('Invalid credit card number.');
    return FALSE;
  }
  return TRUE;
}