StripeException:没有这样的计划 [英] StripeException: No Such Plan

查看:154
本文介绍了StripeException:没有这样的计划的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建客户对象并将其分配给Stripe中的计划,并收到错误消息不存在这样的计划".错误中给出的计划ID是正确的计划ID:No such plan: prod_EIcYiWkVa7LF7T

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

值得注意的是,客户的StripeCustomerId也未写入数据库,但这可能是因为稍后代码失败,所以没有进行任何更改.

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

推荐答案

以上以评论的形式发布于此,但我将其添加为对@karllekko的歉意,因为我几乎没有通过它就通过了它.

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.

您要使用计划ID plan_xxxxx,而不是产品ID prod_xxxxx.我犯了同样的错误,即创建多个产品而不是一个具有多个价格计划的产品.

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.

创建一个产品,然后针对您的金",银",铜"等价格为每个产品设置多个计划,并在代码中使用这些plan_xxxxx ID来创建订阅.

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.

这篇关于StripeException:没有这样的计划的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