StripeException: No Such Plan

Viewed 9851

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");
        }
3 Answers

This was posted above as a comment, but I'm adding it as an answer with apologies to @karllekko, since I almost passed by it without reading it.

You want to use the Plan ID, plan_xxxxx, not the Product ID, prod_xxxxx. I made the same mistake of creating multiple products instead of one product with multiple price plans.

Create a single product, then set up multiple plans per product for your "Gold", "Silver", "Bronze" etc. pricing and use those plan_xxxxx IDs in your code to create subscriptions.

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

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

Enable Client Integration

I was stuck on this, tried the previous answers and nothing seemed to work, it happens that you must enable Client Integration, it's disabled for any new account by default. You can do it on the Checkout & Payment Links

Beware it has its warnings. It's better to integrate on backend.

enter image description here

Related