IEnumerable <KeyValuePair <CreditCardValidationField, string> > ValidateFields(CreditCardValidationConfiguration configuration, CreditCardValidationContext context) { var acceptedCardType = CreditCardTypeProvider .GetAcceptedCreditCardTypes() .Contains(context.CardType, StringComparer.OrdinalIgnoreCase); if (!acceptedCardType) { yield return(new KeyValuePair <CreditCardValidationField, string>(CreditCardValidationField.CardType, AppLogic.GetString("creditCardDetails.cardType.invalid"))); } var missingRequiredIssueNumber = CreditCardTypeProvider .GetCardTypesRequiringIssueNumber() .Contains(context.CardType, StringComparer.OrdinalIgnoreCase) && string.IsNullOrEmpty(context.IssueNumber); if (missingRequiredIssueNumber) { yield return(new KeyValuePair <CreditCardValidationField, string>(CreditCardValidationField.IssueNumber, AppLogic.GetString("creditCardDetails.cardIssueNumber.required"))); } if (configuration.ValidateCreditCardNumber) { var cardType = CardType.Parse(context.CardType); if (cardType != null) // Only validate known card types { var creditCardValidator = new CreditCardValidator(context.Number, cardType); if (!creditCardValidator.Validate()) { yield return(new KeyValuePair <CreditCardValidationField, string>(CreditCardValidationField.Number, AppLogic.GetString("creditCardDetails.cardNumber.format"))); } } } var missingExpirationDate = context.ExpirationDate == null; if (missingExpirationDate) { yield return(new KeyValuePair <CreditCardValidationField, string>(CreditCardValidationField.ExpirationDate, AppLogic.GetString("creditCardDetails.cardExpirationDate.required"))); } var missingRequiredCardExtraCode = !configuration.CardExtraCodeIsOptional && string.IsNullOrEmpty(context.Cvv); if (missingRequiredCardExtraCode) { yield return(new KeyValuePair <CreditCardValidationField, string>(CreditCardValidationField.Cvv, AppLogic.GetString("address.cs.29"))); } }
IEnumerable <KeyValuePair <CreditCardValidationField, string> > ValidateFields(CreditCardValidationConfiguration configuration, CreditCardValidationContext context) { var acceptedCardType = CreditCardTypeProvider .GetAcceptedCreditCardTypes() .Contains(context.CardType, StringComparer.OrdinalIgnoreCase); if (!acceptedCardType) { yield return(new KeyValuePair <CreditCardValidationField, string>(CreditCardValidationField.CardType, "Invalid card type")); } var missingRequiredIssueNumber = CreditCardTypeProvider .GetCardTypesRequiringIssueNumber() .Contains(context.CardType, StringComparer.OrdinalIgnoreCase) && string.IsNullOrEmpty(context.IssueNumber); if (missingRequiredIssueNumber) { yield return(new KeyValuePair <CreditCardValidationField, string>(CreditCardValidationField.IssueNumber, "Please enter a card issue number")); } if (configuration.ValidateCreditCardNumber) { var cardType = CardType.Parse(context.CardType); if (cardType != null) // Only validate known card types { var creditCardValidator = new CreditCardValidator(context.Number, cardType); if (!creditCardValidator.Validate()) { yield return(new KeyValuePair <CreditCardValidationField, string>(CreditCardValidationField.Number, "Please enter a valid credit card number")); } } } var missingExpirationDate = context.ExpirationDate == null; if (missingExpirationDate) { yield return(new KeyValuePair <CreditCardValidationField, string>(CreditCardValidationField.ExpirationDate, "Card expiration date is missing or invalid")); } var missingRequiredCardExtraCode = !configuration.CardExtraCodeIsOptional && string.IsNullOrEmpty(context.Cvv); if (missingRequiredCardExtraCode) { yield return(new KeyValuePair <CreditCardValidationField, string>(CreditCardValidationField.Cvv, "Please enter the credit card verification code with no spaces. This number can be found printed on the back side of your card")); } }
protected void dlAddress_UpdateCommand(object sender, DataListCommandEventArgs e) { CreditCardPanel ctrlCreditCard = e.Item.FindControl("ctrlCreditCard") as CreditCardPanel; Panel pnlCCData = e.Item.FindControl("pnlCCData") as Panel; Panel pnlECData = e.Item.FindControl("pnlECData") as Panel; AddressControl ctrlAddress = e.Item.FindControl("ctrlAddress") as AddressControl; if (ctrlAddress != null) { ctrlAddress.CountryIDToValidateZipCode = AppLogic.GetCountryID(ctrlAddress.Country); } Page.Validate("EditAddress"); if (AddressMode == AddressTypes.Billing && pnlCCData.Visible) { if (ctrlCreditCard.CreditCardType == AppLogic.GetString("address.cs.32", SkinID, ThisCustomer.LocaleSetting)) { pnlCCTypeErrorMsg.Visible = true; } else { pnlCCTypeErrorMsg.Visible = false; } if (ctrlCreditCard.CardExpMonth == AppLogic.GetString("address.cs.34", SkinID, ThisCustomer.LocaleSetting)) { pnlCCExpMonthErrorMsg.Visible = true; } else { pnlCCExpMonthErrorMsg.Visible = false; } if (ctrlCreditCard.CardExpYr == AppLogic.GetString("address.cs.35", 1, ThisCustomer.LocaleSetting)) { pnlCCExpYrErrorMsg.Visible = true; } else { pnlCCExpYrErrorMsg.Visible = false; } CardType Type = CardType.Parse(ctrlCreditCard.CreditCardType); CreditCardValidator validator = new CreditCardValidator(ctrlCreditCard.CreditCardNumber, Type); bool isValid = validator.Validate(); if (!isValid && AppLogic.AppConfigBool("ValidateCreditCardNumbers")) { ctrlCreditCard.CreditCardNumber = string.Empty; // clear the card extra code AppLogic.StoreCardExtraCodeInSession(ThisCustomer, string.Empty); pnlCCNumberErrorMsg.Visible = true; } else { pnlCCNumberErrorMsg.Visible = false; } } bool isValidCCDropdown = !(pnlCCTypeErrorMsg.Visible || pnlCCExpMonthErrorMsg.Visible || pnlCCExpYrErrorMsg.Visible || pnlCCNumberErrorMsg.Visible); if (dlAddress != null && Page.IsValid && isValidCCDropdown) { AspDotNetStorefrontCore.Address anyAddress = new AspDotNetStorefrontCore.Address(); Echeck ctrlECheck = e.Item.FindControl("ctrlECheck") as Echeck; if (ctrlAddress != null) { anyAddress.AddressID = int.Parse((e.Item.FindControl("hfAddressID") as HiddenField).Value); anyAddress.CustomerID = ThisCustomer.CustomerID; anyAddress.NickName = ctrlAddress.NickName; anyAddress.FirstName = ctrlAddress.FirstName; anyAddress.LastName = ctrlAddress.LastName; anyAddress.Phone = ctrlAddress.PhoneNumber; anyAddress.Company = ctrlAddress.Company; anyAddress.AddressType = AddressMode; anyAddress.ResidenceType = (ResidenceTypes)Enum.Parse(typeof(ResidenceTypes), ctrlAddress.ResidenceType, true); anyAddress.Address1 = ctrlAddress.Address1; anyAddress.Address2 = ctrlAddress.Address2; anyAddress.City = ctrlAddress.City; anyAddress.Suite = ctrlAddress.Suite; anyAddress.Zip = ctrlAddress.ZipCode; anyAddress.Country = ctrlAddress.Country; anyAddress.State = ctrlAddress.State; if (CustomerCCRequired && AddressMode == AddressTypes.Billing) { Address BillingAddress = new Address(); BillingAddress.LoadByCustomer(ThisCustomer.CustomerID, ThisCustomer.PrimaryBillingAddressID, AddressTypes.Billing); if (ctrlCreditCard != null) { anyAddress.CardName = ctrlCreditCard.CreditCardName; if (!ctrlCreditCard.CreditCardNumber.StartsWith("*")) { anyAddress.CardNumber = ctrlCreditCard.CreditCardNumber; } else { anyAddress.CardNumber = BillingAddress.CardNumber; } anyAddress.CardType = ctrlCreditCard.CreditCardType; anyAddress.CardExpirationMonth = ctrlCreditCard.CardExpMonth; anyAddress.CardExpirationYear = ctrlCreditCard.CardExpYr; if (AppLogic.AppConfigBool("ShowCardStartDateFields")) { string cardStartDate = ""; if (ctrlCreditCard.CardExpMonth != AppLogic.GetString("address.cs.34", SkinID, ThisCustomer.LocaleSetting)) { cardStartDate = ctrlCreditCard.CardStartMonth; } if (ctrlCreditCard.CardExpYr != AppLogic.GetString("address.cs.35", SkinID, ThisCustomer.LocaleSetting)) { cardStartDate += ctrlCreditCard.CardStartYear; } anyAddress.CardStartDate = cardStartDate; } if (AppLogic.AppConfigBool("CardExtraCodeIsOptional")) { anyAddress.CardIssueNumber = ctrlCreditCard.CreditCardIssueNumber; } } if (ShowEcheck && ctrlECheck != null) { anyAddress.ECheckBankAccountName = ctrlECheck.ECheckBankAccountName; anyAddress.ECheckBankName = ctrlECheck.ECheckBankName; if (!ctrlECheck.ECheckBankABACode.StartsWith("*")) { anyAddress.ECheckBankABACode = ctrlECheck.ECheckBankABACode; } else { anyAddress.ECheckBankABACode = BillingAddress.ECheckBankABACode; } if (!ctrlECheck.ECheckBankAccountNumber.StartsWith("*")) { anyAddress.ECheckBankAccountNumber = ctrlECheck.ECheckBankAccountNumber; } else { anyAddress.ECheckBankAccountNumber = BillingAddress.ECheckBankAccountNumber; } anyAddress.ECheckBankAccountType = ctrlECheck.ECheckBankAccountType; } if (pnlCCData.Visible) { anyAddress.PaymentMethodLastUsed = AppLogic.ro_PMCreditCard; } else if (pnlECData.Visible) { anyAddress.PaymentMethodLastUsed = AppLogic.ro_PMECheck; } else { anyAddress.PaymentMethodLastUsed = BillingAddress.PaymentMethodLastUsed; } } anyAddress.UpdateDB(); if (AppLogic.AppConfig("VerifyAddressesProvider") != "") { AspDotNetStorefrontCore.Address standardizedAddress = new AspDotNetStorefrontCore.Address(); string validateResult = AddressValidation.RunValidate(anyAddress, out standardizedAddress); anyAddress = standardizedAddress; anyAddress.UpdateDB(); if (validateResult != AppLogic.ro_OK) { } } dlAddress.EditItemIndex = -1; LoadData(); } } }