saleor-apps-redis_apl/apps/taxes/src/pages/api/webhooks/checkout-calculate-taxes.ts

68 lines
2.2 KiB
TypeScript
Raw Normal View History

import { SaleorSyncWebhook } from "@saleor/app-sdk/handlers/next";
feat: finalize order process (#355) * feat: :sparkles: add dummy order-created * refactor: :fire: unused private-providers-configuration-service * feat: :sparkles: add dummy order-fulfilled * refactor: :truck: move provider-config * refactor: :truck: crudSettingsConfigurator -> crudSettingsManager * refactor: :recycle: [tax-provider].ts -> [tax-provider]-webhook.service.ts * feat: :sparkles: add dummy createOrder * refactor: :recycle: distinguish between salesOrder and salesInvoice in avatax * refactor: :truck: [provider]-calculate.ts to [provider]-transform.ts * refactor: :truck: ResponseTaxPayload to tax-provider-webhook.ts * refactor: :truck: ResponseTaxPayload -> CalculateTaxesResponse * refactor: :recycle: webhooks with active-tax-provider.service.ts * feat: :sparkles: add skeleton orderCreate functionality * refactor: :recycle: [provider]-transform.ts -> [provider]-[webhook]-transform.ts * feat: :sparkles: add order-fulfilled with avatax call * refactor: :recycle: move getActiveTaxProvider to active-tax-provider * refactor: :label: export types for [provider]-client function args * refactor: :truck: UpdateAppMetadata -> UpdateMetadata * feat: :sparkles: fulfill order with id from metadata * build: :arrow_up: upgrade avatax * feat: :sparkles: commit transaction on fulfill in avatax * fix: :bug: return of webhooks to ensure valid retry behavior * refactor: :truck: [provider]-[webhook]-transform -> [provider]-[webhook]-map * refactor: :label: export types of avatax-calculate-taxes mapPayload * refactor: :recycle: extract address-map to separate function * refactor: :recycle: remove schema.ts * refactor: :recycle: move addressSchema to channels-config.ts * feat: :sparkles: add tests & placeholder tests for avatax & taxjar maps * refactor: :recycle: throw error if no metadata * refactor: :recycle: change EXTERNAL_ID_KEY to PROVIDER_ORDER_ID_KEY add comments * refactor: :recycle: comments -> it.todo in tests * refactor: :bulb: add comment about shipping_item_code * refactor: :white_check_mark: add todo items for tests * refactor: :recycle: remove export and add sumLines to taxJarOrderCreated * refactor: :recycle: address-map with avatarAddressFactory * docs: :bulb: add comment about MOCKED_SALEOR_PAYLOAD * refactor: :recycle: remove export of mapLines and add to avataxCalculateTaxes * style: :art: add newline-after-var warn to eslint-config-saleor * style: :art: autofix newline-after-var in taxes * test: :white_check_mark: restructure tests according to new naming in address-map * refactor: :recycle: add shippingItemCode to avataxCalculateTaxes wrapper object * refactor: :truck: payloadProps -> payloadArgs * refactor: :recycle: add Maps suffix to map wrapper objects * refactor: :recycle: remove data: null from ActiveTaxProviderResult * refactor: :recycle: maintain the object hierarchy in tests * refactor: :recycle: refactor webhook responses with WebhookResponseFactory * build: :arrow_up: vitest * test: :white_check_mark: add tests for get-app-config-test * test: :white_check_mark: add tests for getActiveTaxProvider * refactor: :recycle: use address fragment for taxBase and order * refactor: :recycle: rename WebhookResponseFactory -> WebhookResponse * style: :construction_worker: add multiline-comment-style * fix: :bug: dummy test in get-app-config.test.ts * refactor: :recycle: rename AddressFragment -> Address * refactor: :recycle: use debug instead of error in webhook-response noRetry * refactor: :recycle: refactor as variables in mutation * build: :construction_worker: add changeset * refactor: :recycle: split changesets in two * build: :arrow_up: vite * build: :arrow_up: vite && vitest in all apps
2023-04-17 11:58:21 +00:00
import {
CalculateTaxesEventFragment,
UntypedCalculateTaxesDocument,
} from "../../../../generated/graphql";
import { saleorApp } from "../../../../saleor-app";
import { createLogger } from "../../../lib/logger";
feat: finalize order process (#355) * feat: :sparkles: add dummy order-created * refactor: :fire: unused private-providers-configuration-service * feat: :sparkles: add dummy order-fulfilled * refactor: :truck: move provider-config * refactor: :truck: crudSettingsConfigurator -> crudSettingsManager * refactor: :recycle: [tax-provider].ts -> [tax-provider]-webhook.service.ts * feat: :sparkles: add dummy createOrder * refactor: :recycle: distinguish between salesOrder and salesInvoice in avatax * refactor: :truck: [provider]-calculate.ts to [provider]-transform.ts * refactor: :truck: ResponseTaxPayload to tax-provider-webhook.ts * refactor: :truck: ResponseTaxPayload -> CalculateTaxesResponse * refactor: :recycle: webhooks with active-tax-provider.service.ts * feat: :sparkles: add skeleton orderCreate functionality * refactor: :recycle: [provider]-transform.ts -> [provider]-[webhook]-transform.ts * feat: :sparkles: add order-fulfilled with avatax call * refactor: :recycle: move getActiveTaxProvider to active-tax-provider * refactor: :label: export types for [provider]-client function args * refactor: :truck: UpdateAppMetadata -> UpdateMetadata * feat: :sparkles: fulfill order with id from metadata * build: :arrow_up: upgrade avatax * feat: :sparkles: commit transaction on fulfill in avatax * fix: :bug: return of webhooks to ensure valid retry behavior * refactor: :truck: [provider]-[webhook]-transform -> [provider]-[webhook]-map * refactor: :label: export types of avatax-calculate-taxes mapPayload * refactor: :recycle: extract address-map to separate function * refactor: :recycle: remove schema.ts * refactor: :recycle: move addressSchema to channels-config.ts * feat: :sparkles: add tests & placeholder tests for avatax & taxjar maps * refactor: :recycle: throw error if no metadata * refactor: :recycle: change EXTERNAL_ID_KEY to PROVIDER_ORDER_ID_KEY add comments * refactor: :recycle: comments -> it.todo in tests * refactor: :bulb: add comment about shipping_item_code * refactor: :white_check_mark: add todo items for tests * refactor: :recycle: remove export and add sumLines to taxJarOrderCreated * refactor: :recycle: address-map with avatarAddressFactory * docs: :bulb: add comment about MOCKED_SALEOR_PAYLOAD * refactor: :recycle: remove export of mapLines and add to avataxCalculateTaxes * style: :art: add newline-after-var warn to eslint-config-saleor * style: :art: autofix newline-after-var in taxes * test: :white_check_mark: restructure tests according to new naming in address-map * refactor: :recycle: add shippingItemCode to avataxCalculateTaxes wrapper object * refactor: :truck: payloadProps -> payloadArgs * refactor: :recycle: add Maps suffix to map wrapper objects * refactor: :recycle: remove data: null from ActiveTaxProviderResult * refactor: :recycle: maintain the object hierarchy in tests * refactor: :recycle: refactor webhook responses with WebhookResponseFactory * build: :arrow_up: vitest * test: :white_check_mark: add tests for get-app-config-test * test: :white_check_mark: add tests for getActiveTaxProvider * refactor: :recycle: use address fragment for taxBase and order * refactor: :recycle: rename WebhookResponseFactory -> WebhookResponse * style: :construction_worker: add multiline-comment-style * fix: :bug: dummy test in get-app-config.test.ts * refactor: :recycle: rename AddressFragment -> Address * refactor: :recycle: use debug instead of error in webhook-response noRetry * refactor: :recycle: refactor as variables in mutation * build: :construction_worker: add changeset * refactor: :recycle: split changesets in two * build: :arrow_up: vite * build: :arrow_up: vite && vitest in all apps
2023-04-17 11:58:21 +00:00
import { WebhookResponse } from "../../../modules/app/webhook-response";
feat: redesign taxes app with macaw-ui (#433) * refactor: :recycle: replace material-ui with macaw-ui; remove all views * add apps-ui * feat: add configuration screen (#514) * feat: :sparkles: add basic layout * refactor: :fire: enabled field * refactor: :recycle: move part of config to credentials * refactor: :recycle: move address from channel to provider * feat: :sparkles: add all states for providers * refactor: :recycle: merge redesign with refactor * refactor: :recycle: replace material-ui with macaw-ui; remove all views * fix: :bug: text-decoration on breadcrumb link * feat: :sparkles: add stripe icon * feat: :sparkles: add AppCard * feat: :sparkles: add AppBreadcrumbs and new provider pages * refactor: :recycle: add gridRatio to support two app grids * refactor: :fire: theme-synchronizer test * refactor: :recycle: make breadcrumbs bulletproof * fix: :bug: failing build * feat: :sparkles: add app-layout * build: :arrow_up: upgrade macaw-ui * feat: redesign provider forms (#533) * build: :heavy_plus_sign: add @saleor/react-hook-form-macaw * feat: add binding for Toggle in react-hook-form-macaw * feat: :sparkles: add AppToggle component * feat: :sparkles: add create-avatax-configuration and edit-avatax-configuration * feat: :sparkles: add taxjar-validation-service with address validation * feat: :sparkles: add AvataxValidationService * feat: :sparkles: add edit/create taxjar config * feat: :sparkles: add delete configuration * refactor: :recycle: change invalid address error message * refactor: :recycle: throw in validation services instead of authenticated: true/false * docs: :bulb: add todo comments * refactor: :recycle: better variable naming in parse error * fix: :bug: disable button when loading * refactor: :recycle: make defaultValues required * refactor: :fire: remove custom fontWeights * fix: :bug: toggle form submission bug * feat: :sparkles: extract provider-label and use in forms * feat: :sparkles: use new Section component and change copy * refactor: :recycle: use ProviderLabel in ProvidersTable * build: :green_heart: fix lockfile * fix: :bug: address feedback * feat: channel provider table (#538) * refactor: :fire: providers-config-input-schema * refactor: :recycle: move providers * feat: :sparkles: add basic channel-list * refactor: :truck: move around * feat: :sparkles: add ChannelConfigurationService * feat: :sparkles: add select provider in channel table * refactor: :fire: logger traces * refactor: :loud_sound: refine logs * feat: :white_check_mark: add avatax-config-mock-generator and use in webhooks mock generators * refactor: :recycle: split up avatax-validation.service and add tests for response resolver * feat: :white_check_mark: add avatax-validation-error-resolver tests * refactor: :truck: move taxjar-validation.service to separate folder * feat: :white_check_mark: extract taxjar-validation-error-resolver and add tests * feat: :white_check_mark: add channel-config-mock-generator * feat: :white_check_mark: add ChannelFetcherMockGenerator * test: :white_check_mark: add tests for channel-configuration-merge * test: :white_check_mark: add tests for crud-settings.service * fix: :speech_balloon: channel copy * refactor: :loud_sound: remove data from logs * refactor: :truck: move configuration & validation to configuration folder * fix: :bug: imports * fix: :bug: showing loading & add at the same time * refactor: :recycle: public configurations & obfuscation rework * refactor: :truck: extract repositories from services * refactor: :truck: instance -> connection (#544) * refactor: :recycle: move creating configuration service to procedure * fix: :bug: 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: :lipstick: minor visual issues * feat: :sparkles: add shipping tax code * fix: :bug: fix toggle * refactor: :recycle: use common table in providers-table * docs: :bulb: add comment to obfuscator * feat: :sparkles: sort countries by label not code * Taxes 💸: Add runtime migrations to schema v2 (#545) * build: :heavy_plus_sign: add dotenv * feat: :construction: add draft of migration scripts * refactor: :recycle: settingsManager to accept appId * feat: :sparkles: tax-providers and channels transforms * feat: :sparkles: add migration classes * feat: :construction: add migration to connection getAll * feat: :construction: add dummy data script * feat: :sparkles: add runtime channel migration * feat: :sparkles: add migration and report scripts * fix: :bug: name of dummy class method * feat: :white_check_mark: add transform tests * build: :green_heart: update lockfile * fix: creating & updating a provider (#563) * refactor: :white_check_mark: improve the test for update * docs: :bulb: comment crud-settings * refactor: :fire: unused file * fix: :bug: appId bug * refactor: :truck: rename dummy-utils * fix: :lipstick: padding in table * refactor: :speech_balloon: change avatax texts * build: :construction_worker: add changeset
2023-06-15 07:01:50 +00:00
import { getActiveConnection } from "../../../modules/taxes/active-connection";
export const config = {
api: {
bodyParser: false,
},
};
feat: finalize order process (#355) * feat: :sparkles: add dummy order-created * refactor: :fire: unused private-providers-configuration-service * feat: :sparkles: add dummy order-fulfilled * refactor: :truck: move provider-config * refactor: :truck: crudSettingsConfigurator -> crudSettingsManager * refactor: :recycle: [tax-provider].ts -> [tax-provider]-webhook.service.ts * feat: :sparkles: add dummy createOrder * refactor: :recycle: distinguish between salesOrder and salesInvoice in avatax * refactor: :truck: [provider]-calculate.ts to [provider]-transform.ts * refactor: :truck: ResponseTaxPayload to tax-provider-webhook.ts * refactor: :truck: ResponseTaxPayload -> CalculateTaxesResponse * refactor: :recycle: webhooks with active-tax-provider.service.ts * feat: :sparkles: add skeleton orderCreate functionality * refactor: :recycle: [provider]-transform.ts -> [provider]-[webhook]-transform.ts * feat: :sparkles: add order-fulfilled with avatax call * refactor: :recycle: move getActiveTaxProvider to active-tax-provider * refactor: :label: export types for [provider]-client function args * refactor: :truck: UpdateAppMetadata -> UpdateMetadata * feat: :sparkles: fulfill order with id from metadata * build: :arrow_up: upgrade avatax * feat: :sparkles: commit transaction on fulfill in avatax * fix: :bug: return of webhooks to ensure valid retry behavior * refactor: :truck: [provider]-[webhook]-transform -> [provider]-[webhook]-map * refactor: :label: export types of avatax-calculate-taxes mapPayload * refactor: :recycle: extract address-map to separate function * refactor: :recycle: remove schema.ts * refactor: :recycle: move addressSchema to channels-config.ts * feat: :sparkles: add tests & placeholder tests for avatax & taxjar maps * refactor: :recycle: throw error if no metadata * refactor: :recycle: change EXTERNAL_ID_KEY to PROVIDER_ORDER_ID_KEY add comments * refactor: :recycle: comments -> it.todo in tests * refactor: :bulb: add comment about shipping_item_code * refactor: :white_check_mark: add todo items for tests * refactor: :recycle: remove export and add sumLines to taxJarOrderCreated * refactor: :recycle: address-map with avatarAddressFactory * docs: :bulb: add comment about MOCKED_SALEOR_PAYLOAD * refactor: :recycle: remove export of mapLines and add to avataxCalculateTaxes * style: :art: add newline-after-var warn to eslint-config-saleor * style: :art: autofix newline-after-var in taxes * test: :white_check_mark: restructure tests according to new naming in address-map * refactor: :recycle: add shippingItemCode to avataxCalculateTaxes wrapper object * refactor: :truck: payloadProps -> payloadArgs * refactor: :recycle: add Maps suffix to map wrapper objects * refactor: :recycle: remove data: null from ActiveTaxProviderResult * refactor: :recycle: maintain the object hierarchy in tests * refactor: :recycle: refactor webhook responses with WebhookResponseFactory * build: :arrow_up: vitest * test: :white_check_mark: add tests for get-app-config-test * test: :white_check_mark: add tests for getActiveTaxProvider * refactor: :recycle: use address fragment for taxBase and order * refactor: :recycle: rename WebhookResponseFactory -> WebhookResponse * style: :construction_worker: add multiline-comment-style * fix: :bug: dummy test in get-app-config.test.ts * refactor: :recycle: rename AddressFragment -> Address * refactor: :recycle: use debug instead of error in webhook-response noRetry * refactor: :recycle: refactor as variables in mutation * build: :construction_worker: add changeset * refactor: :recycle: split changesets in two * build: :arrow_up: vite * build: :arrow_up: vite && vitest in all apps
2023-04-17 11:58:21 +00:00
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) => {
feat: redesign taxes app with macaw-ui (#433) * refactor: :recycle: replace material-ui with macaw-ui; remove all views * add apps-ui * feat: add configuration screen (#514) * feat: :sparkles: add basic layout * refactor: :fire: enabled field * refactor: :recycle: move part of config to credentials * refactor: :recycle: move address from channel to provider * feat: :sparkles: add all states for providers * refactor: :recycle: merge redesign with refactor * refactor: :recycle: replace material-ui with macaw-ui; remove all views * fix: :bug: text-decoration on breadcrumb link * feat: :sparkles: add stripe icon * feat: :sparkles: add AppCard * feat: :sparkles: add AppBreadcrumbs and new provider pages * refactor: :recycle: add gridRatio to support two app grids * refactor: :fire: theme-synchronizer test * refactor: :recycle: make breadcrumbs bulletproof * fix: :bug: failing build * feat: :sparkles: add app-layout * build: :arrow_up: upgrade macaw-ui * feat: redesign provider forms (#533) * build: :heavy_plus_sign: add @saleor/react-hook-form-macaw * feat: add binding for Toggle in react-hook-form-macaw * feat: :sparkles: add AppToggle component * feat: :sparkles: add create-avatax-configuration and edit-avatax-configuration * feat: :sparkles: add taxjar-validation-service with address validation * feat: :sparkles: add AvataxValidationService * feat: :sparkles: add edit/create taxjar config * feat: :sparkles: add delete configuration * refactor: :recycle: change invalid address error message * refactor: :recycle: throw in validation services instead of authenticated: true/false * docs: :bulb: add todo comments * refactor: :recycle: better variable naming in parse error * fix: :bug: disable button when loading * refactor: :recycle: make defaultValues required * refactor: :fire: remove custom fontWeights * fix: :bug: toggle form submission bug * feat: :sparkles: extract provider-label and use in forms * feat: :sparkles: use new Section component and change copy * refactor: :recycle: use ProviderLabel in ProvidersTable * build: :green_heart: fix lockfile * fix: :bug: address feedback * feat: channel provider table (#538) * refactor: :fire: providers-config-input-schema * refactor: :recycle: move providers * feat: :sparkles: add basic channel-list * refactor: :truck: move around * feat: :sparkles: add ChannelConfigurationService * feat: :sparkles: add select provider in channel table * refactor: :fire: logger traces * refactor: :loud_sound: refine logs * feat: :white_check_mark: add avatax-config-mock-generator and use in webhooks mock generators * refactor: :recycle: split up avatax-validation.service and add tests for response resolver * feat: :white_check_mark: add avatax-validation-error-resolver tests * refactor: :truck: move taxjar-validation.service to separate folder * feat: :white_check_mark: extract taxjar-validation-error-resolver and add tests * feat: :white_check_mark: add channel-config-mock-generator * feat: :white_check_mark: add ChannelFetcherMockGenerator * test: :white_check_mark: add tests for channel-configuration-merge * test: :white_check_mark: add tests for crud-settings.service * fix: :speech_balloon: channel copy * refactor: :loud_sound: remove data from logs * refactor: :truck: move configuration & validation to configuration folder * fix: :bug: imports * fix: :bug: showing loading & add at the same time * refactor: :recycle: public configurations & obfuscation rework * refactor: :truck: extract repositories from services * refactor: :truck: instance -> connection (#544) * refactor: :recycle: move creating configuration service to procedure * fix: :bug: 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: :lipstick: minor visual issues * feat: :sparkles: add shipping tax code * fix: :bug: fix toggle * refactor: :recycle: use common table in providers-table * docs: :bulb: add comment to obfuscator * feat: :sparkles: sort countries by label not code * Taxes 💸: Add runtime migrations to schema v2 (#545) * build: :heavy_plus_sign: add dotenv * feat: :construction: add draft of migration scripts * refactor: :recycle: settingsManager to accept appId * feat: :sparkles: tax-providers and channels transforms * feat: :sparkles: add migration classes * feat: :construction: add migration to connection getAll * feat: :construction: add dummy data script * feat: :sparkles: add runtime channel migration * feat: :sparkles: add migration and report scripts * fix: :bug: name of dummy class method * feat: :white_check_mark: add transform tests * build: :green_heart: update lockfile * fix: creating & updating a provider (#563) * refactor: :white_check_mark: improve the test for update * docs: :bulb: comment crud-settings * refactor: :fire: unused file * fix: :bug: appId bug * refactor: :truck: rename dummy-utils * fix: :lipstick: padding in table * refactor: :speech_balloon: change avatax texts * build: :construction_worker: add changeset
2023-06-15 07:01:50 +00:00
const logger = createLogger({ location: "checkoutCalculateTaxesSyncWebhook" });
const { payload } = ctx;
feat: finalize order process (#355) * feat: :sparkles: add dummy order-created * refactor: :fire: unused private-providers-configuration-service * feat: :sparkles: add dummy order-fulfilled * refactor: :truck: move provider-config * refactor: :truck: crudSettingsConfigurator -> crudSettingsManager * refactor: :recycle: [tax-provider].ts -> [tax-provider]-webhook.service.ts * feat: :sparkles: add dummy createOrder * refactor: :recycle: distinguish between salesOrder and salesInvoice in avatax * refactor: :truck: [provider]-calculate.ts to [provider]-transform.ts * refactor: :truck: ResponseTaxPayload to tax-provider-webhook.ts * refactor: :truck: ResponseTaxPayload -> CalculateTaxesResponse * refactor: :recycle: webhooks with active-tax-provider.service.ts * feat: :sparkles: add skeleton orderCreate functionality * refactor: :recycle: [provider]-transform.ts -> [provider]-[webhook]-transform.ts * feat: :sparkles: add order-fulfilled with avatax call * refactor: :recycle: move getActiveTaxProvider to active-tax-provider * refactor: :label: export types for [provider]-client function args * refactor: :truck: UpdateAppMetadata -> UpdateMetadata * feat: :sparkles: fulfill order with id from metadata * build: :arrow_up: upgrade avatax * feat: :sparkles: commit transaction on fulfill in avatax * fix: :bug: return of webhooks to ensure valid retry behavior * refactor: :truck: [provider]-[webhook]-transform -> [provider]-[webhook]-map * refactor: :label: export types of avatax-calculate-taxes mapPayload * refactor: :recycle: extract address-map to separate function * refactor: :recycle: remove schema.ts * refactor: :recycle: move addressSchema to channels-config.ts * feat: :sparkles: add tests & placeholder tests for avatax & taxjar maps * refactor: :recycle: throw error if no metadata * refactor: :recycle: change EXTERNAL_ID_KEY to PROVIDER_ORDER_ID_KEY add comments * refactor: :recycle: comments -> it.todo in tests * refactor: :bulb: add comment about shipping_item_code * refactor: :white_check_mark: add todo items for tests * refactor: :recycle: remove export and add sumLines to taxJarOrderCreated * refactor: :recycle: address-map with avatarAddressFactory * docs: :bulb: add comment about MOCKED_SALEOR_PAYLOAD * refactor: :recycle: remove export of mapLines and add to avataxCalculateTaxes * style: :art: add newline-after-var warn to eslint-config-saleor * style: :art: autofix newline-after-var in taxes * test: :white_check_mark: restructure tests according to new naming in address-map * refactor: :recycle: add shippingItemCode to avataxCalculateTaxes wrapper object * refactor: :truck: payloadProps -> payloadArgs * refactor: :recycle: add Maps suffix to map wrapper objects * refactor: :recycle: remove data: null from ActiveTaxProviderResult * refactor: :recycle: maintain the object hierarchy in tests * refactor: :recycle: refactor webhook responses with WebhookResponseFactory * build: :arrow_up: vitest * test: :white_check_mark: add tests for get-app-config-test * test: :white_check_mark: add tests for getActiveTaxProvider * refactor: :recycle: use address fragment for taxBase and order * refactor: :recycle: rename WebhookResponseFactory -> WebhookResponse * style: :construction_worker: add multiline-comment-style * fix: :bug: dummy test in get-app-config.test.ts * refactor: :recycle: rename AddressFragment -> Address * refactor: :recycle: use debug instead of error in webhook-response noRetry * refactor: :recycle: refactor as variables in mutation * build: :construction_worker: add changeset * refactor: :recycle: split changesets in two * build: :arrow_up: vite * build: :arrow_up: vite && vitest in all apps
2023-04-17 11:58:21 +00:00
const webhookResponse = new WebhookResponse(res);
feat: redesign taxes app with macaw-ui (#433) * refactor: :recycle: replace material-ui with macaw-ui; remove all views * add apps-ui * feat: add configuration screen (#514) * feat: :sparkles: add basic layout * refactor: :fire: enabled field * refactor: :recycle: move part of config to credentials * refactor: :recycle: move address from channel to provider * feat: :sparkles: add all states for providers * refactor: :recycle: merge redesign with refactor * refactor: :recycle: replace material-ui with macaw-ui; remove all views * fix: :bug: text-decoration on breadcrumb link * feat: :sparkles: add stripe icon * feat: :sparkles: add AppCard * feat: :sparkles: add AppBreadcrumbs and new provider pages * refactor: :recycle: add gridRatio to support two app grids * refactor: :fire: theme-synchronizer test * refactor: :recycle: make breadcrumbs bulletproof * fix: :bug: failing build * feat: :sparkles: add app-layout * build: :arrow_up: upgrade macaw-ui * feat: redesign provider forms (#533) * build: :heavy_plus_sign: add @saleor/react-hook-form-macaw * feat: add binding for Toggle in react-hook-form-macaw * feat: :sparkles: add AppToggle component * feat: :sparkles: add create-avatax-configuration and edit-avatax-configuration * feat: :sparkles: add taxjar-validation-service with address validation * feat: :sparkles: add AvataxValidationService * feat: :sparkles: add edit/create taxjar config * feat: :sparkles: add delete configuration * refactor: :recycle: change invalid address error message * refactor: :recycle: throw in validation services instead of authenticated: true/false * docs: :bulb: add todo comments * refactor: :recycle: better variable naming in parse error * fix: :bug: disable button when loading * refactor: :recycle: make defaultValues required * refactor: :fire: remove custom fontWeights * fix: :bug: toggle form submission bug * feat: :sparkles: extract provider-label and use in forms * feat: :sparkles: use new Section component and change copy * refactor: :recycle: use ProviderLabel in ProvidersTable * build: :green_heart: fix lockfile * fix: :bug: address feedback * feat: channel provider table (#538) * refactor: :fire: providers-config-input-schema * refactor: :recycle: move providers * feat: :sparkles: add basic channel-list * refactor: :truck: move around * feat: :sparkles: add ChannelConfigurationService * feat: :sparkles: add select provider in channel table * refactor: :fire: logger traces * refactor: :loud_sound: refine logs * feat: :white_check_mark: add avatax-config-mock-generator and use in webhooks mock generators * refactor: :recycle: split up avatax-validation.service and add tests for response resolver * feat: :white_check_mark: add avatax-validation-error-resolver tests * refactor: :truck: move taxjar-validation.service to separate folder * feat: :white_check_mark: extract taxjar-validation-error-resolver and add tests * feat: :white_check_mark: add channel-config-mock-generator * feat: :white_check_mark: add ChannelFetcherMockGenerator * test: :white_check_mark: add tests for channel-configuration-merge * test: :white_check_mark: add tests for crud-settings.service * fix: :speech_balloon: channel copy * refactor: :loud_sound: remove data from logs * refactor: :truck: move configuration & validation to configuration folder * fix: :bug: imports * fix: :bug: showing loading & add at the same time * refactor: :recycle: public configurations & obfuscation rework * refactor: :truck: extract repositories from services * refactor: :truck: instance -> connection (#544) * refactor: :recycle: move creating configuration service to procedure * fix: :bug: 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: :lipstick: minor visual issues * feat: :sparkles: add shipping tax code * fix: :bug: fix toggle * refactor: :recycle: use common table in providers-table * docs: :bulb: add comment to obfuscator * feat: :sparkles: sort countries by label not code * Taxes 💸: Add runtime migrations to schema v2 (#545) * build: :heavy_plus_sign: add dotenv * feat: :construction: add draft of migration scripts * refactor: :recycle: settingsManager to accept appId * feat: :sparkles: tax-providers and channels transforms * feat: :sparkles: add migration classes * feat: :construction: add migration to connection getAll * feat: :construction: add dummy data script * feat: :sparkles: add runtime channel migration * feat: :sparkles: add migration and report scripts * fix: :bug: name of dummy class method * feat: :white_check_mark: add transform tests * build: :green_heart: update lockfile * fix: creating & updating a provider (#563) * refactor: :white_check_mark: improve the test for update * docs: :bulb: comment crud-settings * refactor: :fire: unused file * fix: :bug: appId bug * refactor: :truck: rename dummy-utils * fix: :lipstick: padding in table * refactor: :speech_balloon: change avatax texts * build: :construction_worker: add changeset
2023-06-15 07:01:50 +00:00
logger.info("Handler for CHECKOUT_CALCULATE_TAXES webhook called");
feat: finalize order process (#355) * feat: :sparkles: add dummy order-created * refactor: :fire: unused private-providers-configuration-service * feat: :sparkles: add dummy order-fulfilled * refactor: :truck: move provider-config * refactor: :truck: crudSettingsConfigurator -> crudSettingsManager * refactor: :recycle: [tax-provider].ts -> [tax-provider]-webhook.service.ts * feat: :sparkles: add dummy createOrder * refactor: :recycle: distinguish between salesOrder and salesInvoice in avatax * refactor: :truck: [provider]-calculate.ts to [provider]-transform.ts * refactor: :truck: ResponseTaxPayload to tax-provider-webhook.ts * refactor: :truck: ResponseTaxPayload -> CalculateTaxesResponse * refactor: :recycle: webhooks with active-tax-provider.service.ts * feat: :sparkles: add skeleton orderCreate functionality * refactor: :recycle: [provider]-transform.ts -> [provider]-[webhook]-transform.ts * feat: :sparkles: add order-fulfilled with avatax call * refactor: :recycle: move getActiveTaxProvider to active-tax-provider * refactor: :label: export types for [provider]-client function args * refactor: :truck: UpdateAppMetadata -> UpdateMetadata * feat: :sparkles: fulfill order with id from metadata * build: :arrow_up: upgrade avatax * feat: :sparkles: commit transaction on fulfill in avatax * fix: :bug: return of webhooks to ensure valid retry behavior * refactor: :truck: [provider]-[webhook]-transform -> [provider]-[webhook]-map * refactor: :label: export types of avatax-calculate-taxes mapPayload * refactor: :recycle: extract address-map to separate function * refactor: :recycle: remove schema.ts * refactor: :recycle: move addressSchema to channels-config.ts * feat: :sparkles: add tests & placeholder tests for avatax & taxjar maps * refactor: :recycle: throw error if no metadata * refactor: :recycle: change EXTERNAL_ID_KEY to PROVIDER_ORDER_ID_KEY add comments * refactor: :recycle: comments -> it.todo in tests * refactor: :bulb: add comment about shipping_item_code * refactor: :white_check_mark: add todo items for tests * refactor: :recycle: remove export and add sumLines to taxJarOrderCreated * refactor: :recycle: address-map with avatarAddressFactory * docs: :bulb: add comment about MOCKED_SALEOR_PAYLOAD * refactor: :recycle: remove export of mapLines and add to avataxCalculateTaxes * style: :art: add newline-after-var warn to eslint-config-saleor * style: :art: autofix newline-after-var in taxes * test: :white_check_mark: restructure tests according to new naming in address-map * refactor: :recycle: add shippingItemCode to avataxCalculateTaxes wrapper object * refactor: :truck: payloadProps -> payloadArgs * refactor: :recycle: add Maps suffix to map wrapper objects * refactor: :recycle: remove data: null from ActiveTaxProviderResult * refactor: :recycle: maintain the object hierarchy in tests * refactor: :recycle: refactor webhook responses with WebhookResponseFactory * build: :arrow_up: vitest * test: :white_check_mark: add tests for get-app-config-test * test: :white_check_mark: add tests for getActiveTaxProvider * refactor: :recycle: use address fragment for taxBase and order * refactor: :recycle: rename WebhookResponseFactory -> WebhookResponse * style: :construction_worker: add multiline-comment-style * fix: :bug: dummy test in get-app-config.test.ts * refactor: :recycle: rename AddressFragment -> Address * refactor: :recycle: use debug instead of error in webhook-response noRetry * refactor: :recycle: refactor as variables in mutation * build: :construction_worker: add changeset * refactor: :recycle: split changesets in two * build: :arrow_up: vite * build: :arrow_up: vite && vitest in all apps
2023-04-17 11:58:21 +00:00
try {
verifyCalculateTaxesPayload(payload);
feat: redesign taxes app with macaw-ui (#433) * refactor: :recycle: replace material-ui with macaw-ui; remove all views * add apps-ui * feat: add configuration screen (#514) * feat: :sparkles: add basic layout * refactor: :fire: enabled field * refactor: :recycle: move part of config to credentials * refactor: :recycle: move address from channel to provider * feat: :sparkles: add all states for providers * refactor: :recycle: merge redesign with refactor * refactor: :recycle: replace material-ui with macaw-ui; remove all views * fix: :bug: text-decoration on breadcrumb link * feat: :sparkles: add stripe icon * feat: :sparkles: add AppCard * feat: :sparkles: add AppBreadcrumbs and new provider pages * refactor: :recycle: add gridRatio to support two app grids * refactor: :fire: theme-synchronizer test * refactor: :recycle: make breadcrumbs bulletproof * fix: :bug: failing build * feat: :sparkles: add app-layout * build: :arrow_up: upgrade macaw-ui * feat: redesign provider forms (#533) * build: :heavy_plus_sign: add @saleor/react-hook-form-macaw * feat: add binding for Toggle in react-hook-form-macaw * feat: :sparkles: add AppToggle component * feat: :sparkles: add create-avatax-configuration and edit-avatax-configuration * feat: :sparkles: add taxjar-validation-service with address validation * feat: :sparkles: add AvataxValidationService * feat: :sparkles: add edit/create taxjar config * feat: :sparkles: add delete configuration * refactor: :recycle: change invalid address error message * refactor: :recycle: throw in validation services instead of authenticated: true/false * docs: :bulb: add todo comments * refactor: :recycle: better variable naming in parse error * fix: :bug: disable button when loading * refactor: :recycle: make defaultValues required * refactor: :fire: remove custom fontWeights * fix: :bug: toggle form submission bug * feat: :sparkles: extract provider-label and use in forms * feat: :sparkles: use new Section component and change copy * refactor: :recycle: use ProviderLabel in ProvidersTable * build: :green_heart: fix lockfile * fix: :bug: address feedback * feat: channel provider table (#538) * refactor: :fire: providers-config-input-schema * refactor: :recycle: move providers * feat: :sparkles: add basic channel-list * refactor: :truck: move around * feat: :sparkles: add ChannelConfigurationService * feat: :sparkles: add select provider in channel table * refactor: :fire: logger traces * refactor: :loud_sound: refine logs * feat: :white_check_mark: add avatax-config-mock-generator and use in webhooks mock generators * refactor: :recycle: split up avatax-validation.service and add tests for response resolver * feat: :white_check_mark: add avatax-validation-error-resolver tests * refactor: :truck: move taxjar-validation.service to separate folder * feat: :white_check_mark: extract taxjar-validation-error-resolver and add tests * feat: :white_check_mark: add channel-config-mock-generator * feat: :white_check_mark: add ChannelFetcherMockGenerator * test: :white_check_mark: add tests for channel-configuration-merge * test: :white_check_mark: add tests for crud-settings.service * fix: :speech_balloon: channel copy * refactor: :loud_sound: remove data from logs * refactor: :truck: move configuration & validation to configuration folder * fix: :bug: imports * fix: :bug: showing loading & add at the same time * refactor: :recycle: public configurations & obfuscation rework * refactor: :truck: extract repositories from services * refactor: :truck: instance -> connection (#544) * refactor: :recycle: move creating configuration service to procedure * fix: :bug: 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: :lipstick: minor visual issues * feat: :sparkles: add shipping tax code * fix: :bug: fix toggle * refactor: :recycle: use common table in providers-table * docs: :bulb: add comment to obfuscator * feat: :sparkles: sort countries by label not code * Taxes 💸: Add runtime migrations to schema v2 (#545) * build: :heavy_plus_sign: add dotenv * feat: :construction: add draft of migration scripts * refactor: :recycle: settingsManager to accept appId * feat: :sparkles: tax-providers and channels transforms * feat: :sparkles: add migration classes * feat: :construction: add migration to connection getAll * feat: :construction: add dummy data script * feat: :sparkles: add runtime channel migration * feat: :sparkles: add migration and report scripts * fix: :bug: name of dummy class method * feat: :white_check_mark: add transform tests * build: :green_heart: update lockfile * fix: creating & updating a provider (#563) * refactor: :white_check_mark: improve the test for update * docs: :bulb: comment crud-settings * refactor: :fire: unused file * fix: :bug: appId bug * refactor: :truck: rename dummy-utils * fix: :lipstick: padding in table * refactor: :speech_balloon: change avatax texts * build: :construction_worker: add changeset
2023-06-15 07:01:50 +00:00
logger.debug("Payload validated succesfully");
feat: finalize order process (#355) * feat: :sparkles: add dummy order-created * refactor: :fire: unused private-providers-configuration-service * feat: :sparkles: add dummy order-fulfilled * refactor: :truck: move provider-config * refactor: :truck: crudSettingsConfigurator -> crudSettingsManager * refactor: :recycle: [tax-provider].ts -> [tax-provider]-webhook.service.ts * feat: :sparkles: add dummy createOrder * refactor: :recycle: distinguish between salesOrder and salesInvoice in avatax * refactor: :truck: [provider]-calculate.ts to [provider]-transform.ts * refactor: :truck: ResponseTaxPayload to tax-provider-webhook.ts * refactor: :truck: ResponseTaxPayload -> CalculateTaxesResponse * refactor: :recycle: webhooks with active-tax-provider.service.ts * feat: :sparkles: add skeleton orderCreate functionality * refactor: :recycle: [provider]-transform.ts -> [provider]-[webhook]-transform.ts * feat: :sparkles: add order-fulfilled with avatax call * refactor: :recycle: move getActiveTaxProvider to active-tax-provider * refactor: :label: export types for [provider]-client function args * refactor: :truck: UpdateAppMetadata -> UpdateMetadata * feat: :sparkles: fulfill order with id from metadata * build: :arrow_up: upgrade avatax * feat: :sparkles: commit transaction on fulfill in avatax * fix: :bug: return of webhooks to ensure valid retry behavior * refactor: :truck: [provider]-[webhook]-transform -> [provider]-[webhook]-map * refactor: :label: export types of avatax-calculate-taxes mapPayload * refactor: :recycle: extract address-map to separate function * refactor: :recycle: remove schema.ts * refactor: :recycle: move addressSchema to channels-config.ts * feat: :sparkles: add tests & placeholder tests for avatax & taxjar maps * refactor: :recycle: throw error if no metadata * refactor: :recycle: change EXTERNAL_ID_KEY to PROVIDER_ORDER_ID_KEY add comments * refactor: :recycle: comments -> it.todo in tests * refactor: :bulb: add comment about shipping_item_code * refactor: :white_check_mark: add todo items for tests * refactor: :recycle: remove export and add sumLines to taxJarOrderCreated * refactor: :recycle: address-map with avatarAddressFactory * docs: :bulb: add comment about MOCKED_SALEOR_PAYLOAD * refactor: :recycle: remove export of mapLines and add to avataxCalculateTaxes * style: :art: add newline-after-var warn to eslint-config-saleor * style: :art: autofix newline-after-var in taxes * test: :white_check_mark: restructure tests according to new naming in address-map * refactor: :recycle: add shippingItemCode to avataxCalculateTaxes wrapper object * refactor: :truck: payloadProps -> payloadArgs * refactor: :recycle: add Maps suffix to map wrapper objects * refactor: :recycle: remove data: null from ActiveTaxProviderResult * refactor: :recycle: maintain the object hierarchy in tests * refactor: :recycle: refactor webhook responses with WebhookResponseFactory * build: :arrow_up: vitest * test: :white_check_mark: add tests for get-app-config-test * test: :white_check_mark: add tests for getActiveTaxProvider * refactor: :recycle: use address fragment for taxBase and order * refactor: :recycle: rename WebhookResponseFactory -> WebhookResponse * style: :construction_worker: add multiline-comment-style * fix: :bug: dummy test in get-app-config.test.ts * refactor: :recycle: rename AddressFragment -> Address * refactor: :recycle: use debug instead of error in webhook-response noRetry * refactor: :recycle: refactor as variables in mutation * build: :construction_worker: add changeset * refactor: :recycle: split changesets in two * build: :arrow_up: vite * build: :arrow_up: vite && vitest in all apps
2023-04-17 11:58:21 +00:00
} catch (error) {
feat: redesign taxes app with macaw-ui (#433) * refactor: :recycle: replace material-ui with macaw-ui; remove all views * add apps-ui * feat: add configuration screen (#514) * feat: :sparkles: add basic layout * refactor: :fire: enabled field * refactor: :recycle: move part of config to credentials * refactor: :recycle: move address from channel to provider * feat: :sparkles: add all states for providers * refactor: :recycle: merge redesign with refactor * refactor: :recycle: replace material-ui with macaw-ui; remove all views * fix: :bug: text-decoration on breadcrumb link * feat: :sparkles: add stripe icon * feat: :sparkles: add AppCard * feat: :sparkles: add AppBreadcrumbs and new provider pages * refactor: :recycle: add gridRatio to support two app grids * refactor: :fire: theme-synchronizer test * refactor: :recycle: make breadcrumbs bulletproof * fix: :bug: failing build * feat: :sparkles: add app-layout * build: :arrow_up: upgrade macaw-ui * feat: redesign provider forms (#533) * build: :heavy_plus_sign: add @saleor/react-hook-form-macaw * feat: add binding for Toggle in react-hook-form-macaw * feat: :sparkles: add AppToggle component * feat: :sparkles: add create-avatax-configuration and edit-avatax-configuration * feat: :sparkles: add taxjar-validation-service with address validation * feat: :sparkles: add AvataxValidationService * feat: :sparkles: add edit/create taxjar config * feat: :sparkles: add delete configuration * refactor: :recycle: change invalid address error message * refactor: :recycle: throw in validation services instead of authenticated: true/false * docs: :bulb: add todo comments * refactor: :recycle: better variable naming in parse error * fix: :bug: disable button when loading * refactor: :recycle: make defaultValues required * refactor: :fire: remove custom fontWeights * fix: :bug: toggle form submission bug * feat: :sparkles: extract provider-label and use in forms * feat: :sparkles: use new Section component and change copy * refactor: :recycle: use ProviderLabel in ProvidersTable * build: :green_heart: fix lockfile * fix: :bug: address feedback * feat: channel provider table (#538) * refactor: :fire: providers-config-input-schema * refactor: :recycle: move providers * feat: :sparkles: add basic channel-list * refactor: :truck: move around * feat: :sparkles: add ChannelConfigurationService * feat: :sparkles: add select provider in channel table * refactor: :fire: logger traces * refactor: :loud_sound: refine logs * feat: :white_check_mark: add avatax-config-mock-generator and use in webhooks mock generators * refactor: :recycle: split up avatax-validation.service and add tests for response resolver * feat: :white_check_mark: add avatax-validation-error-resolver tests * refactor: :truck: move taxjar-validation.service to separate folder * feat: :white_check_mark: extract taxjar-validation-error-resolver and add tests * feat: :white_check_mark: add channel-config-mock-generator * feat: :white_check_mark: add ChannelFetcherMockGenerator * test: :white_check_mark: add tests for channel-configuration-merge * test: :white_check_mark: add tests for crud-settings.service * fix: :speech_balloon: channel copy * refactor: :loud_sound: remove data from logs * refactor: :truck: move configuration & validation to configuration folder * fix: :bug: imports * fix: :bug: showing loading & add at the same time * refactor: :recycle: public configurations & obfuscation rework * refactor: :truck: extract repositories from services * refactor: :truck: instance -> connection (#544) * refactor: :recycle: move creating configuration service to procedure * fix: :bug: 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: :lipstick: minor visual issues * feat: :sparkles: add shipping tax code * fix: :bug: fix toggle * refactor: :recycle: use common table in providers-table * docs: :bulb: add comment to obfuscator * feat: :sparkles: sort countries by label not code * Taxes 💸: Add runtime migrations to schema v2 (#545) * build: :heavy_plus_sign: add dotenv * feat: :construction: add draft of migration scripts * refactor: :recycle: settingsManager to accept appId * feat: :sparkles: tax-providers and channels transforms * feat: :sparkles: add migration classes * feat: :construction: add migration to connection getAll * feat: :construction: add dummy data script * feat: :sparkles: add runtime channel migration * feat: :sparkles: add migration and report scripts * fix: :bug: name of dummy class method * feat: :white_check_mark: add transform tests * build: :green_heart: update lockfile * fix: creating & updating a provider (#563) * refactor: :white_check_mark: improve the test for update * docs: :bulb: comment crud-settings * refactor: :fire: unused file * fix: :bug: appId bug * refactor: :truck: rename dummy-utils * fix: :lipstick: padding in table * refactor: :speech_balloon: change avatax texts * build: :construction_worker: add changeset
2023-06-15 07:01:50 +00:00
logger.debug("Payload validation failed");
refactor: refine taxjar (#494) * feat: :white_check_mark: add first tests & use address-factory * feat: :sparkles: add distributeDiscount * refactor: taxjar maps to adapters (#495) * refactor: :recycle: taxjar-calculate-taxes-map with taxjar-calculate-taxes-adapter * refactor: :recycle: taxjar-order-created-map -> taxjar-order-created-adapter * refactor: :recycle: address 1st batch of feedback * refactor: :recycle: split up taxjar-calculate-taxes-adapter * refactor: :truck: extract shipping transformer * docs: :bulb: add comment about refunds in distribute-discount * refactor: :truck: split up taxjar-order-created-adapter classes * refactor: :recycle: mocks with taxjar-mock-factory * refactor: :recycle: mocks with avatax-mock-factory * refactor: avatax maps to adapters (#506) * refactor: :recycle: move around & refactor avatax-order-created-map -> adapter * refactor: :truck: move avatax-order-created- to its own folder * refactor: :recycle: avatax-calculate-taxes-map -> adapter * refactor: :recycle: avatax-order-fulfilled-maps -> adapter * feat: :sparkles: add logger to adapters * refactor: :recycle: mocks -> avatax-mock-transaction-factory & fix tests * feat: add tests for taxjar (#509) * fix: :truck: tax-provider-utils.test name * feat: :white_check_mark: add nexus tests & other taxjar tests * feat: :goal_net: add ExpectedError and use it in webhook-response * refactor: :white_check_mark: unify taxjar-calculate-taxes tests with mock-generator * feat: :white_check_mark: add TaxJarOrderCreatedMockGenerator * feat: :white_check_mark: add avatax-calculate-taxes-mock-generator * feat: :white_check_mark: add AvataxOrderCreatedMockGenerator * refactor: :fire: tax-mock-factory * fix: :bug: housekeeping * fix: :bug: feedback * feat: :white_check_mark: add taxBase with discounts test * fix: :bug: address feedback * refactor: :fire: unused avatax-mock-factory functions * feat: :sparkles: use discount utils in all providers * feat: :sparkles: differentiate between pricesEnteredWithTax in taxjar
2023-05-29 08:35:34 +00:00
return webhookResponse.error(error);
}
try {
feat: finalize order process (#355) * feat: :sparkles: add dummy order-created * refactor: :fire: unused private-providers-configuration-service * feat: :sparkles: add dummy order-fulfilled * refactor: :truck: move provider-config * refactor: :truck: crudSettingsConfigurator -> crudSettingsManager * refactor: :recycle: [tax-provider].ts -> [tax-provider]-webhook.service.ts * feat: :sparkles: add dummy createOrder * refactor: :recycle: distinguish between salesOrder and salesInvoice in avatax * refactor: :truck: [provider]-calculate.ts to [provider]-transform.ts * refactor: :truck: ResponseTaxPayload to tax-provider-webhook.ts * refactor: :truck: ResponseTaxPayload -> CalculateTaxesResponse * refactor: :recycle: webhooks with active-tax-provider.service.ts * feat: :sparkles: add skeleton orderCreate functionality * refactor: :recycle: [provider]-transform.ts -> [provider]-[webhook]-transform.ts * feat: :sparkles: add order-fulfilled with avatax call * refactor: :recycle: move getActiveTaxProvider to active-tax-provider * refactor: :label: export types for [provider]-client function args * refactor: :truck: UpdateAppMetadata -> UpdateMetadata * feat: :sparkles: fulfill order with id from metadata * build: :arrow_up: upgrade avatax * feat: :sparkles: commit transaction on fulfill in avatax * fix: :bug: return of webhooks to ensure valid retry behavior * refactor: :truck: [provider]-[webhook]-transform -> [provider]-[webhook]-map * refactor: :label: export types of avatax-calculate-taxes mapPayload * refactor: :recycle: extract address-map to separate function * refactor: :recycle: remove schema.ts * refactor: :recycle: move addressSchema to channels-config.ts * feat: :sparkles: add tests & placeholder tests for avatax & taxjar maps * refactor: :recycle: throw error if no metadata * refactor: :recycle: change EXTERNAL_ID_KEY to PROVIDER_ORDER_ID_KEY add comments * refactor: :recycle: comments -> it.todo in tests * refactor: :bulb: add comment about shipping_item_code * refactor: :white_check_mark: add todo items for tests * refactor: :recycle: remove export and add sumLines to taxJarOrderCreated * refactor: :recycle: address-map with avatarAddressFactory * docs: :bulb: add comment about MOCKED_SALEOR_PAYLOAD * refactor: :recycle: remove export of mapLines and add to avataxCalculateTaxes * style: :art: add newline-after-var warn to eslint-config-saleor * style: :art: autofix newline-after-var in taxes * test: :white_check_mark: restructure tests according to new naming in address-map * refactor: :recycle: add shippingItemCode to avataxCalculateTaxes wrapper object * refactor: :truck: payloadProps -> payloadArgs * refactor: :recycle: add Maps suffix to map wrapper objects * refactor: :recycle: remove data: null from ActiveTaxProviderResult * refactor: :recycle: maintain the object hierarchy in tests * refactor: :recycle: refactor webhook responses with WebhookResponseFactory * build: :arrow_up: vitest * test: :white_check_mark: add tests for get-app-config-test * test: :white_check_mark: add tests for getActiveTaxProvider * refactor: :recycle: use address fragment for taxBase and order * refactor: :recycle: rename WebhookResponseFactory -> WebhookResponse * style: :construction_worker: add multiline-comment-style * fix: :bug: dummy test in get-app-config.test.ts * refactor: :recycle: rename AddressFragment -> Address * refactor: :recycle: use debug instead of error in webhook-response noRetry * refactor: :recycle: refactor as variables in mutation * build: :construction_worker: add changeset * refactor: :recycle: split changesets in two * build: :arrow_up: vite * build: :arrow_up: vite && vitest in all apps
2023-04-17 11:58:21 +00:00
const appMetadata = payload.recipient?.privateMetadata ?? [];
const channelSlug = payload.taxBase.channel.slug;
feat: redesign taxes app with macaw-ui (#433) * refactor: :recycle: replace material-ui with macaw-ui; remove all views * add apps-ui * feat: add configuration screen (#514) * feat: :sparkles: add basic layout * refactor: :fire: enabled field * refactor: :recycle: move part of config to credentials * refactor: :recycle: move address from channel to provider * feat: :sparkles: add all states for providers * refactor: :recycle: merge redesign with refactor * refactor: :recycle: replace material-ui with macaw-ui; remove all views * fix: :bug: text-decoration on breadcrumb link * feat: :sparkles: add stripe icon * feat: :sparkles: add AppCard * feat: :sparkles: add AppBreadcrumbs and new provider pages * refactor: :recycle: add gridRatio to support two app grids * refactor: :fire: theme-synchronizer test * refactor: :recycle: make breadcrumbs bulletproof * fix: :bug: failing build * feat: :sparkles: add app-layout * build: :arrow_up: upgrade macaw-ui * feat: redesign provider forms (#533) * build: :heavy_plus_sign: add @saleor/react-hook-form-macaw * feat: add binding for Toggle in react-hook-form-macaw * feat: :sparkles: add AppToggle component * feat: :sparkles: add create-avatax-configuration and edit-avatax-configuration * feat: :sparkles: add taxjar-validation-service with address validation * feat: :sparkles: add AvataxValidationService * feat: :sparkles: add edit/create taxjar config * feat: :sparkles: add delete configuration * refactor: :recycle: change invalid address error message * refactor: :recycle: throw in validation services instead of authenticated: true/false * docs: :bulb: add todo comments * refactor: :recycle: better variable naming in parse error * fix: :bug: disable button when loading * refactor: :recycle: make defaultValues required * refactor: :fire: remove custom fontWeights * fix: :bug: toggle form submission bug * feat: :sparkles: extract provider-label and use in forms * feat: :sparkles: use new Section component and change copy * refactor: :recycle: use ProviderLabel in ProvidersTable * build: :green_heart: fix lockfile * fix: :bug: address feedback * feat: channel provider table (#538) * refactor: :fire: providers-config-input-schema * refactor: :recycle: move providers * feat: :sparkles: add basic channel-list * refactor: :truck: move around * feat: :sparkles: add ChannelConfigurationService * feat: :sparkles: add select provider in channel table * refactor: :fire: logger traces * refactor: :loud_sound: refine logs * feat: :white_check_mark: add avatax-config-mock-generator and use in webhooks mock generators * refactor: :recycle: split up avatax-validation.service and add tests for response resolver * feat: :white_check_mark: add avatax-validation-error-resolver tests * refactor: :truck: move taxjar-validation.service to separate folder * feat: :white_check_mark: extract taxjar-validation-error-resolver and add tests * feat: :white_check_mark: add channel-config-mock-generator * feat: :white_check_mark: add ChannelFetcherMockGenerator * test: :white_check_mark: add tests for channel-configuration-merge * test: :white_check_mark: add tests for crud-settings.service * fix: :speech_balloon: channel copy * refactor: :loud_sound: remove data from logs * refactor: :truck: move configuration & validation to configuration folder * fix: :bug: imports * fix: :bug: showing loading & add at the same time * refactor: :recycle: public configurations & obfuscation rework * refactor: :truck: extract repositories from services * refactor: :truck: instance -> connection (#544) * refactor: :recycle: move creating configuration service to procedure * fix: :bug: 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: :lipstick: minor visual issues * feat: :sparkles: add shipping tax code * fix: :bug: fix toggle * refactor: :recycle: use common table in providers-table * docs: :bulb: add comment to obfuscator * feat: :sparkles: sort countries by label not code * Taxes 💸: Add runtime migrations to schema v2 (#545) * build: :heavy_plus_sign: add dotenv * feat: :construction: add draft of migration scripts * refactor: :recycle: settingsManager to accept appId * feat: :sparkles: tax-providers and channels transforms * feat: :sparkles: add migration classes * feat: :construction: add migration to connection getAll * feat: :construction: add dummy data script * feat: :sparkles: add runtime channel migration * feat: :sparkles: add migration and report scripts * fix: :bug: name of dummy class method * feat: :white_check_mark: add transform tests * build: :green_heart: update lockfile * fix: creating & updating a provider (#563) * refactor: :white_check_mark: improve the test for update * docs: :bulb: comment crud-settings * refactor: :fire: unused file * fix: :bug: appId bug * refactor: :truck: rename dummy-utils * fix: :lipstick: padding in table * refactor: :speech_balloon: change avatax texts * build: :construction_worker: add changeset
2023-06-15 07:01:50 +00:00
const taxProvider = getActiveConnection(channelSlug, appMetadata);
feat: redesign taxes app with macaw-ui (#433) * refactor: :recycle: replace material-ui with macaw-ui; remove all views * add apps-ui * feat: add configuration screen (#514) * feat: :sparkles: add basic layout * refactor: :fire: enabled field * refactor: :recycle: move part of config to credentials * refactor: :recycle: move address from channel to provider * feat: :sparkles: add all states for providers * refactor: :recycle: merge redesign with refactor * refactor: :recycle: replace material-ui with macaw-ui; remove all views * fix: :bug: text-decoration on breadcrumb link * feat: :sparkles: add stripe icon * feat: :sparkles: add AppCard * feat: :sparkles: add AppBreadcrumbs and new provider pages * refactor: :recycle: add gridRatio to support two app grids * refactor: :fire: theme-synchronizer test * refactor: :recycle: make breadcrumbs bulletproof * fix: :bug: failing build * feat: :sparkles: add app-layout * build: :arrow_up: upgrade macaw-ui * feat: redesign provider forms (#533) * build: :heavy_plus_sign: add @saleor/react-hook-form-macaw * feat: add binding for Toggle in react-hook-form-macaw * feat: :sparkles: add AppToggle component * feat: :sparkles: add create-avatax-configuration and edit-avatax-configuration * feat: :sparkles: add taxjar-validation-service with address validation * feat: :sparkles: add AvataxValidationService * feat: :sparkles: add edit/create taxjar config * feat: :sparkles: add delete configuration * refactor: :recycle: change invalid address error message * refactor: :recycle: throw in validation services instead of authenticated: true/false * docs: :bulb: add todo comments * refactor: :recycle: better variable naming in parse error * fix: :bug: disable button when loading * refactor: :recycle: make defaultValues required * refactor: :fire: remove custom fontWeights * fix: :bug: toggle form submission bug * feat: :sparkles: extract provider-label and use in forms * feat: :sparkles: use new Section component and change copy * refactor: :recycle: use ProviderLabel in ProvidersTable * build: :green_heart: fix lockfile * fix: :bug: address feedback * feat: channel provider table (#538) * refactor: :fire: providers-config-input-schema * refactor: :recycle: move providers * feat: :sparkles: add basic channel-list * refactor: :truck: move around * feat: :sparkles: add ChannelConfigurationService * feat: :sparkles: add select provider in channel table * refactor: :fire: logger traces * refactor: :loud_sound: refine logs * feat: :white_check_mark: add avatax-config-mock-generator and use in webhooks mock generators * refactor: :recycle: split up avatax-validation.service and add tests for response resolver * feat: :white_check_mark: add avatax-validation-error-resolver tests * refactor: :truck: move taxjar-validation.service to separate folder * feat: :white_check_mark: extract taxjar-validation-error-resolver and add tests * feat: :white_check_mark: add channel-config-mock-generator * feat: :white_check_mark: add ChannelFetcherMockGenerator * test: :white_check_mark: add tests for channel-configuration-merge * test: :white_check_mark: add tests for crud-settings.service * fix: :speech_balloon: channel copy * refactor: :loud_sound: remove data from logs * refactor: :truck: move configuration & validation to configuration folder * fix: :bug: imports * fix: :bug: showing loading & add at the same time * refactor: :recycle: public configurations & obfuscation rework * refactor: :truck: extract repositories from services * refactor: :truck: instance -> connection (#544) * refactor: :recycle: move creating configuration service to procedure * fix: :bug: 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: :lipstick: minor visual issues * feat: :sparkles: add shipping tax code * fix: :bug: fix toggle * refactor: :recycle: use common table in providers-table * docs: :bulb: add comment to obfuscator * feat: :sparkles: sort countries by label not code * Taxes 💸: Add runtime migrations to schema v2 (#545) * build: :heavy_plus_sign: add dotenv * feat: :construction: add draft of migration scripts * refactor: :recycle: settingsManager to accept appId * feat: :sparkles: tax-providers and channels transforms * feat: :sparkles: add migration classes * feat: :construction: add migration to connection getAll * feat: :construction: add dummy data script * feat: :sparkles: add runtime channel migration * feat: :sparkles: add migration and report scripts * fix: :bug: name of dummy class method * feat: :white_check_mark: add transform tests * build: :green_heart: update lockfile * fix: creating & updating a provider (#563) * refactor: :white_check_mark: improve the test for update * docs: :bulb: comment crud-settings * refactor: :fire: unused file * fix: :bug: appId bug * refactor: :truck: rename dummy-utils * fix: :lipstick: padding in table * refactor: :speech_balloon: change avatax texts * build: :construction_worker: add changeset
2023-06-15 07:01:50 +00:00
logger.info({ taxProvider }, "Will calculate taxes using the tax provider:");
feat: finalize order process (#355) * feat: :sparkles: add dummy order-created * refactor: :fire: unused private-providers-configuration-service * feat: :sparkles: add dummy order-fulfilled * refactor: :truck: move provider-config * refactor: :truck: crudSettingsConfigurator -> crudSettingsManager * refactor: :recycle: [tax-provider].ts -> [tax-provider]-webhook.service.ts * feat: :sparkles: add dummy createOrder * refactor: :recycle: distinguish between salesOrder and salesInvoice in avatax * refactor: :truck: [provider]-calculate.ts to [provider]-transform.ts * refactor: :truck: ResponseTaxPayload to tax-provider-webhook.ts * refactor: :truck: ResponseTaxPayload -> CalculateTaxesResponse * refactor: :recycle: webhooks with active-tax-provider.service.ts * feat: :sparkles: add skeleton orderCreate functionality * refactor: :recycle: [provider]-transform.ts -> [provider]-[webhook]-transform.ts * feat: :sparkles: add order-fulfilled with avatax call * refactor: :recycle: move getActiveTaxProvider to active-tax-provider * refactor: :label: export types for [provider]-client function args * refactor: :truck: UpdateAppMetadata -> UpdateMetadata * feat: :sparkles: fulfill order with id from metadata * build: :arrow_up: upgrade avatax * feat: :sparkles: commit transaction on fulfill in avatax * fix: :bug: return of webhooks to ensure valid retry behavior * refactor: :truck: [provider]-[webhook]-transform -> [provider]-[webhook]-map * refactor: :label: export types of avatax-calculate-taxes mapPayload * refactor: :recycle: extract address-map to separate function * refactor: :recycle: remove schema.ts * refactor: :recycle: move addressSchema to channels-config.ts * feat: :sparkles: add tests & placeholder tests for avatax & taxjar maps * refactor: :recycle: throw error if no metadata * refactor: :recycle: change EXTERNAL_ID_KEY to PROVIDER_ORDER_ID_KEY add comments * refactor: :recycle: comments -> it.todo in tests * refactor: :bulb: add comment about shipping_item_code * refactor: :white_check_mark: add todo items for tests * refactor: :recycle: remove export and add sumLines to taxJarOrderCreated * refactor: :recycle: address-map with avatarAddressFactory * docs: :bulb: add comment about MOCKED_SALEOR_PAYLOAD * refactor: :recycle: remove export of mapLines and add to avataxCalculateTaxes * style: :art: add newline-after-var warn to eslint-config-saleor * style: :art: autofix newline-after-var in taxes * test: :white_check_mark: restructure tests according to new naming in address-map * refactor: :recycle: add shippingItemCode to avataxCalculateTaxes wrapper object * refactor: :truck: payloadProps -> payloadArgs * refactor: :recycle: add Maps suffix to map wrapper objects * refactor: :recycle: remove data: null from ActiveTaxProviderResult * refactor: :recycle: maintain the object hierarchy in tests * refactor: :recycle: refactor webhook responses with WebhookResponseFactory * build: :arrow_up: vitest * test: :white_check_mark: add tests for get-app-config-test * test: :white_check_mark: add tests for getActiveTaxProvider * refactor: :recycle: use address fragment for taxBase and order * refactor: :recycle: rename WebhookResponseFactory -> WebhookResponse * style: :construction_worker: add multiline-comment-style * fix: :bug: dummy test in get-app-config.test.ts * refactor: :recycle: rename AddressFragment -> Address * refactor: :recycle: use debug instead of error in webhook-response noRetry * refactor: :recycle: refactor as variables in mutation * build: :construction_worker: add changeset * refactor: :recycle: split changesets in two * build: :arrow_up: vite * build: :arrow_up: vite && vitest in all apps
2023-04-17 11:58:21 +00:00
const calculatedTaxes = await taxProvider.calculateTaxes(payload.taxBase);
logger.info({ calculatedTaxes }, "Taxes calculated");
feat: finalize order process (#355) * feat: :sparkles: add dummy order-created * refactor: :fire: unused private-providers-configuration-service * feat: :sparkles: add dummy order-fulfilled * refactor: :truck: move provider-config * refactor: :truck: crudSettingsConfigurator -> crudSettingsManager * refactor: :recycle: [tax-provider].ts -> [tax-provider]-webhook.service.ts * feat: :sparkles: add dummy createOrder * refactor: :recycle: distinguish between salesOrder and salesInvoice in avatax * refactor: :truck: [provider]-calculate.ts to [provider]-transform.ts * refactor: :truck: ResponseTaxPayload to tax-provider-webhook.ts * refactor: :truck: ResponseTaxPayload -> CalculateTaxesResponse * refactor: :recycle: webhooks with active-tax-provider.service.ts * feat: :sparkles: add skeleton orderCreate functionality * refactor: :recycle: [provider]-transform.ts -> [provider]-[webhook]-transform.ts * feat: :sparkles: add order-fulfilled with avatax call * refactor: :recycle: move getActiveTaxProvider to active-tax-provider * refactor: :label: export types for [provider]-client function args * refactor: :truck: UpdateAppMetadata -> UpdateMetadata * feat: :sparkles: fulfill order with id from metadata * build: :arrow_up: upgrade avatax * feat: :sparkles: commit transaction on fulfill in avatax * fix: :bug: return of webhooks to ensure valid retry behavior * refactor: :truck: [provider]-[webhook]-transform -> [provider]-[webhook]-map * refactor: :label: export types of avatax-calculate-taxes mapPayload * refactor: :recycle: extract address-map to separate function * refactor: :recycle: remove schema.ts * refactor: :recycle: move addressSchema to channels-config.ts * feat: :sparkles: add tests & placeholder tests for avatax & taxjar maps * refactor: :recycle: throw error if no metadata * refactor: :recycle: change EXTERNAL_ID_KEY to PROVIDER_ORDER_ID_KEY add comments * refactor: :recycle: comments -> it.todo in tests * refactor: :bulb: add comment about shipping_item_code * refactor: :white_check_mark: add todo items for tests * refactor: :recycle: remove export and add sumLines to taxJarOrderCreated * refactor: :recycle: address-map with avatarAddressFactory * docs: :bulb: add comment about MOCKED_SALEOR_PAYLOAD * refactor: :recycle: remove export of mapLines and add to avataxCalculateTaxes * style: :art: add newline-after-var warn to eslint-config-saleor * style: :art: autofix newline-after-var in taxes * test: :white_check_mark: restructure tests according to new naming in address-map * refactor: :recycle: add shippingItemCode to avataxCalculateTaxes wrapper object * refactor: :truck: payloadProps -> payloadArgs * refactor: :recycle: add Maps suffix to map wrapper objects * refactor: :recycle: remove data: null from ActiveTaxProviderResult * refactor: :recycle: maintain the object hierarchy in tests * refactor: :recycle: refactor webhook responses with WebhookResponseFactory * build: :arrow_up: vitest * test: :white_check_mark: add tests for get-app-config-test * test: :white_check_mark: add tests for getActiveTaxProvider * refactor: :recycle: use address fragment for taxBase and order * refactor: :recycle: rename WebhookResponseFactory -> WebhookResponse * style: :construction_worker: add multiline-comment-style * fix: :bug: dummy test in get-app-config.test.ts * refactor: :recycle: rename AddressFragment -> Address * refactor: :recycle: use debug instead of error in webhook-response noRetry * refactor: :recycle: refactor as variables in mutation * build: :construction_worker: add changeset * refactor: :recycle: split changesets in two * build: :arrow_up: vite * build: :arrow_up: vite && vitest in all apps
2023-04-17 11:58:21 +00:00
return webhookResponse.success(ctx.buildResponse(calculatedTaxes));
} catch (error) {
refactor: refine taxjar (#494) * feat: :white_check_mark: add first tests & use address-factory * feat: :sparkles: add distributeDiscount * refactor: taxjar maps to adapters (#495) * refactor: :recycle: taxjar-calculate-taxes-map with taxjar-calculate-taxes-adapter * refactor: :recycle: taxjar-order-created-map -> taxjar-order-created-adapter * refactor: :recycle: address 1st batch of feedback * refactor: :recycle: split up taxjar-calculate-taxes-adapter * refactor: :truck: extract shipping transformer * docs: :bulb: add comment about refunds in distribute-discount * refactor: :truck: split up taxjar-order-created-adapter classes * refactor: :recycle: mocks with taxjar-mock-factory * refactor: :recycle: mocks with avatax-mock-factory * refactor: avatax maps to adapters (#506) * refactor: :recycle: move around & refactor avatax-order-created-map -> adapter * refactor: :truck: move avatax-order-created- to its own folder * refactor: :recycle: avatax-calculate-taxes-map -> adapter * refactor: :recycle: avatax-order-fulfilled-maps -> adapter * feat: :sparkles: add logger to adapters * refactor: :recycle: mocks -> avatax-mock-transaction-factory & fix tests * feat: add tests for taxjar (#509) * fix: :truck: tax-provider-utils.test name * feat: :white_check_mark: add nexus tests & other taxjar tests * feat: :goal_net: add ExpectedError and use it in webhook-response * refactor: :white_check_mark: unify taxjar-calculate-taxes tests with mock-generator * feat: :white_check_mark: add TaxJarOrderCreatedMockGenerator * feat: :white_check_mark: add avatax-calculate-taxes-mock-generator * feat: :white_check_mark: add AvataxOrderCreatedMockGenerator * refactor: :fire: tax-mock-factory * fix: :bug: housekeeping * fix: :bug: feedback * feat: :white_check_mark: add taxBase with discounts test * fix: :bug: address feedback * refactor: :fire: unused avatax-mock-factory functions * feat: :sparkles: use discount utils in all providers * feat: :sparkles: differentiate between pricesEnteredWithTax in taxjar
2023-05-29 08:35:34 +00:00
return webhookResponse.error(error);
}
});