1 import { ITaxProvider, TaxTypes } from "@medusajs/framework/types"
2
3 export default class SystemTaxService implements ITaxProvider {
4 static identifier = "system"
5
6 getIdentifier(): string {
7 return SystemTaxService.identifier
8 }
9
10 async getTaxLines(
11 itemLines: TaxTypes.ItemTaxCalculationLine[],
12 shippingLines: TaxTypes.ShippingTaxCalculationLine[],
13 _: TaxTypes.TaxCalculationContext
14 ): Promise<(TaxTypes.ItemTaxLineDTO | TaxTypes.ShippingTaxLineDTO)[]> {
15 let taxLines: (TaxTypes.ItemTaxLineDTO | TaxTypes.ShippingTaxLineDTO)[] =
16 itemLines.flatMap((l) => {
17 return l.rates.map((r) => ({
18 rate_id: r.id,
19 rate: r.rate || 0,
20 name: r.name,
21 code: r.code,
22 line_item_id: l.line_item.id,
23 provider_id: this.getIdentifier(),
24 }))
25 })
26
27 taxLines = taxLines.concat(
28 shippingLines.flatMap((l) => {
29 return l.rates.map((r) => ({
30 rate_id: r.id,
31 rate: r.rate || 0,
32 name: r.name,
33 code: r.code,
34 shipping_line_id: l.shipping_line.id,
35 provider_id: this.getIdentifier(),
36 }))
37 })
38 )
39
40 return taxLines
41 }
42 }