From 14902a4b68731172f8a0a140816700af195a13b5 Mon Sep 17 00:00:00 2001 From: Lukasz Ostrowski Date: Sun, 15 Dec 2024 18:37:55 +0100 Subject: [PATCH] log suspicious taxes calculation --- .changeset/six-lamps-shop.md | 5 +++++ .../calculate-taxes/avatax-calculate-taxes-adapter.ts | 11 +++++++++++ .../pages/api/webhooks/checkout-calculate-taxes.ts | 1 + 3 files changed, 17 insertions(+) create mode 100644 .changeset/six-lamps-shop.md diff --git a/.changeset/six-lamps-shop.md b/.changeset/six-lamps-shop.md new file mode 100644 index 000000000..1f7973d51 --- /dev/null +++ b/.changeset/six-lamps-shop.md @@ -0,0 +1,5 @@ +--- +"app-avatax": patch +--- + +Add log when suspicious calculation happen - when line tax rate is non-zero but amount of taxes is zero diff --git a/apps/avatax/src/modules/avatax/calculate-taxes/avatax-calculate-taxes-adapter.ts b/apps/avatax/src/modules/avatax/calculate-taxes/avatax-calculate-taxes-adapter.ts index 4f5cd3dab..c9f8b49b5 100644 --- a/apps/avatax/src/modules/avatax/calculate-taxes/avatax-calculate-taxes-adapter.ts +++ b/apps/avatax/src/modules/avatax/calculate-taxes/avatax-calculate-taxes-adapter.ts @@ -37,6 +37,17 @@ export class AvataxCalculateTaxesAdapter { const transformedResponse = this.avataxCalculateTaxesResponseTransformer.transform(response); + transformedResponse.lines.forEach((l) => { + const tax = (l.total_gross_amount = l.total_net_amount); + const rate = l.tax_rate; + + if (tax === 0 && rate !== 0) { + this.logger.warn("Line has zero tax, but rate is not zero", { + taxCalculationSummary: response.summary, + }); + } + }); + this.logger.debug("Transformed AvaTax createTransaction response"); return transformedResponse; diff --git a/apps/avatax/src/pages/api/webhooks/checkout-calculate-taxes.ts b/apps/avatax/src/pages/api/webhooks/checkout-calculate-taxes.ts index 39a6f1579..98d7e4af5 100644 --- a/apps/avatax/src/pages/api/webhooks/checkout-calculate-taxes.ts +++ b/apps/avatax/src/pages/api/webhooks/checkout-calculate-taxes.ts @@ -31,6 +31,7 @@ const handler = checkoutCalculateTaxesSyncWebhook.createHandler(async (req, res, /** * Create deps in handler, so it's potentially faster and reduce lambda start + * TODO: It's rather not true, we should move it outside */ const subscriptionErrorChecker = new SubscriptionPayloadErrorChecker(logger, captureException); const useCase = new CalculateTaxesUseCase({