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:
Stevche Radevski
2024-07-09 09:37:13 +00:00
committed by GitHub
parent db6969578f
commit 1c3ef13371
22 changed files with 824 additions and 121 deletions
+1
View File
@@ -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,
}
}