lucky simon
lucky simon

Reputation: 291

error when charged { Error: No such plan: on stripe with Node JS

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

Answers (1)

Eugene Shilin
Eugene Shilin

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

Related Questions