예제 #1
0
		public ValidationResponse Validate(string entry, ICardNetwork cardNetwork, List<CardNetwork> acceptableCardNetworksForTransaction)
		{
			return ValidateDate(entry, _dateToMessaureFrom, (entryDate, dateToMeasureFrom) => 
			{
				return (entryDate <= dateToMeasureFrom || (entryDate.Month == dateToMeasureFrom.Month && entryDate.Year == dateToMeasureFrom.Year)) && entryDate >= dateToMeasureFrom.AddYears(-10); 
			}, "Check start date");
		}
예제 #2
0
		public ValidationResponse Validate(string entry, ICardNetwork cardNetwork, List<CardNetwork> acceptableCardNetworksForTransaction)
		{
			int i;
			entry = entry ?? string.Empty;
			var valid = int.TryParse(entry, out i) && entry.Length > 0 && entry.Length <= cardNetwork.GetIssueNumberLength();
			var errorMessage = !valid ? "Check issue number" : string.Empty;
			return new ValidationResponse(valid, errorMessage, !string.IsNullOrWhiteSpace(errorMessage) && entry.Length > 0);
		}
		public void RunTests(int testId, string issueNumberEntry, ICardNetwork cardNetwork, bool expectedPass, bool expectedShouldDisplayErrorMessage, string expectedErrorMessage)
		{
			var sut = new IssueNumberValidator();
			var actualPass = sut.Validate(issueNumberEntry, cardNetwork, new List<CardNetwork> { cardNetwork.GetCardNetworkType() });
			Assert.That(actualPass.IsValid, Is.EqualTo(expectedPass));
			Assert.That(actualPass.ErrorMessage, Is.EqualTo(expectedErrorMessage));
			Assert.That(actualPass.ShouldDisplayErrorMessage, Is.EqualTo(expectedShouldDisplayErrorMessage));
		}
		public void RunTests(int testId, string expiryDateExpiry, ICardNetwork cardNetwork, bool expectedPass, bool expectedShouldDisplayErrorMessage, string expectedErrorMessage, DateTime dateToMeasureFrom)
		{
			var sut = new ExpiryDateValidator(dateToMeasureFrom);
			var actualPass = sut.Validate(expiryDateExpiry, cardNetwork, new List<CardNetwork> { cardNetwork.GetCardNetworkType() });
			Assert.That(actualPass.IsValid, Is.EqualTo(expectedPass));
			Assert.That(actualPass.ErrorMessage, Is.EqualTo(expectedErrorMessage));
			Assert.That(actualPass.ShouldDisplayErrorMessage, Is.EqualTo(expectedShouldDisplayErrorMessage));
		}
예제 #5
0
		private void AssertCardNetwork(ICardNetwork actualCardNetwork, CardNetwork cardNetwork, string securityCode, int securityCodeLength, int cardNumberLength, bool shouldDisplayStartDate, bool shouldDisplayIssueNumber)
		{
			Assert.That(actualCardNetwork.GetCardNetworkType(), Is.EqualTo(cardNetwork));
			Assert.That(actualCardNetwork.GetSecurityCodeLabel(), Is.EqualTo(securityCode));
			Assert.That(actualCardNetwork.GetSecurityCodeLength(), Is.EqualTo(securityCodeLength));
			Assert.That(actualCardNetwork.GetCardNumberLength(), Is.EqualTo(cardNumberLength));
			Assert.That(actualCardNetwork.ShouldDisplayStartDate(), Is.EqualTo(shouldDisplayStartDate));
			Assert.That(actualCardNetwork.ShouldDisplayIssueNumber(), Is.EqualTo(shouldDisplayIssueNumber));
		}
예제 #6
0
		public ValidationResponse Validate(string entry, ICardNetwork cardNetwork, List<CardNetwork> acceptableCardNetworksForTransaction)
		{
			int i;
			entry = entry ?? string.Empty;
			var valid = int.TryParse(entry, out i) && entry.Length == cardNetwork.GetSecurityCodeLength();
			var errorMessage = string.Empty;

			if (!valid && entry.Length >= cardNetwork.GetSecurityCodeLength())
			{
				errorMessage = "Check security code";
			}

			return new ValidationResponse(valid, errorMessage, !string.IsNullOrWhiteSpace(errorMessage));
		}
		public TokenPaymentDefaultsViewModel(string lastFour, string expiryDate, string cardToken, string consumerToken, CardNetwork cardNetwork)
		{
			var unformattedLastFour = lastFour ?? string.Empty;
			var unformattedExpiryDate = expiryDate ?? string.Empty;
			CardToken = cardToken;
			ConsumerToken = consumerToken;

			CardNetork = CardNetorkDiscoverer.DiscoverCardNetwork(cardNetwork);

			var masklength = CardNetork.GetCardNumberLength() - unformattedLastFour.Length;
			var mask = string.Concat(Enumerable.Repeat("*", masklength));

			MaskedCardNumber = string.Concat(mask, lastFour).FormatToJudoString(CardNetork.CardNumberFormat());
			ExpiryDate = unformattedExpiryDate.FormatToJudoString(DateFormat);
		}
