/// <summary>
        /// Validate card number
        /// </summary>
        /// <param name="cardNumber">Card number</param>
        /// <returns>Validation result <see cref="ValidationResult" /> </returns>
        public object Validate([FromBody] string cardNumber)
        {
            try
            {
                if (cardNumber == null)
                {
                    return(BadRequest($"Card number not specified"));
                }

                decimal?cardNumberDec = CardNumberHelper.TryParse(cardNumber);
                if (cardNumberDec == null)
                {
                    return(BadRequest($"Invalid card number"));
                }

                var res = Repository.ValidateCard(cardNumberDec.Value);

                return(new ValidationResult
                {
                    CardType = res.CardType,
                    ValidationStatus = res.ValidationStatus,
                });
            }
            catch (Exception e)
            {
                Logger.Error(e, $"Validate cardNumber={cardNumber}");
                return(InternalServerError(e));
            }
        }
Exemplo n.º 2
0
        static void TestParseCardNumber(string cardNumberString, decimal?expectedCardNumber)
        {
            decimal?actualCardNumber = CardNumberHelper.TryParse(cardNumberString);

            Assert.AreEqual(expectedCardNumber, actualCardNumber);
        }
Exemplo n.º 3
0
 public void TestParseCardNumber15HyphenDelimValid()
 => Assert.AreEqual(123456789012345M, CardNumberHelper.TryParse("1234-567890-12345"));
Exemplo n.º 4
0
 public void TestParseCardNumber15MixDelimInvalid()
 => Assert.AreEqual(null, CardNumberHelper.TryParse("1234 567890-12345"));
Exemplo n.º 5
0
 public void TestParseCardNumber15WhitespaceDelimValid()
 => Assert.AreEqual(123456789012345M, CardNumberHelper.TryParse("1234 567890 12345"));
Exemplo n.º 6
0
 public void TestParseCardNumber16HyphenDelimValid()
 => Assert.AreEqual(1234567812345678M, CardNumberHelper.TryParse("1234-5678-1234-5678"));
Exemplo n.º 7
0
 public void TestParseCardNumberGreater16Invalid()
 => Assert.AreEqual(null, CardNumberHelper.TryParse("12345678123456781"));
Exemplo n.º 8
0
 public void TestParseCardNumber15Valid()
 => Assert.AreEqual(123456781234567M, CardNumberHelper.TryParse("123456781234567"));
Exemplo n.º 9
0
 public void TestParseCardNumberLess15Invalid()
 => Assert.AreEqual(null, CardNumberHelper.TryParse("12345678123456"));
Exemplo n.º 10
0
 public void TestParseCardNumberNonDigitCharsInvalid()
 => Assert.AreEqual(null, CardNumberHelper.TryParse("1234567812345A"));
Exemplo n.º 11
0
 public void TestParseCardNumberEmptyInvalid()
 => Assert.AreEqual(null, CardNumberHelper.TryParse(string.Empty));