Stripe payments 使用非零单位\金额\小数点创建签出会话将返回不推荐使用的金额字段的错误消息

Stripe payments 使用非零单位\金额\小数点创建签出会话将返回不推荐使用的金额字段的错误消息,stripe-payments,Stripe Payments,当我试图创建一个签出会话时,如果我的单位金额小数点后的值不是零,我似乎遇到了一个奇怪的stripe响应行为 在postman(我刚刚替换了本例中的键和URL)中运行此命令,其中单位为23.99,即使我没有在帖子中使用该字段,也会给我一个错误响应,以处理不推荐的()“amount”字段: POST /v1/checkout/sessions HTTP/1.1 Host: api.stripe.com Authorization: Bearer sk_test_mytestenvironmentse

当我试图创建一个签出会话时,如果我的单位金额小数点后的值不是零,我似乎遇到了一个奇怪的stripe响应行为

在postman(我刚刚替换了本例中的键和URL)中运行此命令,其中单位为23.99,即使我没有在帖子中使用该字段,也会给我一个错误响应,以处理不推荐的()“amount”字段:

POST /v1/checkout/sessions HTTP/1.1
Host: api.stripe.com
Authorization: Bearer sk_test_mytestenvironmentsecretkey
Content-Type: application/x-www-form-urlencoded

success_url=https://example.com/payment/success&cancel_url=https://example.com/payment/cancel&payment_method_types[0]=card&mode=subscription&line_items[0][quantity]=1&line_items[0][price_data][currency]=USD&line_items[0][price_data][product]=prod_HoG79Vj0HStdtG&line_items[0][price_data][unit_amount_decimal]=23.99&line_items[0][price_data][recurring][interval]=day&line_items[0][price_data][recurring][interval_count]=1&customer=cus_HoG7QB7kstWaWB
Stripe的答复如下:

{
  "error": {
    "message": "Checkout does not support plans with more than 2 decimals in the `amount` in `line_items[0]`.",
    "param": "line_items[0]",
    "type": "invalid_request_error"
  }
}
例如,如果我执行相同的POST,但将unit_amount_decimal值更改为23.00/23.0/23,则它对请求感到满意,并使用checkout session对象进行响应:

POST /v1/checkout/sessions HTTP/1.1
Host: api.stripe.com
Authorization: Bearer sk_test_mytestenvironmentsecretkey
Content-Type: application/x-www-form-urlencoded

success_url=https://example.com/payment/success&cancel_url=https://example.com/payment/cancel&payment_method_types[0]=card&mode=subscription&line_items[0][quantity]=1&line_items[0][price_data][currency]=USD&line_items[0][price_data][product]=prod_HoG79Vj0HStdtG&line_items[0][price_data][unit_amount_decimal]=23.00&line_items[0][price_data][recurring][interval]=day&line_items[0][price_data][recurring][interval_count]=1&customer=cus_HoG7QB7kstWaWB
政府回应:

{
  "id": "cs_test_9FDuAIEyGuvb9RapQ0pOAs4240UHRhSqks1kezHYBhEaBX5tG59mOBqB",
  "object": "checkout.session",
  "allow_promotion_codes": null,
  "amount_subtotal": 23,
  "amount_total": 23,
  "billing_address_collection": null,
  "cancel_url": "https://example.com/payment/cancel",
  "client_reference_id": null,
  "currency": "usd",
  "customer": "cus_HoG7QB7kstWaWB",
  "customer_email": null,
  "livemode": false,
  "locale": null,
  "metadata": {},
  "mode": "subscription",
  "payment_intent": null,
  "payment_method_types": [
    "card"
  ],
  "setup_intent": null,
  "shipping": null,
  "shipping_address_collection": null,
  "submit_type": null,
  "subscription": null,
  "success_url": "https://example.com/payment/success",
  "total_details": {
    "amount_discount": 0,
    "amount_tax": 0
  }
}
我已经读过了,但还没有找到一个原因,为什么它不喜欢在小数点后加上除零值以外的其他值


有没有什么明显的错误?在我的场景中,在这篇文章之前创建价格对象对我来说没有意义,所以我希望我可以直接使用这个价格数据创建一个内嵌的价格对象

我误读了文档中的十进制值-它仍然用于定义次要单位(如美分)这意味着我通过23.99仍然意味着23.99便士,而不是我所想的23.99英镑


我已经联系了Stripe支持部门,他们回应说,他们不支持结账时金额低于美分的价格(这是可以理解的)。他们提出了这个问题,并将更新文档,这样会话对象就不会包含unit\u amount\u decimal属性。

我错误地阅读了文档中的十进制值-它仍然用于定义次要单位(如美分),这意味着我通过23.99仍然意味着23.99美分,而不是我所认为的23.99美元。但看起来这个“单位金额”小数位字段最多应该允许12位小数位。看起来是个bug,您应该联系Stripe支持部门