[英]Retrieve all products prices with multiple currency options
我有兩個產品 A 和 B,每個有兩個價格(1 個月和 3 個月周期)。 每個價格都有兩種貨幣選項(美元和歐元)。
我可以使用以下方式列出所有價格:
const prices = await stripe.prices.list({});
但它不會返回每個產品價格的貨幣選項。 我只獲得默認貨幣 (USD) 的價格。 如何檢索所有貨幣的價格? 我試過這個:
const businessOwnerProduct = await stripe.prices.retrieve(
'price_xxxxxxxxxxxxxx',
{expand: ['currency_options']}
);
但它返回每個產品的價格。 因此我需要多個請求(4)。
有沒有辦法檢索產品列表+價格(多種貨幣)?
默認情況下不返回currency_options
屬性。 這就是 Stripe 所說的“可包含”屬性。 這個想法是渲染成本很高,因為您可能有多種貨幣,因此您必須在使用他們的Expand feature檢索它時明確要求它。
這是您的第二個示例在調用 Retrieve Price API時展開它的地方。
如此處所述,展開功能在列表調用期間也有效。 所以你的代碼應該是這樣的:
const prices = await stripe.prices.list({ expand: ['data.currency_options'], });
注意data.
前綴為 API 返回一個列表,該列表默認包含 10 個價格的data
數組
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.