예제 #8
0
		public ValidationResponse Validate(string entry, ICardNetwork cardNetwork, List<CardNetwork> acceptableCardNetworksForTransaction)
		{
			var strippedEntry = (entry ?? string.Empty).Replace(" ", string.Empty);

			var regex = new Regex(_country.GetPostcodeRegex(), RegexOptions.IgnoreCase);
			var match = regex.Match(strippedEntry);

			var errorMessage = string.Empty;

			if (!match.Success && strippedEntry.Length >= _country.GetPostcodeLength())
			{
				errorMessage = string.Format("Check {0}", _country.GetPostcodeTitle());
			}

			return new ValidationResponse(match.Success, errorMessage, !string.IsNullOrWhiteSpace(errorMessage));
		}
예제 #9
0
		public ValidationResponse Validate(string entry, ICardNetwork cardNetwork, List<CardNetwork> acceptableCardNetworksForTransaction)
		{
			var strippedEntry = (entry ?? string.Empty).Replace(" ", "");
			var errorMessage = string.Empty;

			var networkAccepted = cardNetwork.CardNetworkAcceptedForTransaction(cardNetwork.GetCardNetworkType(), acceptableCardNetworksForTransaction);
			var cardNumberIsValid = cardNetwork.IsCardNumberValid(strippedEntry) && strippedEntry.Length >= cardNetwork.GetCardNumberLength();

			if (!networkAccepted)
			{
				errorMessage = string.Format("We do not accept {0}, please use other cards", cardNetwork.GetCardNetworkType().GetAttribute<DisplayName>().Name);
			}
			else if (!cardNumberIsValid && strippedEntry.Length >= cardNetwork.GetCardNumberLength())
			{
				errorMessage = "Check card number";
			}

			return new ValidationResponse(networkAccepted && cardNumberIsValid, errorMessage , !string.IsNullOrWhiteSpace(errorMessage));
		}
예제 #10
0
		public void Validate(object sender)
		{
			_validParts.Clear();

			if (!_isTokenPayment)
			{
				var network = _cardNetworkDiscoverer.DiscoverCardNetwork(cardNumberEntry.Text ?? string.Empty);

				if (network.GetCardNetworkType() != _currentDiscoveredNetwork.GetCardNetworkType())
				{
					_currentDiscoveredNetwork = network;
					UpdateCardIcons();
					UpdateCvvMaxLength();
					UpdateCardNumberFormat();
					UpdateCardNumberMaxLength();

					_currentDiscoveredNetwork.SetAvsEnabled(Judo.AvsEnabled);
					startDateEntry.IsVisible = _currentDiscoveredNetwork.ShouldDisplayStartDate();
					issueNumberEntry.IsVisible = _currentDiscoveredNetwork.ShouldDisplayIssueNumber();
				}

				ValidatePart(cardNumberEntry, new CardNumberValidator(), CardPart.CardNumber);
				ValidatePart(expiryDateEntry, new ExpiryDateValidator(DateTime.Now), CardPart.ExpiryDate);
				ValidatePart(startDateEntry, new StartDateValidator(DateTime.Now), CardPart.StartDate);
				ValidatePart(issueNumberEntry, new IssueNumberValidator(), CardPart.IssueNumber);
			}

			ValidatePart(cvvEntry, new SecurityCodeValidator(), CardPart.SecurityCode);
			ValidatePart(postcodeEntry, new PostcodeValidator(_currentDiscoveredCountry), CardPart.Postcode);

			DisplayAvsFieldIfAvsEnabledAndPrimaryPartsAreMet();
			DisplayPaymentButtonIfValidPartsMet();

			var entry = (JudoEntry)sender;

			Advance(entry, string.IsNullOrWhiteSpace(entry.Error));
		}
예제 #11
0
		void SetUpDefaults(TokenPaymentDefaultsViewModel defaults)
		{
			cardNumberEntry.Format = "";
			cardNumberEntry.Text = defaults.MaskedCardNumber;
			cardImage.Opacity = !string.IsNullOrWhiteSpace(defaults.MaskedCardNumber) ? 1 : 0.5;
			expiryDateEntry.Text = defaults.ExpiryDate;
			expiryDateEntry.Format = "";
			cardNumberEntry.IsEnabled = false;
			expiryDateEntry.IsEnabled = false;
			startDateEntry.IsEnabled = false;
			issueNumberEntry.IsEnabled = false;
			_currentDiscoveredNetwork = defaults.CardNetork;
			UpdateCardIcons();
			UpdateCvvMaxLength();
			_currentDiscoveredNetwork.SetAvsEnabled(Judo.AvsEnabled);
		}
예제 #12
0
		public ValidationResponse Validate(string entry, ICardNetwork cardNetwork, List<CardNetwork> acceptableCardNetworksForTransaction)
		{
			return ValidateDate(entry, _dateToMessaureFrom, (entryDate, dateToMeasureFrom) => { return entryDate >= dateToMeasureFrom && entryDate <= dateToMeasureFrom.AddYears(10); }, "Check expiry date");
		}