public ActionResult OrderSummary(CheckoutModel model, CreditCardModel cardModel) { ModelState.Clear(); this.ViewBag.DisplayTax = DomainService.GetSettingsValueAsBool(SettingsKey.useTax, this.DomainID); bool isDirect = DomainService.GetSettingsValue(SettingsKey.sagePayMethod, this.DomainID).ToLowerInvariant() .Equals(SagePayPaymentType.Direct.ToString().ToLowerInvariant()); this.ViewBag.PaymentTypes = ECommerceService.GetAllPaymentDomainAsSelectList(this.DomainID, true); this.ViewBag.SagePay = PaymentType.SagePay.ToString().ToLowerInvariant(); this.ViewBag.IsDirect = isDirect; if (isDirect) this.ViewBag.CardTypes = Enum.GetValues(typeof(CardType)).Cast<CardType>() .Select(c => new SelectListItem { Text = c.ToString(), Value = ((int)c).ToString() }).ToList(); tbl_Basket basket = FindBasket(); if (basket == null) { ModelState.AddModelError("", "There is no basket assigned to you."); return View(); } model.CopyValuesFromBasket(basket); if (!model.TermsAndConditionsConfirmed) { ModelState.AddModelError("TermsAndConditionsConfirmed", "Please agree to our terms and conditions."); 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); } if (!ECommerceService.IsEnoughOnStock(basket.tbl_BasketContent)) { ModelState.AddModelError("", "Quantity of order oversize current stock ammount"); return View(model); } if (TryValidateModel(model)) { //int customerID = Request.IsAuthenticated && !AdminUser.IsAdmn ? AdminUser.UserID : 0; tbl_Orders order = ECommerceService.SaveOrder(0, model.PaymentDomainID, (int?)null, basket.BasketID); if (order == null) { ModelState.AddModelError("", "There was a problem saving new order."); return View(model); } if (!String.IsNullOrEmpty(model.DonationAmount)) { decimal donationAmount = 0; bool parsed = Decimal.TryParse(model.DonationAmount.ChangeDecimalSeparator(), out donationAmount); if (parsed && donationAmount > 0) { if (model.BillingAddressTheSame && model.IsDeliverable) ECommerceService.SaveOrderForDonation(0, this.DomainID, model.DeliveryAddress1, model.DeliveryAddress2, model.DeliveryAddress3, model.DeliveryCity, model.DeliveryCountryID, model.DeliveryFirstName, model.DeliveryPhone, model.DeliveryPostcode, model.DeliveryState, model.DeliverySurname, model.Email, order.CustomerID, donationAmount, model.GiftAid, selectedPaymentType.PaymentDomainID, DonationType.Single, order.OrderID); else ECommerceService.SaveOrderForDonation(0, this.DomainID, model.BillingAddress1, model.BillingAddress2, model.BillingAddress3, model.BillingCity, model.BillingCountryID.Value, model.BillingFirstName, model.BillingPhone, model.BillingPostcode, model.BillingState, model.BillingSurname, model.Email, order.CustomerID, donationAmount, model.GiftAid, selectedPaymentType.PaymentDomainID, DonationType.Single, order.OrderID); } } 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 }); case PaymentType.Stripe: return RedirectToRoute("Stripe", new { action = "Payment", orderID = order.OrderID }); default: return View(model); } } ModelState.AddModelError("", "Some of the values are incorrect."); return View(model); }
public ActionResult SaveNewOrder(string instructions, bool isPayment = false, int paymentDomainID = 0, CreditCardModel creditCardInfo = null, bool isCustomPrice = false, string customPrice = "", int? addressID = null, CashPayment cashPayment = CashPayment.Cash) { if (SessionManager.AdminBasket == null) return Json(new { success = false, error = "System cannot find your basket." }); if (!ECommerceService.IsEnoughOnStock(SessionManager.AdminBasket.tbl_BasketContent)) return Json(new { success = false, error = "Quantity of order items exceeds current stock ammount." }); SessionManager.AdminBasket = ECommerceService.UpdateBasketDeliveryNotes(instructions, SessionManager.AdminBasket.BasketID); tbl_Orders order = ECommerceService.SaveOrder(0, null, isPayment ? (int?)null : (int)cashPayment, SessionManager.AdminBasket.BasketID, AdminUser.UserID, addressID.GetValueOrDefault(0)); if (order == null) return Json(new { success = false, error = "There was a problem saving new order." }); if (isCustomPrice) { decimal price = 0; bool parsed = Decimal.TryParse(customPrice.ChangeDecimalSeparator(), out price); if (parsed) ECommerceService.SaveCustomTotalAmount(price, order.OrderID); } if (isPayment) { var selectedPaymentType = ECommerceService.GetPaymentDomainByID(paymentDomainID); if (selectedPaymentType == null) { return Json(new { success = false, error = "Please select payment type." }); } var isDirect = DomainService.GetSettingsValue(SettingsKey.sagePayMethod, SessionManager.AdminBasket.B_DomainID) == SagePayPaymentType.Direct.ToString(); PaymentType key = (PaymentType)Enum.Parse(typeof(PaymentType), selectedPaymentType.tbl_PaymentType.PT_Code); switch (key) { case PaymentType.SagePay: if (isDirect) { if (creditCardInfo == null) return Json(new { success = false, error = "Please fill in credit card information." }); SessionManager.CreditCard = creditCardInfo; } return Json(new { success = true, url = Url.RouteUrl("SagePay", new { action = "Payment", orderID = order.OrderID }) }); case PaymentType.PayPal: return Json(new { success = true, url = Url.RouteUrl("PayPal", new { action = "Payment", orderID = order.OrderID }) }); case PaymentType.SecureTrading: return Json(new { success = true, url = Url.RouteUrl("SecureTrading", new { action = "Payment", orderID = order.OrderID }) }); } } else { order = ECommerceService.UpdateOrderPaymentStatus(order.OrderID, PaymentStatus.Paid); var domain = DomainService.GetDomainByID(SessionManager.AdminBasket.B_DomainID); MailingService.SendOrderConfirmationAdmin(order, domain != null ? domain.DO_Email : String.Empty); MailingService.SendOrderConfirmation(order); } if (order == null) return Json(new { success = false, error = "There was a problem updating payment status for order." }); return Json(new { success = true }); }
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); }