gpt4 book ai didi

c# - Stripe 异常 : No Such Plan

转载 作者:行者123 更新时间:2023-12-03 16:18:03 29 4
gpt4 key购买 nike

我正在创建一个客户对象并将它们分配给 Stripe 中的一个计划,但出现错误“不存在这样的计划”。错误中给出的计划 ID 是正确的计划 ID:No such plan: prod_EIcYiWkVa7LF7T
可能值得注意的是,客户的 StripeCustomerId 也没有写入数据库,但这可能是因为代码稍后失败,因此没有进行任何更改。

 [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 表示歉意的答案,因为我几乎没有阅读它就通过了它。

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

创建单个产品,然后为每个产品为您的“金”、“银”、“铜”等定价设置多个计划并使用这些 plan_xxxxx用于创建订阅的代码中的 ID。

关于c# - Stripe 异常 : No Such Plan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54079124/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com