fix: tax not calculating (#412)
* fix: 🐛 disable autocomplete on country-select * fix: 🐛 invalid response format bug * build: 👷 add changeset * docs: 💡 add comment with improvement idea
This commit is contained in:
parent
8424989dad
commit
56b27b2e21
4 changed files with 23 additions and 6 deletions
5
.changeset/dull-planets-dance.md
Normal file
5
.changeset/dull-planets-dance.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"saleor-app-taxes": patch
|
||||
---
|
||||
|
||||
Fix invalid response format in `order-calculate-taxes`.
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,17 @@ export const CountrySelect = React.forwardRef((p: CountrySelectProps, ref) => {
|
|||
}) ?? null
|
||||
}
|
||||
getOptionLabel={(option) => option.label}
|
||||
renderInput={(params) => <TextField {...params} inputRef={ref} placeholder={"Country"} />}
|
||||
renderInput={(params) => (
|
||||
<TextField
|
||||
{...params}
|
||||
inputRef={ref}
|
||||
placeholder={"Country"}
|
||||
inputProps={{
|
||||
...params.inputProps,
|
||||
autoComplete: "new-password", // disable autocomplete and autofill
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue