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");
}
Please use the price API Id instead of using prod_ID above.
As the picture shows, it worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With