Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StripeException: No Such Plan

I'm creating a customer object and assigning them to a plan in Stripe and am getting the error "no such plan exists." The plan id that's given in the error is the correct plan id: No such plan: prod_EIcYiWkVa7LF7T

It may be worth noting that the customer's StripeCustomerId also isn't being written to the database, but that may be because the code is failing later on so no changes are made.

 [HttpPost]
        [Authorize]
        public ActionResult Subscribe(SubscribeViewModel model)
        {

            string CurrentUserId = User.Identity.GetUserId();
            var CurrentUser = UserManager.FindById(CurrentUserId);


            StripeConfiguration.SetApiKey(ConfigurationManager.AppSettings["StripeSecretKey"]);

            var custoptions = new CustomerCreateOptions
            {
                Description = "Customer object for " + CurrentUser.Email,
                SourceToken = model.StripeToken
            };

            var custservice = new CustomerService();
            Customer customer = custservice.Create(custoptions);

            CurrentUser.StripeCustomerId = customer.Id;

            var items = new List<SubscriptionItemOption>
            {
                new SubscriptionItemOption
                {
                    PlanId = db.Plans.Where(a=>a.Id == CurrentUser.Plan).FirstOrDefault().StripePlanId
                }
            };
            var options = new SubscriptionCreateOptions
            {
                CustomerId = CurrentUser.StripeCustomerId,
                Items = items
            };

            var service = new SubscriptionService();
            Subscription subscription = service.Create(options);


            CurrentUser.PlanStatus = "TRIAL";
            CurrentUser.ExpirationDate = DateTime.Now.AddDays(model.Plan.TrialDays);
            var Plan = db.Plans.Where(a => a.Id == CurrentUser.Plan).FirstOrDefault();
            return RedirectToAction("Index", "Home");
        }
like image 704
extensionhelp Avatar asked Jan 07 '19 17:01

extensionhelp


1 Answers

Please use the price API Id instead of using prod_ID above.

As the picture shows, it worked for me. enter image description here

like image 83
DamonWu Avatar answered Nov 15 '22 21:11

DamonWu