#afonso

1 messages · Page 1 of 1 (latest)

severe terraceBOT
rotund harness
lone mesa
#

Ah ok, thanks

rotund harness
#

No problem! Happy to help 😄

lone mesa
#

I was just wondering

#

The unit_amount_decimal

#

Does it allow me to pass 12.41

#

instead of 1241?

#

For $12.41

rotund harness
#

Can you share where you see this unit_amount_decimal parameter?

lone mesa
#

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

rotund harness
lone mesa
#

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.

lone mesa
#

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 };
rotund harness
#

If you set amount to 100 for INR, it will be INR 1. If you set unit_amount_decimal to 100, it should be INR 100. I'd recommend testing it to check if this is the case

#

In general, I'd recommend using unit_amount and compute the integer amount on your own for greater accuracy

lone mesa
#

Yeah, that's what I'm going to do.

#

Thanks.