Beispiel #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);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets the <see cref="Brand"/> of this card. Updates the value if none has yet been set, or
        /// if the <see cref="Number"/> has been changed.
        /// </summary>
        /// <returns>the <see cref="Brand"/> of this card</returns>
        public string GetBrand()
        {
            if (string.IsNullOrWhiteSpace(Brand) && !string.IsNullOrWhiteSpace(Number))
            {
                /*@CardBrand*/
                String evaluatedType;
                if (StripeTextUtils.HasAnyPrefix(Number, PREFIXES_AMERICAN_EXPRESS))
                {
                    evaluatedType = AMERICAN_EXPRESS;
                }
                else if (StripeTextUtils.HasAnyPrefix(Number, PREFIXES_DISCOVER))
                {
                    evaluatedType = DISCOVER;
                }
                else if (StripeTextUtils.HasAnyPrefix(Number, PREFIXES_JCB))
                {
                    evaluatedType = JCB;
                }
                else if (StripeTextUtils.HasAnyPrefix(Number, PREFIXES_DINERS_CLUB))
                {
                    evaluatedType = DINERS_CLUB;
                }
                else if (StripeTextUtils.HasAnyPrefix(Number, PREFIXES_VISA))
                {
                    evaluatedType = VISA;
                }
                else if (StripeTextUtils.HasAnyPrefix(Number, PREFIXES_MASTERCARD))
                {
                    evaluatedType = MASTERCARD;
                }
                else
                {
                    evaluatedType = UNKNOWN;
                }

                Brand = evaluatedType;
            }

            return(Brand);
        }