@unchainedshop/plugins 5.0.0-alpha.2 → 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.
- package/lib/events/aws-eventbridge.d.ts +7 -1
- package/lib/events/aws-eventbridge.js +5 -11
- package/lib/events/redis.d.ts +3 -1
- package/lib/events/redis.js +5 -5
- package/lib/files/gridfs/api.js +1 -1
- package/lib/files/gridfs/handler-express.js +1 -1
- package/lib/payment/datatrans-v2/adapter.js +12 -9
- package/lib/payment/datatrans-v2/build3DSCardholder.d.ts +12 -0
- package/lib/payment/datatrans-v2/build3DSCardholder.js +44 -0
- package/lib/payment/paypal-checkout.js +17 -5
- package/lib/payment/stripe/stripe.js +1 -1
- package/lib/presets/base.js +4 -0
- package/lib/presets/countries/eu.d.ts +1 -0
- package/lib/presets/countries/eu.js +7 -0
- package/lib/presets/countries/uk.d.ts +1 -0
- package/lib/presets/countries/uk.js +7 -0
- package/lib/presets/countries/us.d.ts +1 -0
- package/lib/presets/countries/us.js +7 -0
- package/lib/pricing/delivery-eu-tax/adapter.d.ts +3 -0
- package/lib/pricing/delivery-eu-tax/adapter.js +55 -0
- package/lib/pricing/delivery-eu-tax/index.d.ts +4 -0
- package/lib/pricing/delivery-eu-tax/index.js +10 -0
- package/lib/pricing/delivery-eu-tax.d.ts +2 -0
- package/lib/pricing/delivery-eu-tax.js +55 -0
- package/lib/pricing/delivery-swiss-tax/adapter.js +7 -26
- package/lib/pricing/delivery-swiss-tax.js +7 -26
- package/lib/pricing/delivery-uk-tax/adapter.d.ts +3 -0
- package/lib/pricing/delivery-uk-tax/adapter.js +43 -0
- package/lib/pricing/delivery-uk-tax/index.d.ts +4 -0
- package/lib/pricing/delivery-uk-tax/index.js +10 -0
- package/lib/pricing/delivery-uk-tax.d.ts +2 -0
- package/lib/pricing/delivery-uk-tax.js +43 -0
- package/lib/pricing/delivery-us-sales-tax/adapter.d.ts +3 -0
- package/lib/pricing/delivery-us-sales-tax/adapter.js +58 -0
- package/lib/pricing/delivery-us-sales-tax/index.d.ts +4 -0
- package/lib/pricing/delivery-us-sales-tax/index.js +10 -0
- package/lib/pricing/delivery-us-sales-tax.d.ts +2 -0
- package/lib/pricing/delivery-us-sales-tax.js +58 -0
- package/lib/pricing/product-eu-tax/adapter.d.ts +3 -0
- package/lib/pricing/product-eu-tax/adapter.js +56 -0
- package/lib/pricing/product-eu-tax/index.d.ts +4 -0
- package/lib/pricing/product-eu-tax/index.js +10 -0
- package/lib/pricing/product-eu-tax.d.ts +2 -0
- package/lib/pricing/product-eu-tax.js +56 -0
- package/lib/pricing/product-quotation-price.d.ts +2 -0
- package/lib/pricing/product-quotation-price.js +40 -0
- package/lib/pricing/product-swiss-tax/adapter.js +7 -26
- package/lib/pricing/product-swiss-tax.js +7 -26
- package/lib/pricing/product-uk-tax/adapter.d.ts +3 -0
- package/lib/pricing/product-uk-tax/adapter.js +57 -0
- package/lib/pricing/product-uk-tax/index.d.ts +4 -0
- package/lib/pricing/product-uk-tax/index.js +10 -0
- package/lib/pricing/product-uk-tax.d.ts +2 -0
- package/lib/pricing/product-uk-tax.js +57 -0
- package/lib/pricing/product-us-sales-tax/adapter.d.ts +3 -0
- package/lib/pricing/product-us-sales-tax/adapter.js +52 -0
- package/lib/pricing/product-us-sales-tax/index.d.ts +4 -0
- package/lib/pricing/product-us-sales-tax/index.js +10 -0
- package/lib/pricing/product-us-sales-tax.d.ts +2 -0
- package/lib/pricing/product-us-sales-tax.js +52 -0
- package/lib/pricing/tax/applyTaxRateToTaxableRows.d.ts +23 -0
- package/lib/pricing/tax/applyTaxRateToTaxableRows.js +30 -0
- package/lib/pricing/tax/ch-tax-rates.json +24 -0
- package/lib/pricing/tax/ch.js +6 -30
- package/lib/pricing/tax/eraRates.d.ts +10 -0
- package/lib/pricing/tax/eraRates.js +15 -0
- package/lib/pricing/tax/eu-tax-rates.json +797 -0
- package/lib/pricing/tax/eu.d.ts +12 -0
- package/lib/pricing/tax/eu.js +38 -0
- package/lib/pricing/tax/uk-tax-rates.json +18 -0
- package/lib/pricing/tax/uk.d.ts +10 -0
- package/lib/pricing/tax/uk.js +23 -0
- package/lib/pricing/tax/us-tax-rates.json +334 -0
- package/lib/pricing/tax/us.d.ts +11 -0
- package/lib/pricing/tax/us.js +20 -0
- package/lib/pricing/utils/isDeliveryAddressInCountry.d.ts +1 -1
- package/lib/pricing/utils/isDeliveryAddressInCountry.js +3 -8
- package/lib/pricing/utils/resolveDeliveryLocation.d.ts +10 -0
- package/lib/pricing/utils/resolveDeliveryLocation.js +9 -0
- package/lib/quotations/manual/adapter.js +6 -1
- package/lib/quotations/manual.js +6 -1
- package/lib/worker/gc-guests/adapter.d.ts +9 -0
- package/lib/worker/gc-guests/adapter.js +56 -0
- package/lib/worker/gc-guests/index.d.ts +4 -0
- package/lib/worker/gc-guests/index.js +13 -0
- package/lib/worker/gc-guests.d.ts +8 -0
- package/lib/worker/gc-guests.js +55 -0
- package/lib/worker/invalidate-carts/adapter.d.ts +9 -0
- package/lib/worker/invalidate-carts/adapter.js +52 -0
- package/lib/worker/invalidate-carts/index.d.ts +4 -0
- package/lib/worker/invalidate-carts/index.js +13 -0
- package/lib/worker/invalidate-carts.d.ts +8 -0
- package/lib/worker/invalidate-carts.js +51 -0
- package/lib/worker/zombie-killer/adapter.d.ts +2 -0
- package/lib/worker/zombie-killer/adapter.js +26 -3
- package/lib/worker/zombie-killer/index.js +4 -1
- package/lib/worker/zombie-killer.d.ts +1 -0
- package/lib/worker/zombie-killer.js +24 -3
- package/package.json +24 -7
|
@@ -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,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,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,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,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,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,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,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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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,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;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {} from '@unchainedshop/core';
|
|
2
|
+
import { ProductUkTax } from "./adapter.js";
|
|
3
|
+
export const ProductUkTaxPlugin = {
|
|
4
|
+
key: 'shop.unchained.pricing.product-uk-tax',
|
|
5
|
+
label: 'Product UK Tax Plugin',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
adapters: [ProductUkTax],
|
|
8
|
+
};
|
|
9
|
+
export default ProductUkTaxPlugin;
|
|
10
|
+
export { ProductUkTax } from "./adapter.js";
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ProductPricingDirector, 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
|
+
ProductPricingDirector.registerAdapter(ProductUkTax);
|