@unchainedshop/plugins 5.0.0-alpha.1 → 5.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/lib/events/aws-eventbridge.d.ts +7 -1
  2. package/lib/events/aws-eventbridge.js +5 -11
  3. package/lib/events/redis.d.ts +3 -1
  4. package/lib/events/redis.js +5 -5
  5. package/lib/files/gridfs/api.js +1 -1
  6. package/lib/files/gridfs/handler-express.js +1 -1
  7. package/lib/filters/local-search/index.js +0 -6
  8. package/lib/filters/local-search.js +1 -9
  9. package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts +1 -1
  10. package/lib/payment/cryptopay/db/CryptopayTransactions.js +8 -3
  11. package/lib/payment/cryptopay/module.d.ts +5 -5
  12. package/lib/payment/cryptopay/module.js +2 -2
  13. package/lib/payment/datatrans-v2/adapter.js +12 -9
  14. package/lib/payment/datatrans-v2/build3DSCardholder.d.ts +12 -0
  15. package/lib/payment/datatrans-v2/build3DSCardholder.js +44 -0
  16. package/lib/payment/paypal-checkout.js +17 -5
  17. package/lib/payment/payrexx/payrexx.js +4 -4
  18. package/lib/payment/stripe/stripe.js +1 -1
  19. package/lib/presets/base.js +4 -0
  20. package/lib/presets/countries/eu.d.ts +1 -0
  21. package/lib/presets/countries/eu.js +7 -0
  22. package/lib/presets/countries/uk.d.ts +1 -0
  23. package/lib/presets/countries/uk.js +7 -0
  24. package/lib/presets/countries/us.d.ts +1 -0
  25. package/lib/presets/countries/us.js +7 -0
  26. package/lib/pricing/delivery-eu-tax/adapter.d.ts +3 -0
  27. package/lib/pricing/delivery-eu-tax/adapter.js +55 -0
  28. package/lib/pricing/delivery-eu-tax/index.d.ts +4 -0
  29. package/lib/pricing/delivery-eu-tax/index.js +10 -0
  30. package/lib/pricing/delivery-eu-tax.d.ts +2 -0
  31. package/lib/pricing/delivery-eu-tax.js +55 -0
  32. package/lib/pricing/delivery-swiss-tax/adapter.js +7 -26
  33. package/lib/pricing/delivery-swiss-tax.js +7 -26
  34. package/lib/pricing/delivery-uk-tax/adapter.d.ts +3 -0
  35. package/lib/pricing/delivery-uk-tax/adapter.js +43 -0
  36. package/lib/pricing/delivery-uk-tax/index.d.ts +4 -0
  37. package/lib/pricing/delivery-uk-tax/index.js +10 -0
  38. package/lib/pricing/delivery-uk-tax.d.ts +2 -0
  39. package/lib/pricing/delivery-uk-tax.js +43 -0
  40. package/lib/pricing/delivery-us-sales-tax/adapter.d.ts +3 -0
  41. package/lib/pricing/delivery-us-sales-tax/adapter.js +58 -0
  42. package/lib/pricing/delivery-us-sales-tax/index.d.ts +4 -0
  43. package/lib/pricing/delivery-us-sales-tax/index.js +10 -0
  44. package/lib/pricing/delivery-us-sales-tax.d.ts +2 -0
  45. package/lib/pricing/delivery-us-sales-tax.js +58 -0
  46. package/lib/pricing/product-eu-tax/adapter.d.ts +3 -0
  47. package/lib/pricing/product-eu-tax/adapter.js +56 -0
  48. package/lib/pricing/product-eu-tax/index.d.ts +4 -0
  49. package/lib/pricing/product-eu-tax/index.js +10 -0
  50. package/lib/pricing/product-eu-tax.d.ts +2 -0
  51. package/lib/pricing/product-eu-tax.js +56 -0
  52. package/lib/pricing/product-quotation-price.d.ts +2 -0
  53. package/lib/pricing/product-quotation-price.js +40 -0
  54. package/lib/pricing/product-swiss-tax/adapter.js +7 -26
  55. package/lib/pricing/product-swiss-tax.js +7 -26
  56. package/lib/pricing/product-uk-tax/adapter.d.ts +3 -0
  57. package/lib/pricing/product-uk-tax/adapter.js +57 -0
  58. package/lib/pricing/product-uk-tax/index.d.ts +4 -0
  59. package/lib/pricing/product-uk-tax/index.js +10 -0
  60. package/lib/pricing/product-uk-tax.d.ts +2 -0
  61. package/lib/pricing/product-uk-tax.js +57 -0
  62. package/lib/pricing/product-us-sales-tax/adapter.d.ts +3 -0
  63. package/lib/pricing/product-us-sales-tax/adapter.js +52 -0
  64. package/lib/pricing/product-us-sales-tax/index.d.ts +4 -0
  65. package/lib/pricing/product-us-sales-tax/index.js +10 -0
  66. package/lib/pricing/product-us-sales-tax.d.ts +2 -0
  67. package/lib/pricing/product-us-sales-tax.js +52 -0
  68. package/lib/pricing/tax/applyTaxRateToTaxableRows.d.ts +23 -0
  69. package/lib/pricing/tax/applyTaxRateToTaxableRows.js +30 -0
  70. package/lib/pricing/tax/ch-tax-rates.json +24 -0
  71. package/lib/pricing/tax/ch.js +6 -30
  72. package/lib/pricing/tax/eraRates.d.ts +10 -0
  73. package/lib/pricing/tax/eraRates.js +15 -0
  74. package/lib/pricing/tax/eu-tax-rates.json +797 -0
  75. package/lib/pricing/tax/eu.d.ts +12 -0
  76. package/lib/pricing/tax/eu.js +38 -0
  77. package/lib/pricing/tax/uk-tax-rates.json +18 -0
  78. package/lib/pricing/tax/uk.d.ts +10 -0
  79. package/lib/pricing/tax/uk.js +23 -0
  80. package/lib/pricing/tax/us-tax-rates.json +334 -0
  81. package/lib/pricing/tax/us.d.ts +11 -0
  82. package/lib/pricing/tax/us.js +20 -0
  83. package/lib/pricing/utils/isDeliveryAddressInCountry.d.ts +1 -1
  84. package/lib/pricing/utils/isDeliveryAddressInCountry.js +3 -8
  85. package/lib/pricing/utils/resolveDeliveryLocation.d.ts +10 -0
  86. package/lib/pricing/utils/resolveDeliveryLocation.js +9 -0
  87. package/lib/quotations/manual/adapter.js +6 -1
  88. package/lib/quotations/manual.js +6 -1
  89. package/lib/worker/gc-guests/adapter.d.ts +9 -0
  90. package/lib/worker/gc-guests/adapter.js +56 -0
  91. package/lib/worker/gc-guests/index.d.ts +4 -0
  92. package/lib/worker/gc-guests/index.js +13 -0
  93. package/lib/worker/gc-guests.d.ts +8 -0
  94. package/lib/worker/gc-guests.js +55 -0
  95. package/lib/worker/invalidate-carts/adapter.d.ts +9 -0
  96. package/lib/worker/invalidate-carts/adapter.js +52 -0
  97. package/lib/worker/invalidate-carts/index.d.ts +4 -0
  98. package/lib/worker/invalidate-carts/index.js +13 -0
  99. package/lib/worker/invalidate-carts.d.ts +8 -0
  100. package/lib/worker/invalidate-carts.js +51 -0
  101. package/lib/worker/zombie-killer/adapter.d.ts +2 -0
  102. package/lib/worker/zombie-killer/adapter.js +26 -3
  103. package/lib/worker/zombie-killer/index.js +4 -1
  104. package/lib/worker/zombie-killer.d.ts +1 -0
  105. package/lib/worker/zombie-killer.js +24 -3
  106. package/package.json +25 -8
