Closed 420coupe closed 2 months ago
So this is the piece of code causing the issue. it's just truncating instead of rounding. should something like a Math.round() be implemented to resolve this?
/**
* Converts an amount to the format required by Stripe based on currency.
* https://docs.stripe.com/currencies
* @param {BigNumberInput} amount - The amount to be converted.
* @param {string} currency - The currency code (e.g., 'USD', 'JOD').
* @returns {number} - The converted amount in the smallest currency unit.
*/
export function getSmallestUnit(
amount: BigNumberInput,
currency: string
): number {
const multiplier = getCurrencyMultiplier(currency)
const smallestAmount = new BigNumber(MathBN.mult(amount, multiplier))
let numeric = smallestAmount.numeric
// Check if the currency requires rounding to the nearest ten
if (multiplier === 1e3) {
numeric = Math.ceil(numeric / 10) * 10
}
return parseInt(numeric.toString().split(".").shift()!, 10)
}```
Bug report
Describe the bug
The discrepancy occurs with the
Total
amount displayed on the review page vs what is sent to stripe payment.Ex.
If actual total is
2.675
the amount sent to stripe is truncated2.67
and the Total displayed is2.68
System information
Medusa version (including plugins):
@medusajs/medusa@npm:1.20.6-preview-20240819150500 (via preview)
Node.js version:v21.7.1
Database:Supabase (postgres)
Operating system:Ubuntu 22.04.4
Browser (if relevant):Steps to reproduce the behavior
Expected behavior
The totals should match and it should round up to nearest hundreth place for usd currency.
Screenshots