public ActionResult DonationCheckout(DonationCheckoutModel model, CreditCardModel cardModel) { ModelState.Clear(); this.ViewBag.Donations = ECommerceService.GetAllDonationsInfoForDomainByType(this.DomainID, DonationType.Single); this.ViewBag.Countries = ECommerceService.GetAllCountriesAsSelectList(this.DomainID); bool isDirect = DomainService.GetSettingsValue(SettingsKey.sagePayMethod, this.DomainID).ToLowerInvariant().Equals(SagePayPaymentType.Direct.ToString().ToLowerInvariant()); if (model != null && model.Type == DonationType.Monthly) { //this.ViewBag.PaymentTypes = ECommerceService.GetAllPaymentDomainAsSelectList(this.DomainID, true)).ToList(); } else { this.ViewBag.PaymentTypes = ECommerceService.GetAllPaymentDomainAsSelectList(this.DomainID, true); this.ViewBag.IsDirect = isDirect; this.ViewBag.SagePay = ECommerceService.GetPaymentDomainIDByCode(this.DomainID, PaymentType.SagePay); if (isDirect) this.ViewBag.CardTypes = Enum.GetValues(typeof(CardType)).Cast<CardType>().Select(c => new SelectListItem { Text = c.ToString(), Value = ((int)c).ToString() }).ToList(); } if (model.Type != DonationType.Single) { ModelState.AddModelError("", "Some of the values are incorrect."); return View(model); } var selectedPaymentType = ECommerceService.GetPaymentDomainByID(model.PaymentDomainID); if (selectedPaymentType == null) { ModelState.AddModelError("PaymentDomainID", "Please select payment type."); return View(model); } if (selectedPaymentType.tbl_PaymentType.PT_Code == PaymentType.SagePay.ToString() && isDirect && (cardModel == null || !TryValidateModel(cardModel))) { ModelState.AddModelError("", "There was a problem saving card details."); return View(model); } decimal amount = 0; if (!Decimal.TryParse(model.Amount.ChangeDecimalSeparator(), out amount) && amount > 0) { ModelState.AddModelError("Amount", "Please specify correct amount"); return View(model); } if (TryValidateModel(model)) { int customerID = Request.IsAuthenticated && !AdminUser.IsAdmn ? AdminUser.UserID : 0; tbl_Orders order = ECommerceService.SaveOrderForDonation(0, this.DomainID, model.Address1, model.Address2, model.Address3, model.City, model.CountryID, model.FirstName, model.Phone, model.Postcode, model.State, model.Surname, model.EmailAddress, customerID, amount, model.GiftAid, selectedPaymentType.PaymentDomainID, DonationType.Single, null); PaymentType key = (PaymentType)Enum.Parse(typeof(PaymentType), selectedPaymentType.tbl_PaymentType.PT_Code); switch (key) { case PaymentType.SagePay: if (isDirect) SessionManager.CreditCard = cardModel; return RedirectToRoute("SagePay", new { action = "Payment", orderID = order.OrderID }); case PaymentType.PayPal: return RedirectToRoute("PayPal", new { action = "Payment", orderID = order.OrderID }); case PaymentType.SecureTrading: return RedirectToRoute("SecureTrading", new { action = "Payment", orderID = order.OrderID }); default: return View(model); } } ModelState.AddModelError("", "Some of the values are incorrect."); return View(model); }
public ActionResult DonationCheckout(DonationType type, decimal amount) { if (type != DonationType.Single) return new HttpNotFoundResult("Only single donation allowed."); var model = new DonationCheckoutModel { Amount = amount.ToString("F2"), Type = type }; this.ViewBag.Donations = ECommerceService.GetAllDonationsInfoForDomainByType(this.DomainID, DonationType.Single); this.ViewBag.Countries = ECommerceService.GetAllCountriesAsSelectList(this.DomainID); if (type == DonationType.Monthly) { //this.ViewBag.PaymentTypes = ECommerceService.GetAllPaymentDomainAsSelectList(this.DomainID, true)).ToList(); } else { bool isDirect = DomainService.GetSettingsValue(SettingsKey.sagePayMethod, this.DomainID).ToLowerInvariant().Equals(SagePayPaymentType.Direct.ToString().ToLowerInvariant()); this.ViewBag.PaymentTypes = ECommerceService.GetAllPaymentDomainAsSelectList(this.DomainID, true); this.ViewBag.IsDirect = isDirect; this.ViewBag.SagePay = ECommerceService.GetPaymentDomainIDByCode(this.DomainID, PaymentType.SagePay); if (isDirect) this.ViewBag.CardTypes = Enum.GetValues(typeof(CardType)).Cast<CardType>().Select(c => new SelectListItem { Text = c.ToString(), Value = ((int)c).ToString() }).ToList(); } return View(model); }