node.jsstripe-paymentsstripes

Retrieve all products prices with multiple currency options


I have two products A and B with two prices each (1 monthly and 3 months cycle). Every price has two currency options (USD and EUR).

I'm able to list all the prices using :

const prices = await stripe.prices.list({});

But it doesn't return the currency options for each product prices. I only get the price in the default currency (USD). How can retrieve prices with all the currencies ? I tried this :

const businessOwnerProduct = await stripe.prices.retrieve(
        'price_xxxxxxxxxxxxxx',
        {expand: ['currency_options']}
    );

But it returns the price per product. Thus i need multiple requests (4).

Is there a way to retrieve a list of products + prices (in multiple currencies) ?


Solution

  • The currency_options property is not returned by default. This is what Stripe calls an "includable" property. The idea is that it's costly to render as you could have many currencies and so you have to explicitly ask for it when you retrieve it using their Expand feature.

    This is what your second example does where you expand it when calling the Retrieve Price API.

    The Expand feature also works during a list call as documented here. So your code should look like this:

    const prices = await stripe.prices.list({
      expand: ['data.currency_options'],
    });
    

    Note the data. prefix as the API return a List which has the data array with 10 Prices by default