Example #1
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));
		}
		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));
		}