public override bool Equals(object obj) { if (obj == null) { return(false); } if (obj == this) { return(true); } return(obj is Card other && ((Id == null && other.Id == null) || (Id?.Equals(other.Id) == true)) && ((CardBrand == null && other.CardBrand == null) || (CardBrand?.Equals(other.CardBrand) == true)) && ((Last4 == null && other.Last4 == null) || (Last4?.Equals(other.Last4) == true)) && ((ExpMonth == null && other.ExpMonth == null) || (ExpMonth?.Equals(other.ExpMonth) == true)) && ((ExpYear == null && other.ExpYear == null) || (ExpYear?.Equals(other.ExpYear) == true)) && ((CardholderName == null && other.CardholderName == null) || (CardholderName?.Equals(other.CardholderName) == true)) && ((BillingAddress == null && other.BillingAddress == null) || (BillingAddress?.Equals(other.BillingAddress) == true)) && ((Fingerprint == null && other.Fingerprint == null) || (Fingerprint?.Equals(other.Fingerprint) == true)) && ((CardType == null && other.CardType == null) || (CardType?.Equals(other.CardType) == true)) && ((PrepaidType == null && other.PrepaidType == null) || (PrepaidType?.Equals(other.PrepaidType) == true)) && ((Bin == null && other.Bin == null) || (Bin?.Equals(other.Bin) == true))); }
public override int GetHashCode() { unchecked { int hash = 17; hash = hash * 23 + (CardNumber == null ? 0 : CardNumber.GetHashCode()); hash = hash * 23 + (CardType == null ? 0 : CardType.GetHashCode()); hash = hash * 23 + (ExpMonth == default(byte) ? 0 : ExpMonth.GetHashCode()); hash = hash * 23 + (ExpYear == default(short) ? 0 : ExpYear.GetHashCode()); hash = hash * 23 + (ModifiedDate == default(DateTime) ? 0 : ModifiedDate.GetHashCode()); return(hash); } }
protected void ToString(List <string> toStringOutput) { toStringOutput.Add($"Id = {(Id == null ? "null" : Id == string.Empty ? "" : Id)}"); toStringOutput.Add($"CardBrand = {(CardBrand == null ? "null" : CardBrand.ToString())}"); toStringOutput.Add($"Last4 = {(Last4 == null ? "null" : Last4 == string.Empty ? "" : Last4)}"); toStringOutput.Add($"ExpMonth = {(ExpMonth == null ? "null" : ExpMonth.ToString())}"); toStringOutput.Add($"ExpYear = {(ExpYear == null ? "null" : ExpYear.ToString())}"); toStringOutput.Add($"CardholderName = {(CardholderName == null ? "null" : CardholderName == string.Empty ? "" : CardholderName)}"); toStringOutput.Add($"BillingAddress = {(BillingAddress == null ? "null" : BillingAddress.ToString())}"); toStringOutput.Add($"Fingerprint = {(Fingerprint == null ? "null" : Fingerprint == string.Empty ? "" : Fingerprint)}"); toStringOutput.Add($"CardType = {(CardType == null ? "null" : CardType.ToString())}"); toStringOutput.Add($"PrepaidType = {(PrepaidType == null ? "null" : PrepaidType.ToString())}"); toStringOutput.Add($"Bin = {(Bin == null ? "null" : Bin == string.Empty ? "" : Bin)}"); }
private string Validate(string propName) { if (propName == nameof(CardType)) { if (string.IsNullOrEmpty(CardNumber)) { return(propName + emptyCell); } } if (propName == nameof(CardNumber)) { if (string.IsNullOrEmpty(CardNumber)) { return(propName + emptyCell); } if (CardNumber.Length != properLenght) { return(propName + chainLenght + properLenght); } } if (propName == nameof(ExpMonth)) { if (string.IsNullOrEmpty(ExpMonth.ToString())) { return(propName + emptyCell); } if (ExpMonth > 12 || ExpMonth < 1) { return(propName + monthNotValid); } } if (propName == nameof(ExpYear)) { if (string.IsNullOrEmpty(ExpYear.ToString())) { return(propName + emptyCell); } if (ExpYear > 3000 || ExpYear < 1990) { return(propName + monthNotValid); } } return(null); }
// this function validates the data we get from the client. // it also cleans it up a bit. // it returns an error string if anything that's required isn't present, // and no error if everything is present and seeming valid. // the error returned should contain all errors that were detected. public List <string> Validate() { List <string> e = new List <string>(); if (this.Amount == 0) { Validated = false; return(e); } try { // We'll start by cleaning up the data that they can key in, // removing extraneous whitespace. FirstName = FirstName.Trim(); LastName = LastName.Trim(); ExpMonth = ExpMonth.Trim(); ExpYear = ExpYear.Trim(); CVVNumber = CVVNumber.Trim(); ZipCode = ZipCode.Trim(); CardType = CardType.Trim(); // Here we make sure everything that's required actually has a value. if (FirstName.Length == 0 || LastName.Length == 0 || CardNumber.Length == 0 || CardType.Length == 0 || ExpMonth.Length == 0 || ExpYear.Length == 0 || CVVNumber.Length == 0 || ZipCode.Length == 0) { e.Add("Missing a required value.\n"); } // FirstName, LastName, Cardnumber, CVV, and Zipcode // are validated just by having a value. if (!CardTypes.Contains(CardType)) { e.Add("Card type is invalid.\n"); } // Expiration Month Validation if (int.TryParse(ExpMonth, out int IExpMonth)) { if (IExpMonth > 12 || IExpMonth < 1) { e.Add("Expiration Month is invalid.\n"); } } else { e.Add("Expiration Month is not a number.\n"); } // Expiration Year validation if (int.TryParse(ExpYear, out int IExpYear)) { if (IExpYear < DateTime.Now.Year || IExpYear > DateTime.Now.AddYears(10).Year) { e.Add("Expiration Year is invalid.\n"); } } else { e.Add("Expiration Year is not a number.\n"); } } catch (Exception ex) { Constants.Log(ex); e.Add("Error in credit card validation, unable to continue."); } // if e has a length, it's an error. return(e); }
public override int GetHashCode() { int hashCode = 1370361237; if (Id != null) { hashCode += Id.GetHashCode(); } if (CardBrand != null) { hashCode += CardBrand.GetHashCode(); } if (Last4 != null) { hashCode += Last4.GetHashCode(); } if (ExpMonth != null) { hashCode += ExpMonth.GetHashCode(); } if (ExpYear != null) { hashCode += ExpYear.GetHashCode(); } if (CardholderName != null) { hashCode += CardholderName.GetHashCode(); } if (BillingAddress != null) { hashCode += BillingAddress.GetHashCode(); } if (Fingerprint != null) { hashCode += Fingerprint.GetHashCode(); } if (CardType != null) { hashCode += CardType.GetHashCode(); } if (PrepaidType != null) { hashCode += PrepaidType.GetHashCode(); } if (Bin != null) { hashCode += Bin.GetHashCode(); } return(hashCode); }
private void Tb_date_OnTap(object sender, GestureEventArgs e) { var dateselector = new CardDateSelectorControl { Height = ActualHeight, Width = ActualWidth }; dateselector.Closed += (o, args) => { var eventArgs = (PayNowEventArgs)args; var date = (List <int>)eventArgs.Response; if (date == null) { return; } ExpMonth = date[0]; ExpYear = date[1] - 2000; tb_date.Text = ExpMonth.ToString(CultureInfo.InvariantCulture).PadLeft(2, '0') + " / " + ExpYear.ToString(CultureInfo.InvariantCulture); }; dateSelectorPopup = new Popup { Child = dateselector, VerticalOffset = SystemTray.IsVisible ? Application.Current.Host.Content.ActualHeight - ActualHeight : 0, IsOpen = true }; //popup.IsOpen = true; }