fix(payment-stripe): fix smallest unit calculation (#8663)
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { getSmallestUnit } from "../get-smallest-unit"
|
||||
|
||||
describe("getSmallestUnit", () => {
|
||||
it("should convert an amount to the format required by Stripe based on currency", () => {
|
||||
// 0 decimals
|
||||
expect(getSmallestUnit(50098, "JPY")).toBe(50098)
|
||||
|
||||
// 3 decimals
|
||||
expect(getSmallestUnit(5.124, "KWD")).toBe(5130)
|
||||
|
||||
// 2 decimals
|
||||
expect(getSmallestUnit(100.54, "USD")).toBe(10054)
|
||||
expect(getSmallestUnit(5.126, "KWD")).toBe(5130)
|
||||
expect(getSmallestUnit(0.54, "USD")).toBe(54)
|
||||
expect(getSmallestUnit(0.054, "USD")).toBe(5)
|
||||
expect(getSmallestUnit(0.005104, "USD")).toBe(0)
|
||||
})
|
||||
})
|
||||
@@ -56,7 +56,7 @@ export function getSmallestUnit(
|
||||
numeric = Math.ceil(numeric / 10) * 10
|
||||
}
|
||||
|
||||
return numeric
|
||||
return parseInt(numeric.toString().split(".").shift()!, 10)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user