public override IList<string> ValidatePaymentForm(FormCollection form) { var warnings = new List<string>(); //validate var validator = new PaymentInfoValidator(_services.Localization); var model = new PayPalDirectPaymentInfoModel() { CardholderName = form["CardholderName"], CardNumber = form["CardNumber"], CardCode = form["CardCode"], ExpireMonth = form["ExpireMonth"], ExpireYear = form["ExpireYear"] }; var validationResult = validator.Validate(model); if (!validationResult.IsValid) foreach (var error in validationResult.Errors) warnings.Add(error.ErrorMessage); return warnings; }
public ActionResult PaymentInfo() { var model = new PayPalDirectPaymentInfoModel(); //CC types model.CreditCardTypes.Add(new SelectListItem() { Text = "Visa", Value = "Visa", }); model.CreditCardTypes.Add(new SelectListItem() { Text = "Master card", Value = "MasterCard", }); model.CreditCardTypes.Add(new SelectListItem() { Text = "Discover", Value = "Discover", }); model.CreditCardTypes.Add(new SelectListItem() { Text = "Amex", Value = "Amex", }); //years for (int i = 0; i < 15; i++) { string year = Convert.ToString(DateTime.Now.Year + i); model.ExpireYears.Add(new SelectListItem() { Text = year, Value = year, }); } //months for (int i = 1; i <= 12; i++) { string text = (i < 10) ? "0" + i.ToString() : i.ToString(); model.ExpireMonths.Add(new SelectListItem() { Text = text, Value = i.ToString(), }); } //set postback values var form = this.GetPaymentData(); model.CardholderName = form["CardholderName"]; model.CardNumber = form["CardNumber"]; model.CardCode = form["CardCode"]; var selectedCcType = model.CreditCardTypes.Where(x => x.Value.Equals(form["CreditCardType"], StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (selectedCcType != null) selectedCcType.Selected = true; var selectedMonth = model.ExpireMonths.Where(x => x.Value.Equals(form["ExpireMonth"], StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (selectedMonth != null) selectedMonth.Selected = true; var selectedYear = model.ExpireYears.Where(x => x.Value.Equals(form["ExpireYear"], StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (selectedYear != null) selectedYear.Selected = true; return PartialView(model); }