You are here

protected function CreditCardPaymentMethodBase::validateCvv in Ubercart 8.4

Validates a CVV number during checkout.

Parameters

string $cvv: CVV number as a string.

Return value

bool TRUE if CVV has the correct number of digits.

2 calls to CreditCardPaymentMethodBase::validateCvv()
CreditCardPaymentMethodBase::cartDetails in payment/uc_credit/src/CreditCardPaymentMethodBase.php
Returns the form or render array to be displayed at checkout.
CreditCardPaymentMethodBase::cartProcess in payment/uc_credit/src/CreditCardPaymentMethodBase.php
Called when checkout is submitted with this payment method selected.

File

payment/uc_credit/src/CreditCardPaymentMethodBase.php, line 734

Class

CreditCardPaymentMethodBase
Defines a base credit card payment method plugin implementation.

Namespace

Drupal\uc_credit

Code

protected function validateCvv($cvv) {
  $digits = [];
  $types = $this
    ->getEnabledTypes();
  if (!empty($types['visa']) || !empty($types['mastercard']) || !empty($types['discover'])) {
    $digits[] = 3;
  }
  if (!empty($types['amex'])) {
    $digits[] = 4;
  }

  // Fail validation if it's non-numeric or an incorrect length.
  if (!is_numeric($cvv) || count($digits) > 0 && !in_array(strlen($cvv), $digits)) {
    return FALSE;
  }
  return TRUE;
}