1
votes

I'm currently building a platform using MERN, and have stripe API connected in the backend.

Currently, I can retrieve all products & plans, and can create a plan. But every time I create a plan, it creates a new product for said plan. And I want the plan to be added to an existing product.

Following Stripe's API docs, this is what I currently have:

    stripe.plans.create({
      amount: amount,
      interval: "month",
      product: {
        name: fields.productName,
        id: fields.productID
      },
      currency: "eur",
    }, function(err, plan) {
    }

The product object contains the name and id from an existing product, but I get the following error:

message: "Product already exists."

Since I can do this via the Stripe dashboard, I presume it's definitely possible using API, but I can't seem to figure out what I'm missing.

Any suggestions would be greatly appreciated

1

1 Answers

2
votes

Turns out it was actually a very obvious answer!

product: fields.productID,

Instead of

  product: {
    name: fields.productName,
    id: fields.productID
  },