收费时发生错误{错误:没有这样的计划:在带有Node JS的条带上

时间:2019-03-21 13:04:54

标签: node.js stripe-payments

我正在尝试使用带有条纹的节点JS制定每月计费计划。

我收到此错误:

error when charged { Error: No such plan:

这是我的代码:

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")

在条带的日志中,我得到:

{
  "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"
  }
}

我不知道我在做什么错。

谢谢

1 个答案:

答案 0 :(得分:1)

我想您使用的ID是错误的。它是产品ID,而不是计划ID。您需要使用https://stripe.com/docs/api/plans/create API创建计划。

然后使用新创建的计划的ID来创建订阅。