Reputation: 291
I am trying to make a monthly billing plan using node JS with stripe.
I get this error:
error when charged { Error: No such plan:
Here is my code:
const keyPublishable = "pk_test_DbEg2qVxduEZaIOl03AJAKX800fGtReb3c";
const keySecret = "XXX";
app.post("/charge", async (req, res) => {
try {
var customer = await stripe.customers.create({
email: req.body.stripeEmail,
source: req.body.stripeToken
})
await stripe.subscriptions.create({ // no point in awaiting here
plan: 'prod_EjuGPEbcrhczeA',
customer: customer.id
})
res.render("charge.pug")
In the logs of stripe I get :
{
"error": {
"code": "resource_missing",
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
"message": "No such plan: prod_EjuGPEbcrhczeA",
"param": "plan",
"type": "invalid_request_error"
}
}
I do not know what I am doing wrong.
Thank you
Upvotes: 0
Views: 2845
Reputation: 461
I suppose the id you are using is wrong. It's product id not plan id. What you need is to create a plan using the API: https://stripe.com/docs/api/plans/create.
Then use id of newly created plan to create subscription.
Upvotes: 2