条纹 "Missing required param: line_items[0][currency]." 节点 js
Stripe "Missing required param: line_items[0][currency]." Node js
我正在节点 js 后端创建订阅。它一直运行良好,但今天我收到了这个错误。我没有对代码进行任何更改 - 它只是开始返回此错误。
后端代码:
app.post('/api/subscription', async (req, res) => {
const { priceId } = req.body;
try {
const session = await stripe.checkout.sessions.create({
mode: "subscription",
payment_method_types: ["card"],
line_items: [
{
price: priceId,
// For metered billing, do not pass quantity
quantity: 1,
},
],
// {CHECKOUT_SESSION_ID} is a string literal; do not change it!
// the actual Session ID is returned in the query parameter when your customer
// is redirected to the success page.
success_url: 'https://someurl',
cancel_url: 'https://someurl',
});
res.send({
sessionId: session.id,
});
} catch (e) {
console.log(e)
res.status(400);
return res.send({
error: {
message: e.message,
}
});
}
})
来自我发送的客户
fetch("http://localhost:8000/api/subscription", {
method: "POST",
body: JSON.stringify({ priceId }),
});
我从这里的官方条纹示例中获取了这段代码 https://stripe.com/docs/billing/subscriptions/checkout
正如我所说,它工作正常,现在我已经在两个不同的条带帐户上对其进行了测试,并得到了同样的错误。看起来 stripe 上有些东西发生了变化,但在他们的文档中没有
如果 priceId
是 undefined
/null
,则不会在请求中发送。如果价格不存在,API 假设您尝试在不使用价格的情况下指定订单项的信息,并且它执行的第一个检查是针对有效的 currency
(您没有),这会导致 Missing required param: line_items[0][currency].
错误。
要解决此问题,您需要找出 priceId
未按预期填充的原因,您可能还需要添加检查以确保 priceId
在之前有效继续执行结帐会话创建步骤。
我正在节点 js 后端创建订阅。它一直运行良好,但今天我收到了这个错误。我没有对代码进行任何更改 - 它只是开始返回此错误。 后端代码:
app.post('/api/subscription', async (req, res) => {
const { priceId } = req.body;
try {
const session = await stripe.checkout.sessions.create({
mode: "subscription",
payment_method_types: ["card"],
line_items: [
{
price: priceId,
// For metered billing, do not pass quantity
quantity: 1,
},
],
// {CHECKOUT_SESSION_ID} is a string literal; do not change it!
// the actual Session ID is returned in the query parameter when your customer
// is redirected to the success page.
success_url: 'https://someurl',
cancel_url: 'https://someurl',
});
res.send({
sessionId: session.id,
});
} catch (e) {
console.log(e)
res.status(400);
return res.send({
error: {
message: e.message,
}
});
}
})
来自我发送的客户
fetch("http://localhost:8000/api/subscription", {
method: "POST",
body: JSON.stringify({ priceId }),
});
我从这里的官方条纹示例中获取了这段代码 https://stripe.com/docs/billing/subscriptions/checkout 正如我所说,它工作正常,现在我已经在两个不同的条带帐户上对其进行了测试,并得到了同样的错误。看起来 stripe 上有些东西发生了变化,但在他们的文档中没有
如果 priceId
是 undefined
/null
,则不会在请求中发送。如果价格不存在,API 假设您尝试在不使用价格的情况下指定订单项的信息,并且它执行的第一个检查是针对有效的 currency
(您没有),这会导致 Missing required param: line_items[0][currency].
错误。
要解决此问题,您需要找出 priceId
未按预期填充的原因,您可能还需要添加检查以确保 priceId
在之前有效继续执行结帐会话创建步骤。