
* refactor: ♻️ replace material-ui with macaw-ui; remove all views * add apps-ui * feat: add configuration screen (#514) * feat: ✨ add basic layout * refactor: 🔥 enabled field * refactor: ♻️ move part of config to credentials * refactor: ♻️ move address from channel to provider * feat: ✨ add all states for providers * refactor: ♻️ merge redesign with refactor * refactor: ♻️ replace material-ui with macaw-ui; remove all views * fix: 🐛 text-decoration on breadcrumb link * feat: ✨ add stripe icon * feat: ✨ add AppCard * feat: ✨ add AppBreadcrumbs and new provider pages * refactor: ♻️ add gridRatio to support two app grids * refactor: 🔥 theme-synchronizer test * refactor: ♻️ make breadcrumbs bulletproof * fix: 🐛 failing build * feat: ✨ add app-layout * build: ⬆️ upgrade macaw-ui * feat: redesign provider forms (#533) * build: ➕ add @saleor/react-hook-form-macaw * feat: add binding for Toggle in react-hook-form-macaw * feat: ✨ add AppToggle component * feat: ✨ add create-avatax-configuration and edit-avatax-configuration * feat: ✨ add taxjar-validation-service with address validation * feat: ✨ add AvataxValidationService * feat: ✨ add edit/create taxjar config * feat: ✨ add delete configuration * refactor: ♻️ change invalid address error message * refactor: ♻️ throw in validation services instead of authenticated: true/false * docs: 💡 add todo comments * refactor: ♻️ better variable naming in parse error * fix: 🐛 disable button when loading * refactor: ♻️ make defaultValues required * refactor: 🔥 remove custom fontWeights * fix: 🐛 toggle form submission bug * feat: ✨ extract provider-label and use in forms * feat: ✨ use new Section component and change copy * refactor: ♻️ use ProviderLabel in ProvidersTable * build: 💚 fix lockfile * fix: 🐛 address feedback * feat: channel provider table (#538) * refactor: 🔥 providers-config-input-schema * refactor: ♻️ move providers * feat: ✨ add basic channel-list * refactor: 🚚 move around * feat: ✨ add ChannelConfigurationService * feat: ✨ add select provider in channel table * refactor: 🔥 logger traces * refactor: 🔊 refine logs * feat: ✅ add avatax-config-mock-generator and use in webhooks mock generators * refactor: ♻️ split up avatax-validation.service and add tests for response resolver * feat: ✅ add avatax-validation-error-resolver tests * refactor: 🚚 move taxjar-validation.service to separate folder * feat: ✅ extract taxjar-validation-error-resolver and add tests * feat: ✅ add channel-config-mock-generator * feat: ✅ add ChannelFetcherMockGenerator * test: ✅ add tests for channel-configuration-merge * test: ✅ add tests for crud-settings.service * fix: 💬 channel copy * refactor: 🔊 remove data from logs * refactor: 🚚 move configuration & validation to configuration folder * fix: 🐛 imports * fix: 🐛 showing loading & add at the same time * refactor: ♻️ public configurations & obfuscation rework * refactor: 🚚 extract repositories from services * refactor: 🚚 instance -> connection (#544) * refactor: ♻️ move creating configuration service to procedure * fix: 🐛 some paths & names while renaming * Update apps/taxes/src/pages/api/webhooks/order-calculate-taxes.ts * Update apps/taxes/src/pages/api/webhooks/checkout-calculate-taxes.ts * feat: shipping tax code (#555) * fix: 💄 minor visual issues * feat: ✨ add shipping tax code * fix: 🐛 fix toggle * refactor: ♻️ use common table in providers-table * docs: 💡 add comment to obfuscator * feat: ✨ sort countries by label not code * Taxes 💸: Add runtime migrations to schema v2 (#545) * build: ➕ add dotenv * feat: 🚧 add draft of migration scripts * refactor: ♻️ settingsManager to accept appId * feat: ✨ tax-providers and channels transforms * feat: ✨ add migration classes * feat: 🚧 add migration to connection getAll * feat: 🚧 add dummy data script * feat: ✨ add runtime channel migration * feat: ✨ add migration and report scripts * fix: 🐛 name of dummy class method * feat: ✅ add transform tests * build: 💚 update lockfile * fix: creating & updating a provider (#563) * refactor: ✅ improve the test for update * docs: 💡 comment crud-settings * refactor: 🔥 unused file * fix: 🐛 appId bug * refactor: 🚚 rename dummy-utils * fix: 💄 padding in table * refactor: 💬 change avatax texts * build: 👷 add changeset
67 lines
2.2 KiB
TypeScript
67 lines
2.2 KiB
TypeScript
import { SaleorSyncWebhook } from "@saleor/app-sdk/handlers/next";
|
|
import {
|
|
CalculateTaxesEventFragment,
|
|
UntypedCalculateTaxesDocument,
|
|
} from "../../../../generated/graphql";
|
|
import { saleorApp } from "../../../../saleor-app";
|
|
import { createLogger } from "../../../lib/logger";
|
|
import { WebhookResponse } from "../../../modules/app/webhook-response";
|
|
import { getActiveConnection } from "../../../modules/taxes/active-connection";
|
|
|
|
export const config = {
|
|
api: {
|
|
bodyParser: false,
|
|
},
|
|
};
|
|
|
|
type CalculateTaxesPayload = Extract<CalculateTaxesEventFragment, { __typename: "CalculateTaxes" }>;
|
|
|
|
function verifyCalculateTaxesPayload(payload: CalculateTaxesPayload) {
|
|
if (!payload.taxBase.lines) {
|
|
throw new Error("No lines found in taxBase");
|
|
}
|
|
|
|
if (!payload.taxBase.address) {
|
|
throw new Error("No address found in taxBase");
|
|
}
|
|
|
|
return payload;
|
|
}
|
|
|
|
export const checkoutCalculateTaxesSyncWebhook = new SaleorSyncWebhook<CalculateTaxesPayload>({
|
|
name: "CheckoutCalculateTaxes",
|
|
apl: saleorApp.apl,
|
|
event: "CHECKOUT_CALCULATE_TAXES",
|
|
query: UntypedCalculateTaxesDocument,
|
|
webhookPath: "/api/webhooks/checkout-calculate-taxes",
|
|
});
|
|
|
|
export default checkoutCalculateTaxesSyncWebhook.createHandler(async (req, res, ctx) => {
|
|
const logger = createLogger({ location: "checkoutCalculateTaxesSyncWebhook" });
|
|
const { payload } = ctx;
|
|
const webhookResponse = new WebhookResponse(res);
|
|
|
|
logger.info("Handler for CHECKOUT_CALCULATE_TAXES webhook called");
|
|
|
|
try {
|
|
verifyCalculateTaxesPayload(payload);
|
|
logger.debug("Payload validated succesfully");
|
|
} catch (error) {
|
|
logger.debug("Payload validation failed");
|
|
return webhookResponse.error(error);
|
|
}
|
|
|
|
try {
|
|
const appMetadata = payload.recipient?.privateMetadata ?? [];
|
|
const channelSlug = payload.taxBase.channel.slug;
|
|
const taxProvider = getActiveConnection(channelSlug, appMetadata);
|
|
|
|
logger.info({ taxProvider }, "Will calculate taxes using the tax provider:");
|
|
const calculatedTaxes = await taxProvider.calculateTaxes(payload.taxBase);
|
|
|
|
logger.info({ calculatedTaxes }, "Taxes calculated");
|
|
return webhookResponse.success(ctx.buildResponse(calculatedTaxes));
|
|
} catch (error) {
|
|
return webhookResponse.error(error);
|
|
}
|
|
});
|