创建一个非零unit_amount_decimal的签出会话会返回错误消息,其中包含已弃用的金额字段

问题描述

如果我的unit_amount_decimal的值在小数点后的值不是零,则尝试创建结帐会话时,我似乎从条带出现奇怪的响应行为。

在邮递员中运行此命令(对于示例,我只是替换了键和url),其中unit_amount_decimal为23.99,即使已弃用(according to their documentation)'金额'字段,我也会收到错误响应我不在POST中使用该字段:

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,则它对请求感到满意,并使用结帐会话对象进行响应:

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

Stripe的响应:

{
  "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
  }
}

我已经读过documentation around decimals amounts,但还没有看到为什么它不希望小数点后带有零以外的零值的原因。

我在这里做错了什么吗?在我的情况下,在此POST之前创建价格对象对我来说是没有意义的,因此我希望可以仅使用此price_data创建价格对象内联as their documentation suggests

解决方法

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

我已经联系了Stripe支持部门,他们回复说他们不支持Checkout中不足一分钱的价格(这是可以理解的)。他们提出了问题,并将更新文档,因此会话对象不包含unit_amount_decimal属性。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...