Checks if credit card number fits the visa format.
431556
def is_visa(n):
    """"""
    n, length = str(n), len(str(n))

    if length >= 13 and length <= 16:
        if n[0] == '4':
            return True
    return False
1033073
@Override
  public final boolean isValid(final String pvalue, final ConstraintValidatorContext pcontext) {
    if (StringUtils.isEmpty(pvalue)) {
      return true;
    }
    if (pvalue.length() > LENGTH_CREDIT_CARDNUMBER) {
      // credit card number is to long, but that's handled by size annotation
      return true;
    }
    return CHECK_CREDIT_CARD.isValid(pvalue);
  }
847619
function pre_confirmation_check() {
    global $messageStack;

    include(DIR_WS_CLASSES . 'cc_validation.php');

    $cc_validation = new cc_validation();
    $result = $cc_validation->validate($_POST['authorizenet_aim_cc_number'], $_POST['authorizenet_aim_cc_expires_month'], $_POST['authorizenet_aim_cc_expires_year'], $_POST['authorizenet_aim_cc_cvv']);
    $error = '';
    switch ($result) {
      case -1:
      $error = sprintf(TEXT_CCVAL_ERROR_UNKNOWN_CARD, substr($cc_validation->cc_number, 0, 4));
      break;
      case -2:
      case -3:
      case -4:
      $error = TEXT_CCVAL_ERROR_INVALID_DATE;
      break;
      case false:
      $error = TEXT_CCVAL_ERROR_INVALID_NUMBER;
      break;
    }

    if ( ($result == false) || ($result < 1) ) {
      $messageStack->add_session('checkout_payment', $error . '<!-- ['.$this->code.'] -->', 'error');
      zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
    }

    $this->cc_card_type = $cc_validation->cc_type;
    $this->cc_card_number = $cc_validation->cc_number;
    $this->cc_expiry_month = $cc_validation->cc_expiry_month;
    $this->cc_expiry_year = $cc_validation->cc_expiry_year;
  }
1229644
public static function isCardToken($param)
	{
		$isValid = false;

		if(isset($param['cardToken'])){
			$isTokenEmpty = CheckoutApi_Lib_Validator::isEmpty($param['cardToken']);

			if(!$isTokenEmpty) {
				$isValid = true;
			}
		}

		return $isValid;
	}
1114423
protected function validateCreditCard($field, $value, $params)
    {
        /**
         * I there has been an array of valid cards supplied, or the name of the users card
         * or the name and an array of valid cards
         */
        if (!empty($params)) {
            /**
             * array of valid cards
             */
            if (\is_array($params[0])) {
                $cards = $params[0];
            } elseif (\is_string($params[0])) {
                $cardType = $params[0];
                if (isset($params[1]) && \is_array($params[1])) {
                    $cards = $params[1];
                    if (!\in_array($cardType, $cards, true)) {
                        return false;
                    }
                }
            }
        }


        if ($this->creditCardNumberIsValid($value)) {
            $cardRegex = [
                'visa' => '#^4[0-9]{12}(?:[0-9]{3})?$#',
                'mastercard' => '#^(5[1-5]|2[2-7])[0-9]{14}$#',
                'amex' => '#^3[47][0-9]{13}$#',
                'dinersclub' => '#^3(?:0[0-5]|[68][0-9])[0-9]{11}$#',
                'discover' => '#^6(?:011|5[0-9]{2})[0-9]{12}$#',
            ];

            if (isset($cardType)) {
                // if we don't have any valid cards specified and the card we've been given isn't in our regex array
                if (!isset($cards) && !isset($cardRegex[$cardType])) {
                    return false;
                }

                // we only need to test against one card type
                return (\preg_match($cardRegex[$cardType], $value) === 1);
            }

            if (isset($cards)) {
                // if we have cards, check our users card against only the ones we have
                foreach ($cards as $card) {
                    if (
                        isset($cardRegex[$card]) &&
                        \preg_match($cardRegex[$card], $value) === 1 // if the card is valid, we want to stop looping
                    ) {
                        return true;
                    }
                }
            } else {
                // loop through every card
                foreach ($cardRegex as $regex) {
                    // until we find a valid one
                    if (\preg_match($regex, $value) === 1) {
                        return true;
                    }
                }
            }
        }

        // if we've got this far, the card has passed no validation so it's invalid!
        return false;
    }
677219
public static boolean isValidTWCard(String idCard) {
		if(StrUtil.isEmpty(idCard)) {
			return false;
		}
		String start = idCard.substring(0, 1);
		String mid = idCard.substring(1, 9);
		String end = idCard.substring(9, 10);
		Integer iStart = twFirstCode.get(start);
		if(null == iStart) {
			return false;
		}
		int sum = iStart / 10 + (iStart % 10) * 9;
		final char[] chars = mid.toCharArray();
		Integer iflag = 8;
		for (char c : chars) {
			sum += Integer.valueOf(String.valueOf(c)) * iflag;
			iflag--;
		}
		return (sum % 10 == 0 ? 0 : (10 - sum % 10)) == Integer.valueOf(end) ? true : false;
	}
