From 56b27b2e21be1c651ff54e52a5f790de7c70a203 Mon Sep 17 00:00:00 2001 From: Adrian Pilarczyk Date: Sun, 23 Apr 2023 13:18:20 +0200 Subject: [PATCH] fix: tax not calculating (#412) * fix: :bug: disable autocomplete on country-select * fix: :bug: invalid response format bug * build: :construction_worker: add changeset * docs: :bulb: add comment with improvement idea --- .changeset/dull-planets-dance.md | 5 +++++ apps/taxes/src/modules/app/webhook-response.ts | 10 ++++++---- .../src/modules/ui/country-select/country-select.tsx | 12 +++++++++++- .../src/pages/api/webhooks/order-calculate-taxes.ts | 2 +- 4 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 .changeset/dull-planets-dance.md diff --git a/.changeset/dull-planets-dance.md b/.changeset/dull-planets-dance.md new file mode 100644 index 0000000..efbd7c0 --- /dev/null +++ b/.changeset/dull-planets-dance.md @@ -0,0 +1,5 @@ +--- +"saleor-app-taxes": patch +--- + +Fix invalid response format in `order-calculate-taxes`. diff --git a/apps/taxes/src/modules/app/webhook-response.ts b/apps/taxes/src/modules/app/webhook-response.ts index 80a3db6..55cfd46 100644 --- a/apps/taxes/src/modules/app/webhook-response.ts +++ b/apps/taxes/src/modules/app/webhook-response.ts @@ -2,6 +2,11 @@ import { NextApiResponse } from "next"; import { Logger } from "pino"; import { createLogger } from "../../lib/logger"; +/* + * idea: distinguish between async and sync webhooks + * when sync webhooks, require passing the event and enforce the required response format using ctx.buildResponse + * when async webhooks, dont require anything + */ export class WebhookResponse { private logger: Logger; constructor(private res: NextApiResponse) { @@ -20,9 +25,6 @@ export class WebhookResponse { success(data?: any) { this.logger.debug({ data }, "success called with:"); - return this.res.status(200).json({ - status: 200, - data, - }); + return this.res.send(data); } } diff --git a/apps/taxes/src/modules/ui/country-select/country-select.tsx b/apps/taxes/src/modules/ui/country-select/country-select.tsx index 3c821a1..10e3243 100644 --- a/apps/taxes/src/modules/ui/country-select/country-select.tsx +++ b/apps/taxes/src/modules/ui/country-select/country-select.tsx @@ -37,7 +37,17 @@ export const CountrySelect = React.forwardRef((p: CountrySelectProps, ref) => { }) ?? null } getOptionLabel={(option) => option.label} - renderInput={(params) => } + renderInput={(params) => ( + + )} /> ); }); diff --git a/apps/taxes/src/pages/api/webhooks/order-calculate-taxes.ts b/apps/taxes/src/pages/api/webhooks/order-calculate-taxes.ts index ae1be5b..12b5fe6 100644 --- a/apps/taxes/src/pages/api/webhooks/order-calculate-taxes.ts +++ b/apps/taxes/src/pages/api/webhooks/order-calculate-taxes.ts @@ -66,7 +66,7 @@ export default orderCalculateTaxesSyncWebhook.createHandler(async (req, res, ctx const calculatedTaxes = await taxProvider.calculateTaxes(payload.taxBase); logger.info({ calculatedTaxes }, "Taxes calculated"); - return webhookResponse.success(calculatedTaxes); + return webhookResponse.success(ctx.buildResponse(calculatedTaxes)); } catch (error) { return webhookResponse.failureRetry("Error while calculating taxes"); }