最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - node stripe products list return empty - Stack Overflow

programmeradmin5浏览0评论

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?

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?

Share Improve this question asked Nov 9, 2020 at 12:58 AzimaAzima 4,15115 gold badges58 silver badges113 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

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:

  1. Explicitly request service Products with stripe.products.list({type: 'service'}) (as noted in the API changelog)
  2. Override your default API for that request, with stripe.products.list({}, {apiVersion: '2018-02-05'}) (or any later version)
  3. Upgrade your account default API version
发布评论

评论列表(0)

  1. 暂无评论