我正在尝试检索有关存在的Stripe订阅的一些信息。我知道它存在,因为我检查了仪表板,并将数据条订阅ID与数据库中的订阅ID相匹配(复制粘贴以确认)
我的问题是Stripe告诉我这不是有效的订阅。但是,如果我删除该变量并将其替换为我正在测试的订阅ID字符串,则可以正常工作。我已经通过console.log(typeof subscriptionID)
进行了检查,实际上,我使用的变量是一个字符串。所以对我来说为什么它不起作用没有任何意义。
let subscriptionID = JSON.stringify(req.body.user.company.stripe.subscriptionId)
stripe.subscriptions.retrieve(
subscriptionID)
.then(subscription => {
if(subscription.id != null) {
logger.info(`Retrieved plan successfully`);
return res.json({success: true, subscription});
}
})
.catch(err => {
logger.info(`Error retrieving plan`);
logger.error(`retrievePlan: Error message: ${err}`);
console.log(err)
return res.status(500).json({success: false, message: 'Error retrieving your subscription details.'});
});
这是Stripe文档的链接
https://stripe.com/docs/api/subscriptions/retrieve
编辑**
Stripe的堆栈跟踪/错误消息
stack:
'Error: No such subscription: "<sub ID>"\n at Constructor._Error (/home/josh/Documents/Projects/Blah/billing/node_modules/stripe/lib/Error.js:12:16)\n at Constructor (/home/josh/Documents/Projects/Blah/billing/node_modules/stripe/lib/utils.js:164:17)\n at new Constructor (/home/josh/Documents/Projects/Blah/billing/node_modules/stripe/lib/utils.js:164:17)\n at Function.StripeError.generate (/home/josh/Documents/Projects/Blah/billing/node_modules/stripe/lib/Error.js:57:14)\n at IncomingMessage.res.on (/home/josh/Documents/Projects/Blah/billing/node_modules/stripe/lib/StripeResource.js:165:39)\n at IncomingMessage.emit (events.js:203:15)\n at endReadableNT (_stream_readable.js:1129:12)\n at process._tickCallback (internal/process/next_tick.js:63:19)',
答案 0 :(得分:0)
设法解决了我的问题。它报告它不是字符串,即使它是字符串。我删除了JSON.stringify部分,使其仅是文字变量,但最终使其正常工作。
let subscriptionID = req.body.user.company.stripe.subscriptionId