javascript - node stripe products list return empty
问题描述
I'm trying to return all products and plans list from stripe.
However the products list return empty even though there's a active
product created.
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 [];
});
}
Here are the products from my stripe dashboard:
Plans get returned:
But the products list is empty:
Here's a copy from the stripe doc.
const stripe = require('stripe')('sk_test_smkOYa912GSsdfdfDDfByiohm');
const products = await stripe.products.list({
limit: 3,
});
What am I missing here?
解决方案
Most likely this is related to the API changes from 2018-02-05, when the default behaviour switched from type=good
to type=service
, and your account probably having a default API version predating that. Your Product is likely a type=service
which, as documented, are omitted for Product list requests from older API version by default.
To get the products list request to include the products you're using in the dashboard, you can do one of the following:
- Explicitly request
service
Products withstripe.products.list({type: 'service'})
(as noted in the API changelog) - Override your default API for that request, with
stripe.products.list({}, {apiVersion: '2018-02-05'})
(or any later version) - Upgrade your account default API version
推荐阅读
- r - 使用 dcast 操作大型数据集
- dart - Dart:同时的 http 请求
- express - Busboy + Express:如何获取发送的文件及其规格
- html - 字体大小 rem 不能在不同的屏幕上缩放
- typescript - TypeScript 定义大型模型的更好方法
- python - Django REST Framework:指定 SerializerMethodField 的数据类型
- java - Spring找不到正在运行的kafka图像
- bash - 如何在heroku procfile中编写多行命令
- reactjs - 从 create-react-library 子文件夹导入组件
- java - 不能将旧元素向上推到数组中的一个位置