Ejemplo n.º 1
0
        //@NonNull
        //@CardBrand
        private static string GetPossibleCardType(string cardNumber, bool shouldNormalize)
        {
            if (string.IsNullOrWhiteSpace(cardNumber))
            {
                return(Card.UNKNOWN);
            }

            var spacelessCardNumber = cardNumber;

            if (shouldNormalize)
            {
                spacelessCardNumber = StripeTextUtils.RemoveSpacesAndHyphens(cardNumber);
            }

            if (StripeTextUtils.HasAnyPrefix(spacelessCardNumber, Card.PREFIXES_AMERICAN_EXPRESS))
            {
                return(Card.AMERICAN_EXPRESS);
            }
            else if (StripeTextUtils.HasAnyPrefix(spacelessCardNumber, Card.PREFIXES_DISCOVER))
            {
                return(Card.DISCOVER);
            }
            else if (StripeTextUtils.HasAnyPrefix(spacelessCardNumber, Card.PREFIXES_JCB))
            {
                return(Card.JCB);
            }
            else if (StripeTextUtils.HasAnyPrefix(spacelessCardNumber, Card.PREFIXES_DINERS_CLUB))
            {
                return(Card.DINERS_CLUB);
            }
            else if (StripeTextUtils.HasAnyPrefix(spacelessCardNumber, Card.PREFIXES_VISA))
            {
                return(Card.VISA);
            }
            else if (StripeTextUtils.HasAnyPrefix(spacelessCardNumber, Card.PREFIXES_MASTERCARD))
            {
                return(Card.MASTERCARD);
            }
            else
            {
                return(Card.UNKNOWN);
            }
        }
Ejemplo n.º 2
0
        public static bool IsValidCardNumber(string cardNumber)
        {
            var normalizedNumber = StripeTextUtils.RemoveSpacesAndHyphens(cardNumber);

            return(IsValidLuhnNumber(normalizedNumber) && IsValidCardLength(normalizedNumber));
        }