You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何批量获取Stripe平台多币种的商品及价格信息?

问题描述

我有A、B两个商品,每个商品各包含1个月和3个月周期的两种价格,且每种价格均支持USD和EUR两种币种。目前我可以通过以下代码列出所有价格:

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

但该接口仅返回默认币种(USD)的价格,无法获取各价格对应的多币种选项。我尝试使用以下代码获取单条价格的多币种信息:

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

但此方法仅能返回单个价格的信息,需要发起4次请求才能获取全部数据。请问是否存在可一次性获取所有商品及其多币种价格列表的方法?

解决方案

Stripe的prices.list接口支持在请求中指定扩展字段,你可以直接在列表请求里添加expand: ['data.currency_options']参数,就能一次性获取所有价格的多币种配置,无需逐个调用retrieve接口。

修改后的代码如下:

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

返回的每个价格对象里都会包含currency_options字段,里面就是该价格对应的所有非默认币种的配置信息。

如果需要同时关联对应的商品信息,还可以额外扩展data.product字段,一次性拿到价格所属的商品详情:

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

这样返回的结果里,每个价格项都会附带对应的商品信息和多币种配置,只需要一次请求就能获取全部所需数据。

内容的提问来源于stack exchange,提问作者GuardianAngel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 00:10:34