#custom tax
7 messages · Page 1 of 1 (latest)
async getTaxLines(
itemLines: ItemTaxCalculationLine[],
shippingLines: ShippingTaxCalculationLine[],
context: TaxCalculationContext
): Promise<ProviderTaxLine[]> {
let customer;
if (context.customer) {
customer = await this.customerService_.retrieve(
context.customer.id,
{
relations: [
"billing_address"
],
}
);
console.log("user", customer);
}
let taxLines: ProviderTaxLine[] = itemLines.flatMap((l) => {
return l.rates.map((r) => ({
rate: customer ? customer.billing_address.country_code === 'it' ? r.rate : 0 : r.rate,
name: r.name,
code: r.code,
item_id: l.item.id,
}));
});
taxLines = taxLines.concat(
shippingLines.flatMap((l) => {
return l.rates.map((r) => ({
rate: customer ? customer.billing_address.country_code === 'it' ? r.rate : 0 : r.rate,
name: r.name,
code: r.code,
shipping_method_id: l.shipping_method.id,
}));
})
);
return taxLines;
}```
in checkout customer is undefined so rate will return r.rate, but, after purchase, customer is here and tax are correct