Example #1
0
        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 override IList<string> ValidatePaymentForm(FormCollection form)
		{
			var warnings = new List<string>();
			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)
			{
				validationResult.Errors.Each(x => warnings.Add(x.ErrorMessage));
			}
			return warnings;
		}
        public ActionResult PaymentInfo()
        {
            var model = new PayPalDirectPaymentInfoModel();

            // Credit card 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 paymentData = _httpContext.GetCheckoutState().PaymentData;

            model.CardholderName = (string)paymentData.Get("CardholderName");
            model.CardNumber     = (string)paymentData.Get("CardNumber");
            model.CardCode       = (string)paymentData.Get("CardCode");

            var creditCardType = (string)paymentData.Get("CreditCardType");
            var selectedCcType = model.CreditCardTypes.Where(x => x.Value.Equals(creditCardType, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();

            if (selectedCcType != null)
            {
                selectedCcType.Selected = true;
            }

            var expireMonth   = (string)paymentData.Get("ExpireMonth");
            var selectedMonth = model.ExpireMonths.Where(x => x.Value.Equals(expireMonth, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();

            if (selectedMonth != null)
            {
                selectedMonth.Selected = true;
            }

            var expireYear   = (string)paymentData.Get("ExpireYear");
            var selectedYear = model.ExpireYears.Where(x => x.Value.Equals(expireYear, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();

            if (selectedYear != null)
            {
                selectedYear.Selected = true;
            }

            return(PartialView(model));
        }
		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);
		}