我正在尝试从 stripe 返回所有产品和计划列表。
但是,即使创建了一个active
产品,产品列表也会返回空的。
function getProductsAndPlans() {
return Promise.all([
stripe.products.list({}),
stripe.plans.list({}),
]).then(stripeData => {
console.log('products', stripeData[0]) <-- this is empty
console.log('plans', stripeData[1]) <-- this returns plans
}).catch(err => {
console.error('Error fetching Stripe products and plans: ', err);
return [];
});
}
计划被退回:
但是产品列表是空的:
这是 stripe 文档的副本。
const stripe = require('stripe')('sk_test_smkOYa912GSsdfdfDDfByiohm');
const products = await stripe.products.list({
limit: 3,
});
我在这里错过了什么?
最佳答案
这很可能与 API 更改有关 2018-02-05 ,当默认行为从 type=good
切换到 type=service
时,您的帐户可能有一个默认的 API 版本早于此。您的产品可能是 type=service
,如文档所述,默认情况下,旧 API 版本的产品列表请求会忽略它。
要获取产品列表请求以在仪表板中包含您正在使用的产品,您可以执行以下操作之一:
- 使用
stripe.products.list({type: 'service'})
明确请求service
产品(如 API 变更日志中所述) - 为 that request 覆盖您的默认 API ,带有
stripe.products.list({}, {apiVersion: '2018-02-05'})
(或任何更新版本) - 升级您的帐户 default API version
关于javascript - Node strip 产品列表返回空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64752137/