条纹-如何将小数金额发送给API以进行付款? [英] Stripe - How do you send decimal amounts to the API for a Payment?
问题描述
我正在将一个电子商务平台从使用SagePay迁移到Stripe.
I'm migrating an e-commerce platform from using SagePay to Stripe.
The docs show using an amount
figure of 1099
and a currency of gbp
(https://stripe.com/docs/payments/accept-a-payment#web-create-payment-intent).
据我所知,这意味着10.99英镑(而不是1099英镑).但这在他们的文档中还是非常不清楚的-我以为是这种情况.
As far as I can tell this means £10.99 (not £1099). But this is extremely unclear in their docs - I am assuming this is the case.
如果我尝试发送 amount =>10.99
通过他们的API,我在响应中收到一条错误消息:
If I try and send amount => 10.99
through their API, I get an error message in the response:
"error": {
"code": "parameter_invalid_integer",
"doc_url": "https://stripe.com/docs/error-codes/parameter-invalid-integer",
"message": "Invalid integer: 10.99",
"param": "amount",
"type": "invalid_request_error"
}
使用SagePay,您实际上会发送 10.99
作为金额.
With SagePay you would actually send 10.99
as the amount.
因此,使用Stripe,您是否必须将所有金额转换为货币的单个基本单位(在GBP情况下为便士),例如,如果金额为£10.99,则您要执行(10.99 *100)
,然后发送 1099
?
So, with Stripe, do you have to convert all amounts to the single base unit of a currency (pence in the case of GBP), for example if the amount was £10.99 you'd do (10.99 * 100)
then send 1099
?
文档实际上并没有明确说明.如果您阅读小数金额( https://stripe.com/docs/billing/在其文档中的subscriptions/decimal-amounts )中,您可以使用名为 amount_decimal
的参数,但是如果通过其API发送,也会出现错误:
The docs don't actually make this clear. If you read up on Decimal Amounts (https://stripe.com/docs/billing/subscriptions/decimal-amounts) in their docs it says you can use a parameter called amount_decimal
but this will also give an error if sent through their API:
$intent = \Stripe\PaymentIntent::create([
'amount_decimal' => 10.99,
'currency' => 'gbp',
// Verify your integration in this guide by including this parameter
'metadata' => ['integration_check' => 'accept_a_payment'],
]);
导致错误,提示参数 amount_decimal
未知(即使在文档中?):
Results in an error saying the parameter, amount_decimal
, is unknown (even though it's in their docs?):
"error": {
"code": "parameter_unknown",
"doc_url": "https://stripe.com/docs/error-codes/parameter-unknown",
"message": "Received unknown parameter: amount_decimal",
"param": "amount_decimal",
"type": "invalid_request_error"
}
我的假设是该错误是因为文档的这一部分是指计划"的帐单,而不是一次性付款.我想接受一次性发票的卡式付款,因此使用了接受卡付款文档.
My assumption is that this error is because this part of the documentation is referring to billing for "plans" as opposed to one-off Payments. I'm wanting to accept a card payment for one-off invoices so have used the Accept a Card Payment docs.
所以我的问题是:您是否只以货币的最小单位发送金额(例如10.99英镑的 10.99 * 100
),还是有其他方法可以将其作为十进制(即 10.99
)?
So my question is: Do you just send the amount in the smallest unit of the currency (e.g. 10.99 * 100
for £10.99), or is there some other method where it can be passed as a decimal (i.e. 10.99
)?
推荐答案
记录在此处:
所有API请求都希望以货币的最小单位提供金额.例如,要收取10美元,请提供金额为1000(即1000美分)的金额.对于零小数货币,仍应以整数形式提供金额,但不能乘以100.例如,要收取¥500,则提供金额值为500.
All API requests expect amounts to be provided in a currency’s smallest unit. For example, to charge 10 USD, provide an amount value of 1000 (i.e., 1000 cents). For zero-decimal currencies, still provide amounts as an integer but without multiplying by 100. For example, to charge ¥500, provide an amount value of 500.
您永远不会在Stripe API中的任何地方传递 amount
的小数点.除非在 API参考中明确列出,否则大多数API端点都不支持 amount_decimal
.
You will never pass a decimal point for amount
anywhere in the Stripe API. Most API endpoints do not support amount_decimal
unless it's explicitly listed in the API reference.
这篇关于条纹-如何将小数金额发送给API以进行付款?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!