扩展 Stripe 价格的货币_选项层级

问题描述 投票:0回答:1

我需要使用 Stripe API 检索价格,其中包含层级、货币选项和货币选项内的层级。以下 CLI 命令确实返回根对象和currency_options 处的层,但不返回currency_options 内的层。这是为什么?

我确实在仪表板中看到了该价格的货币等级。

stripe prices retrieve X \
-d "expand[0]"=tiers \
-d "expand[1]"=currency_options.data.tiers

退货:

{
  "id": "X",
  "object": "price",
  "active": true,
  "billing_scheme": "tiered",
  "created": 1717060175,
  "currency": "eur",
  "currency_options": {
    "eur": {
      "custom_unit_amount": null,
      "tax_behavior": "exclusive",
      "unit_amount": null,
      "unit_amount_decimal": null
    },
    "usd": {
      "custom_unit_amount": null,
      "tax_behavior": "exclusive",
      "unit_amount": null,
      "unit_amount_decimal": null
    }
  },
  "custom_unit_amount": null,
  "livemode": false,
  "lookup_key": null,
  "metadata": {},
  "nickname": null,
  "product": "X",
  "recurring": {
    "aggregate_usage": null,
    "interval": "month",
    "interval_count": 1,
    "meter": null,
    "trial_period_days": null,
    "usage_type": "licensed"
  },
  "tax_behavior": "exclusive",
  "tiers": [
    {
      "flat_amount": null,
      "flat_amount_decimal": null,
      "unit_amount": 1500,
      "unit_amount_decimal": "1500",
      "up_to": 10
    },
    {
      "flat_amount": null,
      "flat_amount_decimal": null,
      "unit_amount": 1200,
      "unit_amount_decimal": "1200",
      "up_to": null
    }
  ],
  "tiers_mode": "volume",
  "transform_quantity": null,
  "type": "recurring",
  "unit_amount": null,
  "unit_amount_decimal": null
}

编辑:它似乎通过扩展特定货币来工作,因为currency_options从技术上讲不是一个列表,而是一个属性是货币代码的对象,值是货币选项,如下所示:

stripe prices retrieve X \
-d "expand[0]"=tiers \
-d "expand[1]"=currency_options.usd.tiers
-d "expand[2]"=currency_options.eur.tiers

但这显然不太实用,因为它需要在请求之前知道哪些货币将出现在currency_options中。解决方案是第一个请求了解货币,然后第二个请求扩展每种货币,但似乎应该存在更好的解决方案,不是吗?

stripe-payments
1个回答
0
投票

是的,不幸的是,与我们具有

data
扩展参数的数组对象相反,Stripe 不提供相同的动态属性。

© www.soinside.com 2019 - 2024. All rights reserved.