Stripe - 如何同时列出活动订阅和试用订阅
Stripe - how to list active and trialing subscriptions together
我在 Stripe 中使用 NodeJs。我想以一种很好的方式检索一个客户的所有活动和试用订阅。到目前为止,我只能单独检索订阅。
const activeSubscriptionsObject = await stripe.subscriptions.list({
customer: customerId,
status: 'active'
});
const trialingSubscriptionsObject = await stripe.subscriptions.list({
customer: customerId,
status: 'trialing'
});
我应该怎么做才能获得同时包含试用和有效订阅的订阅对象?
您无法像您所要求的那样检索两个显式状态(而不是其他状态)。这样做的方法是:
- 如前所述,分别检索
active
和 trialing
,然后合并结果;或者,
- 用
status=all
请求列表以获取所有内容 (API ref),然后自己筛选结果。
像这样:
const allSubs = await stripe.subscriptions.list({
customer: customerId,
status: 'all'
});
const statuses = ['active', 'trialing'];
const trialAndActiveSubs = allSubs.data.filter(sub => statuses.includes(sub.status));
我在 Stripe 中使用 NodeJs。我想以一种很好的方式检索一个客户的所有活动和试用订阅。到目前为止,我只能单独检索订阅。
const activeSubscriptionsObject = await stripe.subscriptions.list({
customer: customerId,
status: 'active'
});
const trialingSubscriptionsObject = await stripe.subscriptions.list({
customer: customerId,
status: 'trialing'
});
我应该怎么做才能获得同时包含试用和有效订阅的订阅对象?
您无法像您所要求的那样检索两个显式状态(而不是其他状态)。这样做的方法是:
- 如前所述,分别检索
active
和trialing
,然后合并结果;或者, - 用
status=all
请求列表以获取所有内容 (API ref),然后自己筛选结果。
像这样:
const allSubs = await stripe.subscriptions.list({
customer: customerId,
status: 'all'
});
const statuses = ['active', 'trialing'];
const trialAndActiveSubs = allSubs.data.filter(sub => statuses.includes(sub.status));