【发布时间】:2019-09-05 18:02:59
【问题描述】:
我正在尝试检索有关现有 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)',
【问题讨论】:
-
您需要提供一些上下文。如果字符串在您发出请求时包含有效的 id,并且在硬编码时同样有效,那么还有其他事情在起作用。
-
@DaveNewton 我还需要包括哪些其他上下文?除了我的数据库模型和我的实际数据之外,我已经提供了所有相关的东西。这是在一个函数/控制器内部,应该有零影响
-
@DaveNewton 我已经添加了堆栈跟踪以及来自 Stripe 的错误消息
-
您已经使用复制粘贴的字符串,然后您可以使用
console.log(subscriptionID == "<copy-pasted id>")仔细检查字符串值 -
@Neverever 我刚刚得到它,检查我回复的答案。我很想知道它为什么会这样工作