#afonso
1 messages · Page 1 of 1 (latest)
I'm afraid there is no automatic way to do it. You'd have to handle the minor units for the currency used: https://stripe.com/docs/currencies
Ah ok, thanks
No problem! Happy to help 😄
I was just wondering
The unit_amount_decimal
Does it allow me to pass 12.41
instead of 1241?
For $12.41
Can you share where you see this unit_amount_decimal parameter?
I have the decimal amount saved.
And customer can configure the currency.
So when creating the invoice, I need the value to be interpreted as the decimal of the currency, and not the units.
So 12.41 with USD => $12.41
And 99.5 with YEN => 99 YEN
it seems like it's working
but just wanted to make sure that indeed this is expected behavior of unit_amount_decimal
If you're referring to unit_amount_decimal in Prices: https://stripe.com/docs/api/prices/object#price_object-unit_amount_decimal, the amount will be set in cent. It will work when you try the amount in cents.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Even though the currency might not have cents, right?
For example INR (indian rupee), doesn't have cents.
If I used the normal amount 100 would be interpreted as 100 INR.
With unit_amount_decimal it would be interpreted as 1 INR.
Am I correct?
Wait, how is it possible that INR has minum amount of ₹0.50?
The currency has no cents.
Oh actually that's wrong.
I tried with JPY and it charged me the amount * 100 :/
Story short I have values like 12.41, 99.00, 12.41 stored in the database, and I need stripe to take it these values as decimal, not as the minimum currency unit, do you understand?
If it was just USD or EUR, I could multiply by 100, but I need to support all currencies.
For now I'm doing it like this
function normalizeCurrency(amount, iso_code) {
switch (iso_code) {
case 'bif':
case 'clp':
case 'djf':
case 'gnf':
case 'jpy':
case 'kmf':
case 'krw':
case 'mga':
case 'pyg':
case 'rwf':
case 'ugx':
case 'vnd':
case 'vuv':
case 'xaf':
case 'xof':
case 'xpf':
return amount;
case 'BHD':
case 'JOD':
case 'KWD':
case 'OMR':
case 'TND':
return amount * 1000;
default:
return amount * 100;
}
}
module.exports = { normalizeCurrency };