public ActionResult PaymentInfo() { var model = new PaymentInfoModel(); //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.Request.Form; 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 View("~/Plugins/Payments.Stripe/Views/PaymentStripe/PaymentInfo.cshtml", model); }
public override IList<string> ValidatePaymentForm(FormCollection form) { var warnings = new List<string>(); //validate var validator = new PaymentInfoValidator(_localizationService); var model = new PaymentInfoModel() { CardholderName = form["CardholderName"], CardNumber = form["CardNumber"], CardCode = form["CardCode"], }; var validationResult = validator.Validate(model); if (!validationResult.IsValid) foreach (var error in validationResult.Errors) warnings.Add(error.ErrorMessage); return warnings; }