public HttpResponseMessage Get(string cardNumber, string expiryYear) { HttpResponseMessage response = null; try { IValidationService validationService = new ValidationService(); var validationResult = validationService.Validate(cardNumber, expiryYear); if (!validationResult.IsValid) { response = new HttpResponseMessage() { Content = new JsonContent(validationResult) }; } else { ICardService cardService = new CardService(); int year = cardService.GetCardExpiryYear(expiryYear); ACard card = CardFactory.GetCard(cardNumber, year); var isValidCardNumber = card.IsValid(); response = new HttpResponseMessage() { Content = new JsonContent(new PaymentGW.Application.BounceContext.Validation.DTO.ValidationResult() { CardNumber = cardNumber, IsValid = isValidCardNumber, Message = string.Empty, CardType = card.GetCardType() }) }; } }catch (UnknownCardException uEx) { logger.Error(uEx); response = new HttpResponseMessage() { Content = new JsonContent(new PaymentGW.Application.BounceContext.Validation.DTO.ValidationResult() { CardNumber = cardNumber, IsValid = false, Message = "Card is unknonw" }) }; }catch (Exception ex) { logger.Error(ex); response = new HttpResponseMessage() { Content = new JsonContent(new PaymentGW.Application.BounceContext.Validation.DTO.ValidationResult() { CardNumber = cardNumber, IsValid = false, Message = "There are errors happens .Please contact the PaymentGW ." }) }; } return(response); }
public void Test_Valid_JCBCard_16Digit_StartWith3() { var cardNumber = "3111111111111111"; var expiryYear = 2019; ACard card = CardFactory.GetCard(cardNumber, expiryYear); Assert.IsTrue(card.IsValid()); Assert.AreEqual(CardType.JCB, card.GetCardType()); }
public void Test_Valid_MasterCard_PrimeNumber() { var cardNumber = "5111111111111111"; var expiryYear = 2017; ACard card = CardFactory.GetCard(cardNumber, expiryYear); Assert.IsTrue(card.IsValid()); Assert.AreEqual(CardType.Master, card.GetCardType()); }
public void Test_Valid_VisaCard_WithLeapYear() { var cardNumber = "4111111111111111"; var expiryYear = 2020; ACard card = CardFactory.GetCard(cardNumber, expiryYear); Assert.IsTrue(card.IsValid()); Assert.AreEqual(CardType.Visa, card.GetCardType()); }
public void Test_InValid_VisaCard_NotLeapYear() { var cardNumber = "4111111111111111"; var expiryYear = 2019; ACard card = CardFactory.GetCard(cardNumber, expiryYear); Assert.IsFalse(card.IsValid()); Assert.AreEqual(CardType.Visa, card.GetCardType()); }