public ActionResult CheckCoupon(string couponCode) { var cart = GetSessionCart(); var now = DateTime.Now; try { if (!string.IsNullOrEmpty(couponCode)) { var coupon = _couponService.FindById(couponCode); if (coupon == null || now < coupon.Start_Date || now > coupon.End_Date) { return(Json(new CouponResultViewModel() { Result = false, Message = string.Format(Resource.DataIsNotFound, Resource.HeaderCoupon), Discount = 0, Total = Convert.ToDecimal(cart.Total) })); } return(Json(new CouponResultViewModel() { Result = true, Message = string.Format(Resource.DataIsNotFound, Resource.HeaderCoupon), Discount = coupon.Discount, Total = Convert.ToDecimal(cart.Total) - coupon.Discount })); } return(Json(new CouponResultViewModel() { Result = false, Message = string.Format(Resource.InvalidData, Resource.HeaderCoupon), Discount = 0, Total = Convert.ToDecimal(cart.Total) })); } catch (Exception ex) { return(Json(new CouponResultViewModel() { Result = true, Message = Resource.InternalException, Discount = 0, Total = Convert.ToDecimal(cart.Total) })); } }
public ActionResult Edit(string id) { if (string.IsNullOrWhiteSpace(id)) { TempData[Constants.NotifyMessage] = new NotifyModel { Result = false, Message = string.Format("{0} is not found", "Coupon") }; return(RedirectToAction("Index")); } var entity = _couponService.FindById(id); var model = new CouponViewModel() { Id = entity.Id, Status = entity.Status, Discount = entity.Discount, EndDate = entity.End_Date, StartDate = entity.Start_Date }; return(View(model)); }
public ActionResult CheckOut(string Coupon) { var apiContext = GetAPIContext(); var payerId = Request.Params["PayerID"]; var cart = GetSessionCart(); var now = DateTime.Now; Coupon coupon = null; if (!string.IsNullOrWhiteSpace(Coupon)) { coupon = _couponService.FindById(Coupon); if (coupon != null && !coupon.Status && (now < coupon.Start_Date || now > coupon.End_Date)) { coupon = null; } } if (cart == null) { TempData[Constants.NotifyMessage] = new NotifyModel() { Message = Resource.EmptyCart, Result = false }; return(RedirectToAction("Index", "Home")); } try { var guid = Guid.NewGuid().ToString(); if (string.IsNullOrEmpty(payerId)) { string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/Orders/Confirm?"; //guid we are generating for storing the paymentID received in session //after calling the create function and it is used in the payment execution //var guid = Convert.ToString((new Random()).Next(100000)); //CreatePayment function gives us the payment approval url //on which payer is redirected for paypal account payment cart.Token = guid; var createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + guid, cart, coupon); //get links returned from paypal in response to Create function call var links = createdPayment.links.GetEnumerator(); string paypalRedirectUrl = null; while (links.MoveNext()) { Links lnk = links.Current; if (lnk.rel.ToLower().Trim().Equals("approval_url")) { //saving the payapalredirect URL to which user will be redirected for payment Session.Add(guid, createdPayment.id); return(Redirect(lnk.href)); } } // saving the paymentID in the key guid } } catch (Exception ex) { } return(null); }