【发布时间】:2021-12-03 17:08:40
【问题描述】:
我有这段代码,直接从stripe 网站复制过来的:
app.post('/createSubscription',async (req, res) => {
let r = (Math.random() + 1).toString(36).substring(7);
console.log(r);
const subscription = await stripe.subscriptions.create({
customer: 'cus_' + r,
items: [
{price: 'price_1InXJuIPT89VeZtCMeR3xQWf'},
],
});
})
但是,当我运行此代码时,它在我的控制台中给了我一个错误。
to show where the warning was created)
(node:38025) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict`
我不确定这到底是什么意思,因为我以前从未见过条带的 thsi 错误?我在订阅功能中做错了什么?
【问题讨论】:
-
您不能像这样将 Stripe 客户 ID 生成为随机字符串,这没有任何意义。这不是随机的,您可以在一个 API 调用中创建一个 Customer 对象:stripe.com/docs/api/customers/create,然后使用返回的 ID。以stripe.com/docs/billing/subscriptions/… 为例。
标签: javascript node.js stripe-payments