feat: Add necessary middlewares for tax inclusive pricing (#7827)
We are adding tax inclusive pricing calculation when listing products. Two things to keep in mind: - `region_id` will be required if you request calculated prices. - We won't accept `currency_code` anymore, as that will come from the region info (since ultimately a cart and its currency are tied to a region) REF CORE-2376 DEPENDS ON #8003
This commit is contained in:
@@ -2,6 +2,7 @@ export * from "./cart"
|
||||
export * from "./create-raw-properties-from-bignumber"
|
||||
export * from "./line-item"
|
||||
export * from "./math"
|
||||
export * from "./tax"
|
||||
export * from "./promotion"
|
||||
export * from "./shipping-method"
|
||||
export * from "./transform-properties-to-bignumber"
|
||||
|
||||
@@ -31,3 +31,24 @@ export function calculateTaxTotal({
|
||||
|
||||
return taxTotal
|
||||
}
|
||||
|
||||
export function calculateAmountsWithTax({
|
||||
taxLines,
|
||||
amount,
|
||||
includesTax,
|
||||
}: {
|
||||
taxLines: Pick<TaxLineDTO, "rate">[]
|
||||
amount: number
|
||||
includesTax?: boolean
|
||||
}) {
|
||||
const tax = calculateTaxTotal({
|
||||
taxLines,
|
||||
includesTax,
|
||||
taxableAmount: amount,
|
||||
})
|
||||
|
||||
return {
|
||||
priceWithTax: includesTax ? amount : MathBN.add(tax, amount).toNumber(),
|
||||
priceWithoutTax: includesTax ? MathBN.sub(amount, tax).toNumber() : amount,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user