@@ -1,6 +1,7 @@
1
1
  import { DeliveryPricingRowCategory, DeliveryPricingAdapter, DeliveryPricingDirector, } from '@unchainedshop/core';
2
2
  import { resolveTaxCategoryFromDeliveryProvider, SwissTaxCategories } from "./tax/ch.js";
3
3
  import isDeliveryAddressInCountry from "./utils/isDeliveryAddressInCountry.js";
4
+ import { applyTaxRateToTaxableRows } from "./tax/applyTaxRateToTaxableRows.js";
4
5
  export const DeliverySwissTax = {
5
6
  ...DeliveryPricingAdapter,
6
7
  key: 'shop.unchained.pricing.delivery-swiss-tax',
@@ -27,32 +28,12 @@ export const DeliverySwissTax = {
27
28
  const taxCategory = resolveTaxCategoryFromDeliveryProvider(context.provider) || SwissTaxCategories.DEFAULT;
28
29
  const taxRate = taxCategory.rate(context.order?.ordered);
29
30
  DeliveryPricingAdapter.log(`DeliverySwissTax -> Tax Multiplicator: ${taxRate}`);
30
- params.calculationSheet.filterBy({ isTaxable: true }).forEach(({ isNetPrice, ...row }) => {
31
- if (!isNetPrice) {
32
- const taxAmount = row.amount - row.amount / (1 + taxRate);
33
- pricingAdapter.resultSheet().calculation.push({
34
- ...row,
35
- amount: -taxAmount,
36
- isTaxable: false,
37
- isNetPrice: false,
38
- meta: { adapter: DeliverySwissTax.key },
39
- });
40
- pricingAdapter.resultSheet().addTax({
41
- amount: taxAmount,
42
- rate: taxRate,
43
- baseCategory: DeliveryPricingRowCategory.Delivery,
44
- meta: { adapter: DeliverySwissTax.key },
45
- });
46
- }
47
- else {
48
- const taxAmount = row.amount * taxRate;
49
- pricingAdapter.resultSheet().addTax({
50
- amount: taxAmount,
51
- rate: taxRate,
52
- baseCategory: DeliveryPricingRowCategory.Delivery,
53
- meta: { adapter: DeliverySwissTax.key },
54
- });
55
- }
31
+ applyTaxRateToTaxableRows({
32
+ calculationSheet: params.calculationSheet,
33
+ resultSheet: pricingAdapter.resultSheet(),
34
+ taxRate,
35
+ baseCategory: DeliveryPricingRowCategory.Delivery,
36
+ adapterKey: DeliverySwissTax.key,
56
37
  });
57
38
  return pricingAdapter.calculate();
58
39
  },
@@ -0,0 +1,3 @@
1
+ import { type IDeliveryPricingAdapter } from '@unchainedshop/core';
2
+ export declare const DeliveryUkTax: IDeliveryPricingAdapter;
3
+ export default DeliveryUkTax;
@@ -0,0 +1,43 @@
1
+ import { DeliveryPricingRowCategory, DeliveryPricingAdapter, } from '@unchainedshop/core';
2
+ import { resolveUkTaxCategoryFromDeliveryProvider, UkTaxCategories, UK_VAT_COUNTRY_CODES, } from "../tax/uk.js";
3
+ import isDeliveryAddressInCountry from "../utils/isDeliveryAddressInCountry.js";
4
+ import { applyTaxRateToTaxableRows } from "../tax/applyTaxRateToTaxableRows.js";
5
+ export const DeliveryUkTax = {
6
+ ...DeliveryPricingAdapter,
7
+ key: 'shop.unchained.pricing.delivery-uk-tax',
8
+ version: '1.0.0',
9
+ label: 'Apply UK VAT on Delivery Fees',
10
+ orderIndex: 80,
11
+ isActivatedFor: (context) => {
12
+ if (!context.order)
13
+ return false;
14
+ if (!context.orderDelivery)
15
+ return false;
16
+ return isDeliveryAddressInCountry({
17
+ order: context.order,
18
+ orderDelivery: context.orderDelivery,
19
+ countryCode: context.countryCode,
20
+ }, UK_VAT_COUNTRY_CODES);
21
+ },
22
+ actions: (params) => {
23
+ const pricingAdapter = DeliveryPricingAdapter.actions(params);
24
+ const { context } = params;
25
+ return {
26
+ ...pricingAdapter,
27
+ calculate: async () => {
28
+ const taxCategory = resolveUkTaxCategoryFromDeliveryProvider(context.provider) || UkTaxCategories.STANDARD;
29
+ const taxRate = taxCategory.rate(context.order?.ordered);
30
+ DeliveryPricingAdapter.log(`DeliveryUkTax -> Tax Multiplicator: ${taxRate}`);
31
+ applyTaxRateToTaxableRows({
32
+ calculationSheet: params.calculationSheet,
33
+ resultSheet: pricingAdapter.resultSheet(),
34
+ taxRate,
35
+ baseCategory: DeliveryPricingRowCategory.Delivery,
36
+ adapterKey: DeliveryUkTax.key,
37
+ });
38
+ return pricingAdapter.calculate();
39
+ },
40
+ };
41
+ },
42
+ };
43
+ export default DeliveryUkTax;
@@ -0,0 +1,4 @@
1
+ import { type IPlugin } from '@unchainedshop/core';
2
+ export declare const DeliveryUkTaxPlugin: IPlugin;
3
+ export default DeliveryUkTaxPlugin;
4
+ export { DeliveryUkTax } from './adapter.ts';
@@ -0,0 +1,10 @@
1
+ import {} from '@unchainedshop/core';
2
+ import { DeliveryUkTax } from "./adapter.js";
3
+ export const DeliveryUkTaxPlugin = {
4
+ key: 'shop.unchained.pricing.delivery-uk-tax',
5
+ label: 'Delivery UK Tax Plugin',
6
+ version: '1.0.0',
7
+ adapters: [DeliveryUkTax],
8
+ };
9
+ export default DeliveryUkTaxPlugin;
10
+ export { DeliveryUkTax } from "./adapter.js";
@@ -0,0 +1,2 @@
1
+ import { type IDeliveryPricingAdapter } from '@unchainedshop/core';
2
+ export declare const DeliveryUkTax: IDeliveryPricingAdapter;
@@ -0,0 +1,43 @@
1
+ import { DeliveryPricingRowCategory, DeliveryPricingAdapter, DeliveryPricingDirector, } from '@unchainedshop/core';
2
+ import { resolveUkTaxCategoryFromDeliveryProvider, UkTaxCategories, UK_VAT_COUNTRY_CODES, } from "./tax/uk.js";
3
+ import isDeliveryAddressInCountry from "./utils/isDeliveryAddressInCountry.js";
4
+ import { applyTaxRateToTaxableRows } from "./tax/applyTaxRateToTaxableRows.js";
5
+ export const DeliveryUkTax = {
6
+ ...DeliveryPricingAdapter,
7
+ key: 'shop.unchained.pricing.delivery-uk-tax',
8
+ version: '1.0.0',
9
+ label: 'Apply UK VAT on Delivery Fees',
10
+ orderIndex: 80,
11
+ isActivatedFor: (context) => {
12
+ if (!context.order)
13
+ return false;
14
+ if (!context.orderDelivery)
15
+ return false;
16
+ return isDeliveryAddressInCountry({
17
+ order: context.order,
18
+ orderDelivery: context.orderDelivery,
19
+ countryCode: context.countryCode,
20
+ }, UK_VAT_COUNTRY_CODES);
21
+ },
22
+ actions: (params) => {
23
+ const pricingAdapter = DeliveryPricingAdapter.actions(params);
24
+ const { context } = params;
25
+ return {
26
+ ...pricingAdapter,
27
+ calculate: async () => {
28
+ const taxCategory = resolveUkTaxCategoryFromDeliveryProvider(context.provider) || UkTaxCategories.STANDARD;
29
+ const taxRate = taxCategory.rate(context.order?.ordered);
30
+ DeliveryPricingAdapter.log(`DeliveryUkTax -> Tax Multiplicator: ${taxRate}`);
31
+ applyTaxRateToTaxableRows({
32
+ calculationSheet: params.calculationSheet,
33
+ resultSheet: pricingAdapter.resultSheet(),
34
+ taxRate,
35
+ baseCategory: DeliveryPricingRowCategory.Delivery,
36
+ adapterKey: DeliveryUkTax.key,
37
+ });
38
+ return pricingAdapter.calculate();
39
+ },
40
+ };
41
+ },
42
+ };
43
+ DeliveryPricingDirector.registerAdapter(DeliveryUkTax);
@@ -0,0 +1,3 @@
1
+ import { type IDeliveryPricingAdapter } from '@unchainedshop/core';
2
+ export declare const DeliveryUsSalesTax: IDeliveryPricingAdapter;
3
+ export default DeliveryUsSalesTax;
@@ -0,0 +1,58 @@
1
+ import { DeliveryPricingRowCategory, DeliveryPricingAdapter, } from '@unchainedshop/core';
2
+ import { US_COUNTRY_CODE, isDeliveryExemptFromUsSalesTax, resolveUsSalesTaxRate } from "../tax/us.js";
3
+ import resolveDeliveryLocation from "../utils/resolveDeliveryLocation.js";
4
+ import { applyTaxRateToTaxableRows } from "../tax/applyTaxRateToTaxableRows.js";
5
+ export const DeliveryUsSalesTax = {
6
+ ...DeliveryPricingAdapter,
7
+ key: 'shop.unchained.pricing.delivery-us-sales-tax',
8
+ version: '1.0.0',
9
+ label: 'Apply US State Sales Tax on Delivery Fees',
10
+ orderIndex: 80,
11
+ isActivatedFor: (context) => {
12
+ if (!context.order)
13
+ return false;
14
+ if (!context.orderDelivery)
15
+ return false;
16
+ const { countryCode } = resolveDeliveryLocation({
17
+ order: context.order,
18
+ orderDelivery: context.orderDelivery,
19
+ countryCode: context.countryCode,
20
+ });
21
+ return countryCode === US_COUNTRY_CODE;
22
+ },
23
+ actions: (params) => {
24
+ const pricingAdapter = DeliveryPricingAdapter.actions(params);
25
+ const { context } = params;
26
+ return {
27
+ ...pricingAdapter,
28
+ calculate: async () => {
29
+ if (isDeliveryExemptFromUsSalesTax(context.provider)) {
30
+ return pricingAdapter.calculate();
31
+ }
32
+ const { regionCode } = resolveDeliveryLocation({
33
+ order: context.order,
34
+ orderDelivery: context.orderDelivery,
35
+ countryCode: context.countryCode,
36
+ });
37
+ const taxRate = resolveUsSalesTaxRate({
38
+ regionCode,
39
+ referenceDate: context.order?.ordered,
40
+ });
41
+ if (taxRate === null) {
42
+ DeliveryPricingAdapter.log(`DeliveryUsSalesTax -> unknown state '${regionCode}', no sales tax applied`);
43
+ return pricingAdapter.calculate();
44
+ }
45
+ DeliveryPricingAdapter.log(`DeliveryUsSalesTax -> Tax Multiplicator: ${taxRate}`);
46
+ applyTaxRateToTaxableRows({
47
+ calculationSheet: params.calculationSheet,
48
+ resultSheet: pricingAdapter.resultSheet(),
49
+ taxRate,
50
+ baseCategory: DeliveryPricingRowCategory.Delivery,
51
+ adapterKey: DeliveryUsSalesTax.key,
52
+ });
53
+ return pricingAdapter.calculate();
54
+ },
55
+ };
56
+ },
57
+ };
58
+ export default DeliveryUsSalesTax;
@@ -0,0 +1,4 @@
1
+ import { type IPlugin } from '@unchainedshop/core';
2
+ export declare const DeliveryUsSalesTaxPlugin: IPlugin;
3
+ export default DeliveryUsSalesTaxPlugin;
4
+ export { DeliveryUsSalesTax } from './adapter.ts';
@@ -0,0 +1,10 @@
1
+ import {} from '@unchainedshop/core';
2
+ import { DeliveryUsSalesTax } from "./adapter.js";
3
+ export const DeliveryUsSalesTaxPlugin = {
4
+ key: 'shop.unchained.pricing.delivery-us-sales-tax',
5
+ label: 'Delivery US Sales Tax Plugin',
6
+ version: '1.0.0',
7
+ adapters: [DeliveryUsSalesTax],
8
+ };
9
+ export default DeliveryUsSalesTaxPlugin;
10
+ export { DeliveryUsSalesTax } from "./adapter.js";
@@ -0,0 +1,2 @@
1
+ import { type IDeliveryPricingAdapter } from '@unchainedshop/core';
2
+ export declare const DeliveryUsSalesTax: IDeliveryPricingAdapter;
@@ -0,0 +1,58 @@
1
+ import { DeliveryPricingRowCategory, DeliveryPricingAdapter, DeliveryPricingDirector, } from '@unchainedshop/core';
2
+ import { US_COUNTRY_CODE, isDeliveryExemptFromUsSalesTax, resolveUsSalesTaxRate } from "./tax/us.js";
3
+ import resolveDeliveryLocation from "./utils/resolveDeliveryLocation.js";
4
+ import { applyTaxRateToTaxableRows } from "./tax/applyTaxRateToTaxableRows.js";
5
+ export const DeliveryUsSalesTax = {
6
+ ...DeliveryPricingAdapter,
7
+ key: 'shop.unchained.pricing.delivery-us-sales-tax',
8
+ version: '1.0.0',
9
+ label: 'Apply US State Sales Tax on Delivery Fees',
10
+ orderIndex: 80,
11
+ isActivatedFor: (context) => {
12
+ if (!context.order)
13
+ return false;
14
+ if (!context.orderDelivery)
15
+ return false;
16
+ const { countryCode } = resolveDeliveryLocation({
17
+ order: context.order,
18
+ orderDelivery: context.orderDelivery,
19
+ countryCode: context.countryCode,
20
+ });
21
+ return countryCode === US_COUNTRY_CODE;
22
+ },
23
+ actions: (params) => {
24
+ const pricingAdapter = DeliveryPricingAdapter.actions(params);
25
+ const { context } = params;
26
+ return {
27
+ ...pricingAdapter,
28
+ calculate: async () => {
29
+ if (isDeliveryExemptFromUsSalesTax(context.provider)) {
30
+ return pricingAdapter.calculate();
31
+ }
32
+ const { regionCode } = resolveDeliveryLocation({
33
+ order: context.order,
34
+ orderDelivery: context.orderDelivery,
35
+ countryCode: context.countryCode,
36
+ });
37
+ const taxRate = resolveUsSalesTaxRate({
38
+ regionCode,
39
+ referenceDate: context.order?.ordered,
40
+ });
41
+ if (taxRate === null) {
42
+ DeliveryPricingAdapter.log(`DeliveryUsSalesTax -> unknown state '${regionCode}', no sales tax applied`);
43
+ return pricingAdapter.calculate();
44
+ }
45
+ DeliveryPricingAdapter.log(`DeliveryUsSalesTax -> Tax Multiplicator: ${taxRate}`);
46
+ applyTaxRateToTaxableRows({
47
+ calculationSheet: params.calculationSheet,
48
+ resultSheet: pricingAdapter.resultSheet(),
49
+ taxRate,
50
+ baseCategory: DeliveryPricingRowCategory.Delivery,
51
+ adapterKey: DeliveryUsSalesTax.key,
52
+ });
53
+ return pricingAdapter.calculate();
54
+ },
55
+ };
56
+ },
57
+ };
58
+ DeliveryPricingDirector.registerAdapter(DeliveryUsSalesTax);
@@ -0,0 +1,3 @@
1
+ import { type IProductPricingAdapter } from '@unchainedshop/core';
2
+ export declare const ProductEuTax: IProductPricingAdapter;
3
+ export default ProductEuTax;
@@ -0,0 +1,56 @@
1
+ import { ProductPricingAdapter, ProductPricingRowCategory, } from '@unchainedshop/core';
2
+ import { resolveEuTaxCategoryFromDeliveryProvider, resolveEuTaxCategoryFromProduct, resolveEuTaxRate, } from "../tax/eu.js";
3
+ import resolveDeliveryLocation from "../utils/resolveDeliveryLocation.js";
4
+ import { applyTaxRateToTaxableRows } from "../tax/applyTaxRateToTaxableRows.js";
5
+ export const ProductEuTax = {
6
+ ...ProductPricingAdapter,
7
+ key: 'shop.unchained.pricing.product-eu-tax',
8
+ version: '1.0.0',
9
+ label: 'Apply EU VAT on Product',
10
+ orderIndex: 80,
11
+ isActivatedFor: () => {
12
+ return true;
13
+ },
14
+ actions: (params) => {
15
+ const pricingAdapter = ProductPricingAdapter.actions(params);
16
+ const { context } = params;
17
+ return {
18
+ ...pricingAdapter,
19
+ calculate: async () => {
20
+ const orderDelivery = context.order?.deliveryId
21
+ ? await context.modules.orders.deliveries.findDelivery({
22
+ orderDeliveryId: context.order?.deliveryId,
23
+ })
24
+ : null;
25
+ const { countryCode } = resolveDeliveryLocation({ ...context, orderDelivery });
26
+ let category = resolveEuTaxCategoryFromProduct(context.product);
27
+ if (!category) {
28
+ const provider = orderDelivery?.deliveryProviderId
29
+ ? await context.modules.delivery.findProvider({
30
+ deliveryProviderId: orderDelivery?.deliveryProviderId,
31
+ })
32
+ : null;
33
+ if (provider)
34
+ category = resolveEuTaxCategoryFromDeliveryProvider(provider);
35
+ }
36
+ const taxRate = resolveEuTaxRate({
37
+ countryCode,
38
+ category,
39
+ referenceDate: context.order?.ordered,
40
+ });
41
+ if (taxRate === null)
42
+ return pricingAdapter.calculate();
43
+ ProductPricingAdapter.log(`ProductEuTax -> Tax Multiplicator: ${taxRate}`);
44
+ applyTaxRateToTaxableRows({
45
+ calculationSheet: params.calculationSheet,
46
+ resultSheet: pricingAdapter.resultSheet(),
47
+ taxRate,
48
+ baseCategory: ProductPricingRowCategory.Item,
49
+ adapterKey: ProductEuTax.key,
50
+ });
51
+ return pricingAdapter.calculate();
52
+ },
53
+ };
54
+ },
55
+ };
56
+ export default ProductEuTax;
@@ -0,0 +1,4 @@
1
+ import { type IPlugin } from '@unchainedshop/core';
2
+ export declare const ProductEuTaxPlugin: IPlugin;
3
+ export default ProductEuTaxPlugin;
4
+ export { ProductEuTax } from './adapter.ts';
@@ -0,0 +1,10 @@
1
+ import {} from '@unchainedshop/core';
2
+ import { ProductEuTax } from "./adapter.js";
3
+ export const ProductEuTaxPlugin = {
4
+ key: 'shop.unchained.pricing.product-eu-tax',
5
+ label: 'Product EU Tax Plugin',
6
+ version: '1.0.0',
7
+ adapters: [ProductEuTax],
8
+ };
9
+ export default ProductEuTaxPlugin;
10
+ export { ProductEuTax } from "./adapter.js";
@@ -0,0 +1,2 @@
1
+ import { type IProductPricingAdapter } from '@unchainedshop/core';
2
+ export declare const ProductEuTax: IProductPricingAdapter;
@@ -0,0 +1,56 @@
1
+ import { ProductPricingDirector, ProductPricingAdapter, ProductPricingRowCategory, } from '@unchainedshop/core';
2
+ import { resolveEuTaxCategoryFromDeliveryProvider, resolveEuTaxCategoryFromProduct, resolveEuTaxRate, } from "./tax/eu.js";
3
+ import resolveDeliveryLocation from "./utils/resolveDeliveryLocation.js";
4
+ import { applyTaxRateToTaxableRows } from "./tax/applyTaxRateToTaxableRows.js";
5
+ export const ProductEuTax = {
6
+ ...ProductPricingAdapter,
7
+ key: 'shop.unchained.pricing.product-eu-tax',
8
+ version: '1.0.0',
9
+ label: 'Apply EU VAT on Product',
10
+ orderIndex: 80,
11
+ isActivatedFor: () => {
12
+ return true;
13
+ },
14
+ actions: (params) => {
15
+ const pricingAdapter = ProductPricingAdapter.actions(params);
16
+ const { context } = params;
17
+ return {
18
+ ...pricingAdapter,
19
+ calculate: async () => {
20
+ const orderDelivery = context.order?.deliveryId
21
+ ? await context.modules.orders.deliveries.findDelivery({
22
+ orderDeliveryId: context.order?.deliveryId,
23
+ })
24
+ : null;
25
+ const { countryCode } = resolveDeliveryLocation({ ...context, orderDelivery });
26
+ let category = resolveEuTaxCategoryFromProduct(context.product);
27
+ if (!category) {
28
+ const provider = orderDelivery?.deliveryProviderId
29
+ ? await context.modules.delivery.findProvider({
30
+ deliveryProviderId: orderDelivery?.deliveryProviderId,
31
+ })
32
+ : null;
33
+ if (provider)
34
+ category = resolveEuTaxCategoryFromDeliveryProvider(provider);
35
+ }
36
+ const taxRate = resolveEuTaxRate({
37
+ countryCode,
38
+ category,
39
+ referenceDate: context.order?.ordered,
40
+ });
41
+ if (taxRate === null)
42
+ return pricingAdapter.calculate();
43
+ ProductPricingAdapter.log(`ProductEuTax -> Tax Multiplicator: ${taxRate}`);
44
+ applyTaxRateToTaxableRows({
45
+ calculationSheet: params.calculationSheet,
46
+ resultSheet: pricingAdapter.resultSheet(),
47
+ taxRate,
48
+ baseCategory: ProductPricingRowCategory.Item,
49
+ adapterKey: ProductEuTax.key,
50
+ });
51
+ return pricingAdapter.calculate();
52
+ },
53
+ };
54
+ },
55
+ };
56
+ ProductPricingDirector.registerAdapter(ProductEuTax);
@@ -0,0 +1,2 @@
1
+ import { type IProductPricingAdapter } from '@unchainedshop/core';
2
+ export declare const ProductQuotationPrice: IProductPricingAdapter;
@@ -0,0 +1,40 @@
1
+ import { ProductPricingDirector, ProductPricingAdapter, } from '@unchainedshop/core';
2
+ export const ProductQuotationPrice = {
3
+ ...ProductPricingAdapter,
4
+ key: 'shop.unchained.pricing.quotation-price',
5
+ version: '1.0.0',
6
+ label: 'Apply negotiated quotation price',
7
+ orderIndex: 20,
8
+ isActivatedFor: (context) => {
9
+ return Boolean(context.quotationId);
10
+ },
11
+ actions: (params) => {
12
+ const pricingAdapter = ProductPricingAdapter.actions(params);
13
+ return {
14
+ ...pricingAdapter,
15
+ calculate: async () => {
16
+ const { quotationId, currencyCode, quantity, modules } = params.context;
17
+ const quotation = await modules.quotations.findQuotation({ quotationId: quotationId });
18
+ const isApplicable = quotation &&
19
+ quotation.price != null &&
20
+ quotation.currencyCode === currencyCode &&
21
+ (modules.quotations.isProposalValid(quotation) ||
22
+ modules.quotations.normalizedStatus(quotation) === 'FULFILLED');
23
+ if (isApplicable) {
24
+ const negotiatedTotal = Math.round(quotation.price) * quantity;
25
+ const correction = negotiatedTotal - params.calculationSheet.sum();
26
+ if (correction !== 0) {
27
+ pricingAdapter.resultSheet().addItem({
28
+ amount: correction,
29
+ isTaxable: false,
30
+ isNetPrice: false,
31
+ meta: { adapter: ProductQuotationPrice.key, quotationId: quotation._id },
32
+ });
33
+ }
34
+ }
35
+ return pricingAdapter.calculate();
36
+ },
37
+ };
38
+ },
39
+ };
40
+ ProductPricingDirector.registerAdapter(ProductQuotationPrice);
@@ -1,6 +1,7 @@
1
1
  import { ProductPricingAdapter, ProductPricingRowCategory, } from '@unchainedshop/core';
2
2
  import { resolveTaxCategoryFromDeliveryProvider, resolveTaxCategoryFromProduct, SwissTaxCategories, } from "../tax/ch.js";
3
3
  import isDeliveryAddressInCountry from "../utils/isDeliveryAddressInCountry.js";
4
+ import { applyTaxRateToTaxableRows } from "../tax/applyTaxRateToTaxableRows.js";
4
5
  export const ProductSwissTax = {
5
6
  ...ProductPricingAdapter,
6
7
  key: 'shop.unchained.pricing.product-swiss-tax',
@@ -41,32 +42,12 @@ export const ProductSwissTax = {
41
42
  taxCategory = SwissTaxCategories.DEFAULT;
42
43
  const taxRate = taxCategory.rate(context.order?.ordered);
43
44
  ProductPricingAdapter.log(`ProductSwissTax -> Tax Multiplicator: ${taxRate}`);
44
- params.calculationSheet.filterBy({ isTaxable: true }).forEach(({ isNetPrice, ...row }) => {
45
- if (!isNetPrice) {
46
- const taxAmount = row.amount - row.amount / (1 + taxRate);
47
- pricingAdapter.resultSheet().calculation.push({
48
- ...row,
49
- amount: -taxAmount,
50
- isTaxable: false,
51
- isNetPrice: false,
52
- meta: { adapter: ProductSwissTax.key },
53
- });
54
- pricingAdapter.resultSheet().addTax({
55
- amount: taxAmount,
56
- rate: taxRate,
57
- baseCategory: ProductPricingRowCategory.Item,
58
- meta: { adapter: ProductSwissTax.key },
59
- });
60
- }
61
- else {
62
- const taxAmount = row.amount * taxRate;
63
- pricingAdapter.resultSheet().addTax({
64
- amount: taxAmount,
65
- rate: taxRate,
66
- baseCategory: ProductPricingRowCategory.Item,
67
- meta: { adapter: ProductSwissTax.key },
68
- });
69
- }
45
+ applyTaxRateToTaxableRows({
46
+ calculationSheet: params.calculationSheet,
47
+ resultSheet: pricingAdapter.resultSheet(),
48
+ taxRate,
49
+ baseCategory: ProductPricingRowCategory.Item,
50
+ adapterKey: ProductSwissTax.key,
70
51
  });
71
52
  return pricingAdapter.calculate();
72
53
  },
@@ -1,6 +1,7 @@
1
1
  import { ProductPricingDirector, ProductPricingAdapter, ProductPricingRowCategory, } from '@unchainedshop/core';
2
2
  import { resolveTaxCategoryFromDeliveryProvider, resolveTaxCategoryFromProduct, SwissTaxCategories, } from "./tax/ch.js";
3
3
  import isDeliveryAddressInCountry from "./utils/isDeliveryAddressInCountry.js";
4
+ import { applyTaxRateToTaxableRows } from "./tax/applyTaxRateToTaxableRows.js";
4
5
  export const ProductSwissTax = {
5
6
  ...ProductPricingAdapter,
6
7
  key: 'shop.unchained.pricing.product-swiss-tax',
@@ -41,32 +42,12 @@ export const ProductSwissTax = {
41
42
  taxCategory = SwissTaxCategories.DEFAULT;
42
43
  const taxRate = taxCategory.rate(context.order?.ordered);
43
44
  ProductPricingAdapter.log(`ProductSwissTax -> Tax Multiplicator: ${taxRate}`);
44
- params.calculationSheet.filterBy({ isTaxable: true }).forEach(({ isNetPrice, ...row }) => {
45
- if (!isNetPrice) {
46
- const taxAmount = row.amount - row.amount / (1 + taxRate);
47
- pricingAdapter.resultSheet().calculation.push({
48
- ...row,
49
- amount: -taxAmount,
50
- isTaxable: false,
51
- isNetPrice: false,
52
- meta: { adapter: ProductSwissTax.key },
53
- });
54
- pricingAdapter.resultSheet().addTax({
55
- amount: taxAmount,
56
- rate: taxRate,
57
- baseCategory: ProductPricingRowCategory.Item,
58
- meta: { adapter: ProductSwissTax.key },
59
- });
60
- }
61
- else {
62
- const taxAmount = row.amount * taxRate;
63
- pricingAdapter.resultSheet().addTax({
64
- amount: taxAmount,
65
- rate: taxRate,
66
- baseCategory: ProductPricingRowCategory.Item,
67
- meta: { adapter: ProductSwissTax.key },
68
- });
69
- }
45
+ applyTaxRateToTaxableRows({
46
+ calculationSheet: params.calculationSheet,
47
+ resultSheet: pricingAdapter.resultSheet(),
48
+ taxRate,
49
+ baseCategory: ProductPricingRowCategory.Item,
50
+ adapterKey: ProductSwissTax.key,
70
51
  });
71
52
  return pricingAdapter.calculate();
72
53
  },
@@ -0,0 +1,3 @@
1
+ import { type IProductPricingAdapter } from '@unchainedshop/core';
2
+ export declare const ProductUkTax: IProductPricingAdapter;
3
+ export default ProductUkTax;
@@ -0,0 +1,57 @@
1
+ import { ProductPricingAdapter, ProductPricingRowCategory, } from '@unchainedshop/core';
2
+ import { resolveUkTaxCategoryFromDeliveryProvider, resolveUkTaxCategoryFromProduct, UkTaxCategories, UK_VAT_COUNTRY_CODES, } from "../tax/uk.js";
3
+ import isDeliveryAddressInCountry from "../utils/isDeliveryAddressInCountry.js";
4
+ import { applyTaxRateToTaxableRows } from "../tax/applyTaxRateToTaxableRows.js";
5
+ export const ProductUkTax = {
6
+ ...ProductPricingAdapter,
7
+ key: 'shop.unchained.pricing.product-uk-tax',
8
+ version: '1.0.0',
9
+ label: 'Apply UK VAT on Product',
10
+ orderIndex: 80,
11
+ isActivatedFor: () => {
12
+ return true;
13
+ },
14
+ actions: (params) => {
15
+ const pricingAdapter = ProductPricingAdapter.actions(params);
16
+ const { context } = params;
17
+ return {
18
+ ...pricingAdapter,
19
+ calculate: async () => {
20
+ const orderDelivery = context.order?.deliveryId
21
+ ? await context.modules.orders.deliveries.findDelivery({
22
+ orderDeliveryId: context.order?.deliveryId,
23
+ })
24
+ : null;
25
+ if (!isDeliveryAddressInCountry({
26
+ ...context,
27
+ orderDelivery,
28
+ }, UK_VAT_COUNTRY_CODES)) {
29
+ return pricingAdapter.calculate();
30
+ }
31
+ let taxCategory = resolveUkTaxCategoryFromProduct(context.product);
32
+ if (!taxCategory) {
33
+ const provider = orderDelivery?.deliveryProviderId
34
+ ? await context.modules.delivery.findProvider({
35
+ deliveryProviderId: orderDelivery?.deliveryProviderId,
36
+ })
37
+ : null;
38
+ if (provider)
39
+ taxCategory = resolveUkTaxCategoryFromDeliveryProvider(provider);
40
+ }
41
+ if (!taxCategory)
42
+ taxCategory = UkTaxCategories.STANDARD;
43
+ const taxRate = taxCategory.rate(context.order?.ordered);
44
+ ProductPricingAdapter.log(`ProductUkTax -> Tax Multiplicator: ${taxRate}`);
45
+ applyTaxRateToTaxableRows({
46
+ calculationSheet: params.calculationSheet,
47
+ resultSheet: pricingAdapter.resultSheet(),
48
+ taxRate,
49
+ baseCategory: ProductPricingRowCategory.Item,
50
+ adapterKey: ProductUkTax.key,
51
+ });
52
+ return pricingAdapter.calculate();
53
+ },
54
+ };
55
+ },
56
+ };
57
+ export default ProductUkTax;