public List <RuleViolation> GetRuleViolations()
        {
            var violations = new List <RuleViolation>();

            // Card Number
            if (!CardNumber.StartsWith("****-****-****-"))
            {
                CardNumber = CardValidator.CleanCardNumber(CardNumber);
            }

            if (!CardValidator.IsCardNumberValid(CardNumber))
            {
                violations.Add(new RuleViolation("Credit Card Number", string.Empty, "Please enter a valid credit card number",
                                                 "cccardnumber"));
            }

            var cardTypeCheck = CardValidator.GetCardTypeFromNumber(CardNumber);
            var acceptedCards = HccApp.CurrentStore.Settings.PaymentAcceptedCards;

            if (!acceptedCards.Contains(cardTypeCheck))
            {
                violations.Add(new RuleViolation("Card Type Not Accepted", string.Empty,
                                                 "That card type is not accepted by this store. Please use a different card.", "cccardnumber"));
            }

            ValidationHelper.RequiredMinimum(1, "Card Expiration Year is required", ExpirationYear, violations,
                                             "ccexpyear");
            ValidationHelper.RequiredMinimum(1, "Card Expiration Month is required", ExpirationMonth, violations,
                                             "ccexpmonth");
            ValidationHelper.Required("Name on Card is required", CardHolderName, violations, "cccardholder");

            if (HccApp.CurrentStore.Settings.PaymentCreditCardRequireCVV)
            {
                ValidationHelper.RequiredMinimum(3, "Card Security Code is required", SecurityCode.Length, violations,
                                                 "ccsecuritycode");
            }

            SetErrorCss(violations);

            return(violations);
        }
Exemplo n.º 2
0
        public List <RuleViolation> GetRuleViolations()
        {
            var violations = new List <RuleViolation>();

            // Card Number
            if (!CardNumber.StartsWith("****-****-****-"))
            {
                CardNumber = CardValidator.CleanCardNumber(CardNumber);
            }

            if (!CardValidator.IsCardNumberValid(CardNumber))
            {
                violations.Add(new RuleViolation(Localization.GetString("CreditCardNumber"), string.Empty, Localization.GetString("CreditCardMessage"),
                                                 "cccardnumber"));
            }

            var cardTypeCheck = CardValidator.GetCardTypeFromNumber(CardNumber);
            var acceptedCards = HccApp.CurrentStore.Settings.PaymentAcceptedCards;

            if (!acceptedCards.Contains(cardTypeCheck))
            {
                violations.Add(new RuleViolation(Localization.GetString("CardTypeInvalid"), string.Empty,
                                                 Localization.GetString("CardTypeMessage"), "cccardnumber"));
            }

            ValidationHelper.RequiredMinimum(1, Localization.GetString("CardYearRequired"), ExpirationYear, violations,
                                             "ccexpyear");
            ValidationHelper.RequiredMinimum(1, Localization.GetString("CardMonthRequired"), ExpirationMonth, violations,
                                             "ccexpmonth");
            ValidationHelper.Required(Localization.GetString("CardNameRequired"), CardHolderName, violations, "cccardholder");

            if (HccApp.CurrentStore.Settings.PaymentCreditCardRequireCVV)
            {
                ValidationHelper.RequiredMinimum(3, Localization.GetString("CardCodeRequired"), SecurityCode.Length, violations, "ccsecuritycode");
            }

            SetErrorCss(violations);

            return(violations);
        }
Exemplo n.º 3
0
        public JsonResult CleanCreditCard(string number)
        {
            var cardNumber = CardValidator.CleanCardNumber(number);

            return(Json(cardNumber));
        }