public ActionResult AddCoupon(string id) { if (string.IsNullOrEmpty(id)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var customerService = new StripeCustomerService(); var stripeCustomer = customerService.Get(id); var user = UserManager.Users.First(u => u.Email == stripeCustomer.Email); if (stripeCustomer == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var couponService = new StripeCouponService(); var coupons = couponService.List().Select(c => new SelectListItem { Value = c.Id, Text = c.Id }); var model = new CustomerAddCouponViewModel { CustomerDescription = string.Format("{0} {1} ({2})", user.FirstName, user.LastName, user.Email), CustomerId = id, SelectedCoupon = "", Coupons = coupons }; return(View(model)); }
public ActionResult AddCoupon(CustomerAddCouponViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var options = new StripeCustomerUpdateOptions(); options.Coupon = model.SelectedCoupon; var customerService = new StripeCustomerService(); customerService.Update(model.CustomerId, options); return(RedirectToAction("Details", new { id = model.CustomerId })); }