636512
public static function CreditCard ($value, $options) {
		//
		$number_pattern_list	= [
			'American Express'	=> [
				"/^34[0-9]{13}$/",
				"/^37[0-9]{13}$/",
			],
			'China UnionPay'	=> [
				"/^62212[6-9][0-9]{10}$/",
				"/^6221[3-9][0-9][0-9]{10}$/",
				"/^622[2-8] [0-9]{12}$/",
				"/^6229[01][0-9][0-9]{10}$/",
				"/^62292[0-5][0-9]{10}$/",
				"/^62[4-6][0-9]{13}$/",
				"/^628[2-8][0-9]{12}$/",
			],
			'Diners Club International'	=> [
				"/^300[0-9]{11}$/",
				"/^305[0-9]{11}$/",
				"/^3095[0-9]{10}$/",
				"/^36[0-9]{11}$/",
				"/^3[89][0-9]{12}$/",
			],
			'Discover Card'	=> [
				"/^60110[0-9]{11}$/",
				"/^6011[2-4][0-9]{11}$/",
				"/^60117[4-9][0-9]{10}$/",
				"/^60118[6-9][0-9]{10}$/",
				"/^60119[0-9][0-9]{10}$/",
				"/^64[4-9][0-9]{13}$/",
				"/^65[0-9]{14}$/",
			],
			'JCB'	=> [
				"/^352[89][0-9]{12}$/",
				"/^35[3-7][0-9]{12}$/",
				"/^358[1-9][0-9]{12}$/",
			],
			'MasterCard'	=> [
				"/^5[0-9]{15}$/",
			],
			'UATP'			=> [
				"/^1[0-9]{14}$/",
			],
			'Visa'			=> [
				"/^4[0-9]{13}(?:[0-9]{3})?$/",
			],
		];

		foreach ($number_pattern_list as $card_name => $pattern_list) {
			foreach ($pattern_list as $pattern) {
				if (1 === preg_match($pattern, $value)) {
					//チェックディジット
					for ($i = 0, $value = strrev($value), $alt = true, $total = 0; ($str = substr($value, $i, 1)) !== false;$total += $alt ? $str : ($str < 5 ? $str * 2 : 1 + ($str - 5) * 2), $alt = !$alt, $i++);
					return $total % 10 === 0;
				}
			}
		}

		return false;
	}
825041
private function validatePaymentMethodSpecific ()
	{
		$this->validate( 'paymentMethod' );
		switch ( $this->getPaymentMethod() ) {
			case 'ideal':
				$this->validate( 'issuer' );
				if ( $this->getCurrency() != 'EUR' )
					throw new InvalidRequestException( "Cardgate : iDeal only accepts EUR" );
				break;
			case 'mistercash':
				if ( $this->getCurrency() != 'EUR' )
					throw new InvalidRequestException( "Cardgate : Bancontact/Mistercash only accepts EUR" );
				break;
		}
	}
930731
public function isValid()
    {
        $requestPayment = $this->getRequestOrderPayment();
        $orderPayment = $this->getOrderPayment();

        $currencyPayPal = $requestPayment->getCurrency();
        $pricePayPal = $requestPayment->getAmount();

        $currencyPayment = $orderPayment->getCurrency();
        $amountPayment = $orderPayment->getAmount();

        return ($currencyPayPal == $currencyPayment && $pricePayPal == $amountPayment);
    }
1000420
private function getPatternType($cardNumber)
    {
        if (empty($cardNumber)) return;

        $types = [
            'visa'          => '(4\d{12}(?:\d{3})?)',
            'amex'          => '(3[47]\d{13})',
            'jcb'           => '(35[2-8][89]\d\d\d{10})',
            'maestro'       => '((?:5020|5038|6304|6579|6761)\d{12}(?:\d\d)?)',
            'solo'          => '((?:6334|6767)\d{12}(?:\d\d)?\d?)',
            'mastercard'    => '(5[1-5]\d{14})',
            'switch'        => '(?:(?:(?:4903|4905|4911|4936|6333|6759)\d{12})|(?:(?:564182|633110)\d{10})(\d\d)?\d?)',
        ];
        $names      = ['visa','amex', 'jcb', 'maestro', 'solo', 'mastercard', 'switch'];

        $matches    = [];

        $pattern    = "#^(?:" . implode('|', $types)  . ")$#";

        $result     = preg_match($pattern, str_replace(' ', '', $cardNumber), $matches);

        return $result > 0 ? $names[sizeof($matches)-2] : false;
    }
