chore(utils): currency epsilon (#14225)
* chore(utils): currency epsilon * pending diff * getEpsilonFromDecimalPrecision
This commit is contained in:
committed by
GitHub
parent
8bb2ac654c
commit
b3cb904e9b
@@ -1,4 +1,7 @@
|
||||
import { MathBN, MEDUSA_EPSILON } from "@medusajs/framework/utils"
|
||||
import {
|
||||
MathBN,
|
||||
MEDUSA_DEFAULT_CURRENCY_EPSILON,
|
||||
} from "@medusajs/framework/utils"
|
||||
import {
|
||||
getLastFulfillmentStatus,
|
||||
getLastPaymentStatus,
|
||||
@@ -113,7 +116,7 @@ describe("Aggregate Order Status", () => {
|
||||
{
|
||||
status: "authorized",
|
||||
captured_amount: 10,
|
||||
refunded_amount: MathBN.sub(10, MEDUSA_EPSILON),
|
||||
refunded_amount: MathBN.sub(10, MEDUSA_DEFAULT_CURRENCY_EPSILON),
|
||||
amount: 10,
|
||||
},
|
||||
{ status: "canceled" },
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import type { OrderDetailDTO } from "@medusajs/framework/types"
|
||||
import { isDefined, MathBN, MEDUSA_EPSILON } from "@medusajs/framework/utils"
|
||||
import {
|
||||
defaultCurrencies,
|
||||
getEpsilonFromDecimalPrecision,
|
||||
isDefined,
|
||||
MathBN,
|
||||
} from "@medusajs/framework/utils"
|
||||
|
||||
export const getLastPaymentStatus = (order: OrderDetailDTO) => {
|
||||
const PaymentStatus = {
|
||||
@@ -15,6 +20,11 @@ export const getLastPaymentStatus = (order: OrderDetailDTO) => {
|
||||
PARTIALLY_AUTHORIZED: "partially_authorized",
|
||||
}
|
||||
|
||||
const upperCurCode = order.currency_code?.toUpperCase() as string
|
||||
const currencyEpsilon = getEpsilonFromDecimalPrecision(
|
||||
defaultCurrencies[upperCurCode]?.decimal_digits
|
||||
)
|
||||
|
||||
let paymentStatus = {}
|
||||
for (const status in PaymentStatus) {
|
||||
paymentStatus[PaymentStatus[status]] = 0
|
||||
@@ -31,7 +41,7 @@ export const getLastPaymentStatus = (order: OrderDetailDTO) => {
|
||||
paymentCollection.amount,
|
||||
paymentCollection.captured_amount as number
|
||||
),
|
||||
MEDUSA_EPSILON
|
||||
currencyEpsilon
|
||||
)
|
||||
paymentStatus[PaymentStatus.CAPTURED] += isGte ? 1 : 0.5
|
||||
}
|
||||
@@ -42,7 +52,7 @@ export const getLastPaymentStatus = (order: OrderDetailDTO) => {
|
||||
paymentCollection.amount,
|
||||
paymentCollection.refunded_amount as number
|
||||
),
|
||||
MEDUSA_EPSILON
|
||||
currencyEpsilon
|
||||
)
|
||||
paymentStatus[PaymentStatus.REFUNDED] += isGte ? 1 : 0.5
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user