fix: 🐛 use "DEFAULT" value of companyCode for commit to work

This commit is contained in:
Adrian Pilarczyk 2023-08-02 11:47:24 +02:00
parent 79a1411a55
commit 293407e9f0
7 changed files with 12 additions and 21 deletions

View file

@ -3,8 +3,8 @@ import { DocumentType } from "avatax/lib/enums/DocumentType";
import { AddressLocationInfo as AvataxAddress } from "avatax/lib/models/AddressLocationInfo";
import { CommitTransactionModel } from "avatax/lib/models/CommitTransactionModel";
import { CreateTransactionModel } from "avatax/lib/models/CreateTransactionModel";
import { LogOptions } from "avatax/lib/utils/logger";
import packageJson from "../../../package.json";
import { createLogger, Logger } from "../../lib/logger";
import { AvataxClientTaxCodeService } from "./avatax-client-tax-code.service";
import { BaseAvataxConfig } from "./avatax-connection-schema";
@ -14,11 +14,7 @@ type AvataxSettings = {
environment: "sandbox" | "production";
machineName: string;
timeout: number;
logOptions?: {
logEnabled: boolean;
logLevel: number;
logRequestAndResponseInfo: boolean;
};
logOptions?: LogOptions;
};
const defaultAvataxSettings: AvataxSettings = {
@ -60,10 +56,8 @@ export type VoidTransactionArgs = {
export class AvataxClient {
private client: Avatax;
private logger: Logger;
constructor(baseConfig: BaseAvataxConfig) {
this.logger = createLogger({ name: "AvataxClient" });
const settings = createAvataxSettings({ isSandbox: baseConfig.isSandbox });
const avataxClient = new Avatax(settings).withSecurity(baseConfig.credentials);

View file

@ -24,7 +24,7 @@ export type BaseAvataxConfig = z.infer<typeof baseAvataxConfigSchema>;
export const avataxConfigSchema = z
.object({
name: z.string().min(1, { message: "Name requires at least one character." }),
companyCode: z.string().optional(),
companyCode: z.string(),
isAutocommit: z.boolean(),
shippingTaxCode: z.string().optional(),
isDocumentRecordingEnabled: z.boolean().default(true),
@ -36,7 +36,7 @@ export type AvataxConfig = z.infer<typeof avataxConfigSchema>;
export const defaultAvataxConfig: AvataxConfig = {
name: "",
companyCode: "",
companyCode: "DEFAULT",
isSandbox: false,
isAutocommit: false,
isDocumentRecordingEnabled: true,

View file

@ -15,10 +15,7 @@ export class AvataxOrderCancelledAdapter implements WebhookAdapter<OrderCancelle
}
async send(payload: OrderCancelledPayload) {
this.logger.debug(
{ payload },
"Transforming the Saleor payload for cancelling transaction with Avatax..."
);
this.logger.debug("Transforming the Saleor payload for cancelling transaction with Avatax...");
const payloadTransformer = new AvataxOrderCancelledPayloadTransformer(this.config);
const target = payloadTransformer.transform({ ...payload });

View file

@ -20,7 +20,7 @@ export class AvataxOrderFulfilledPayloadTransformer {
return {
transactionCode,
companyCode: this.config.companyCode ?? "",
companyCode: this.config.companyCode,
documentType: this.matchDocumentType(this.config),
model: {
commit: true,

View file

@ -42,7 +42,7 @@ export default orderCancelledAsyncWebhook.createHandler(async (req, res, ctx) =>
const channelSlug = payload.order.channel.slug;
const taxProvider = getActiveConnectionService(channelSlug, appMetadata, ctx.authData);
logger.info("Fetched taxProvider");
logger.info("Cancelling order...");
await taxProvider.cancelOrder(payload);

View file

@ -43,8 +43,6 @@ export default orderCreatedAsyncWebhook.createHandler(async (req, res, ctx) => {
const channelSlug = payload.order?.channel.slug;
const taxProvider = getActiveConnectionService(channelSlug, appMetadata, ctx.authData);
logger.info("Fetched taxProvider");
// todo: figure out what fields are needed and add validation
if (!payload.order) {
return webhookResponse.error(new Error("Insufficient order data"));
@ -54,6 +52,8 @@ export default orderCreatedAsyncWebhook.createHandler(async (req, res, ctx) => {
return webhookResponse.error(new Error("Skipping fulfilled order to prevent duplication"));
}
logger.info("Creating order...");
const createdOrder = await taxProvider.createOrder(payload.order);
logger.info({ createdOrder }, "Order created");

View file

@ -38,18 +38,18 @@ export default orderFulfilledAsyncWebhook.createHandler(async (req, res, ctx) =>
const channelSlug = payload.order?.channel.slug;
const taxProvider = getActiveConnectionService(channelSlug, appMetadata, ctx.authData);
logger.info("Fetched taxProvider");
// todo: figure out what fields are needed and add validation
if (!payload.order) {
return webhookResponse.error(new Error("Insufficient order data"));
}
logger.info("Fulfilling order...");
await taxProvider.fulfillOrder(payload.order);
logger.info("Order fulfilled");
return webhookResponse.success();
} catch (error) {
return webhookResponse.error(new Error("Error while fulfilling tax provider order"));
return webhookResponse.error(error);
}
});