1049080
public static int recognizeVendor(long creditCardNumber) {
	int i = findMatchingRange(creditCardNumber);
	if (i < 0) {
	    return i;
	}
	return ranges[i].vendor;

    }
1350175
protected EmvCardScheme findCardScheme(final String pAid, final String pCardNumber) {
		EmvCardScheme type = EmvCardScheme.getCardTypeByAid(pAid);
		// Get real type for french card
		if (type == EmvCardScheme.CB) {
			type = EmvCardScheme.getCardTypeByCardNumber(pCardNumber);
			if (type != null) {
				LOGGER.debug("Real type:" + type.getName());
			}
		}
		return type;
	}
1187647
function javascript_validation() {
    if ($this->gateway_mode == 'offsite') return '';
    $js = '  if (payment_value == "' . $this->code . '") {' . "\n" .
          '    var cc_owner = document.checkout_payment.authorizenet_cc_owner.value;' . "\n" .
          '    var cc_number = document.checkout_payment.authorizenet_cc_number.value;' . "\n";
    if (MODULE_PAYMENT_AUTHORIZENET_USE_CVV == 'True')  {
      $js .= '    var cc_cvv = document.checkout_payment.authorizenet_cc_cvv.value;' . "\n";
    }
    $js .= '    if (cc_owner == "" || cc_owner.length < ' . CC_OWNER_MIN_LENGTH . ') {' . "\n" .
          '      error_message = error_message + "' . MODULE_PAYMENT_AUTHORIZENET_TEXT_JS_CC_OWNER . '";' . "\n" .
          '      error = 1;' . "\n" .
          '    }' . "\n" .
          '    if (cc_number == "" || cc_number.length < ' . CC_NUMBER_MIN_LENGTH . ') {' . "\n" .
          '      error_message = error_message + "' . MODULE_PAYMENT_AUTHORIZENET_TEXT_JS_CC_NUMBER . '";' . "\n" .
          '      error = 1;' . "\n" .
          '    }' . "\n";
    if (MODULE_PAYMENT_AUTHORIZENET_USE_CVV == 'True')  {
      $js .= '    if (cc_cvv == "" || cc_cvv.length < "3" || cc_cvv.length > "4") {' . "\n".
      '      error_message = error_message + "' . MODULE_PAYMENT_AUTHORIZENET_TEXT_JS_CC_CVV . '";' . "\n" .
      '      error = 1;' . "\n" .
      '    }' . "\n" ;
    }
    $js .= '  }' . "\n";
    return $js;
  }
972641
def check_payment(self, payment):
        
        validation = ""
        required = ["name", "IBAN", "BIC", "amount", "description"]

        for config_item in required:
            if config_item not in payment:
                validation += config_item.upper() + "_MISSING "

        if not isinstance(payment['amount'], int):
            validation += "AMOUNT_NOT_INTEGER "

        if 'execution_date' in payment:
            if not isinstance(payment['execution_date'], datetime.date):
                validation += "EXECUTION_DATE_INVALID_OR_NOT_DATETIME_INSTANCE"
            payment['execution_date'] = payment['execution_date'].isoformat()

        if validation == "":
            return True
        else:
            raise Exception('Payment did not validate: ' + validation)
444840
function validateCards(cards) {
  if (!Array.isArray(cards)) {
    throw new Error('`cards` must be passed as an array');
  }
  for (let i=0; i < cards.length; i++) {
    let card = cards[i];
    if (card.type !== RENDER_TYPE) {
      throw new Error(`Card "${card.name}" must be type "${RENDER_TYPE}", was "${card.type}"`);
    }
    if (!card.render) {
      throw new Error(`Card "${card.name}" must define \`render\``);
    }
  }
}
610823
public static function isValidCvv($card)
	{
		$isValid = false;

		if(isset($card['cvv'])) {

			$isCvvEmpty = CheckoutApi_Lib_Validator::isEmpty($card['cvv']);
			
			if(!$isCvvEmpty && CheckoutApi_Lib_Validator::isValidCvvLen($card['cvv'])) {
			
				$isValid = true;
			
			}
		}
		return $isValid;
	}
121043
function isCreditCard(val) {
  const digits = val.replace(/\D/g, '');
  const types = creditCardType(digits);
  if (!isArray(types) || isEmpty(types)) return false;
  let match = false;
  for (let t = 0; t < types.length; t++) {
    if (match) break;
    const type = types[t];
    // can match any one of the lengths
    if (!isArray(type.lengths) || isEmpty(type.lengths)) continue;
    for (let l = 0; l < type.lengths.length; l++) {
      const len = type.lengths[l];
      if (isFinite(len) && len === digits.length) {
        match = true;
        break;
      }
    }
  }

  return match;
}