首页 > 解决方案 > 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: enter image description here

Plans get returned:

enter image description here

But the products list is empty:

enter image description here

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?

标签: javascriptnode.jspromisestripe-payments

解决方案


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

推荐阅读