#custom tax

7 messages · Page 1 of 1 (latest)

late breach
#

Hello, in getTaxLines method im trying to retrieve customer context but sometimes is undefined, in checkout is undefined, anyone can tell me why please?

#
  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

late breach
#

im trying:

#

but console.log is never fired

#

2024-03-02T14:22:57.703121564Z {"level":"error","message":"Tax Lines must be joined to calculate taxes"