@unchainedshop/plugins 4.8.22 → 4.8.24
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/files/gridfs/handler-express.js +2 -1
- package/lib/files/gridfs/handler-fastify.js +2 -1
- 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-swiss-tax/adapter.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-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/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-swiss-tax/adapter.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-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/package.json +1 -1
|
@@ -18,8 +18,9 @@ const gridfsHandler = async (req, res) => {
|
|
|
18
18
|
const directoryName = decodeURIComponent(directoryNameRaw);
|
|
19
19
|
const fileName = decodeURIComponent(fileNameRaw);
|
|
20
20
|
res.setHeader('Access-Control-Allow-Methods', 'GET, PUT');
|
|
21
|
-
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
|
21
|
+
res.setHeader('Access-Control-Allow-Headers', req.get('Access-Control-Request-Headers') || 'Content-Type');
|
|
22
22
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
23
|
+
res.setHeader('Vary', 'Access-Control-Request-Headers');
|
|
23
24
|
if (req.method === 'OPTIONS') {
|
|
24
25
|
res.status(200).end();
|
|
25
26
|
return;
|
|
@@ -15,8 +15,9 @@ const gridfsHandler = async (req, reply) => {
|
|
|
15
15
|
const { services, modules } = req.unchainedContext;
|
|
16
16
|
const { directoryName, fileName } = req.params;
|
|
17
17
|
reply.header('Access-Control-Allow-Methods', 'GET, PUT');
|
|
18
|
-
reply.header('Access-Control-Allow-Headers', 'content-type');
|
|
18
|
+
reply.header('Access-Control-Allow-Headers', req.headers['access-control-request-headers'] || 'content-type');
|
|
19
19
|
reply.header('Access-Control-Allow-Origin', '*');
|
|
20
|
+
reply.header('Vary', 'Access-Control-Request-Headers');
|
|
20
21
|
if (req.method === 'OPTIONS') {
|
|
21
22
|
reply.status(200);
|
|
22
23
|
return reply.send();
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { DeliveryPricingRowCategory, DeliveryPricingAdapter, } from '@unchainedshop/core';
|
|
2
|
+
import { isEuMemberCountry, resolveEuTaxCategoryFromDeliveryProvider, resolveEuTaxRate, } from "../tax/eu.js";
|
|
3
|
+
import resolveDeliveryLocation from "../utils/resolveDeliveryLocation.js";
|
|
4
|
+
import { applyTaxRateToTaxableRows } from "../tax/applyTaxRateToTaxableRows.js";
|
|
5
|
+
export const DeliveryEuTax = {
|
|
6
|
+
...DeliveryPricingAdapter,
|
|
7
|
+
key: 'shop.unchained.pricing.delivery-eu-tax',
|
|
8
|
+
version: '1.0.0',
|
|
9
|
+
label: 'Apply EU 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
|
+
const { countryCode } = resolveDeliveryLocation({
|
|
17
|
+
order: context.order,
|
|
18
|
+
orderDelivery: context.orderDelivery,
|
|
19
|
+
countryCode: context.countryCode,
|
|
20
|
+
});
|
|
21
|
+
return isEuMemberCountry(countryCode);
|
|
22
|
+
},
|
|
23
|
+
actions: (params) => {
|
|
24
|
+
const pricingAdapter = DeliveryPricingAdapter.actions(params);
|
|
25
|
+
const { context } = params;
|
|
26
|
+
return {
|
|
27
|
+
...pricingAdapter,
|
|
28
|
+
calculate: async () => {
|
|
29
|
+
const { countryCode } = resolveDeliveryLocation({
|
|
30
|
+
order: context.order,
|
|
31
|
+
orderDelivery: context.orderDelivery,
|
|
32
|
+
countryCode: context.countryCode,
|
|
33
|
+
});
|
|
34
|
+
const category = resolveEuTaxCategoryFromDeliveryProvider(context.provider);
|
|
35
|
+
const taxRate = resolveEuTaxRate({
|
|
36
|
+
countryCode,
|
|
37
|
+
category,
|
|
38
|
+
referenceDate: context.order?.ordered,
|
|
39
|
+
});
|
|
40
|
+
if (taxRate === null)
|
|
41
|
+
return pricingAdapter.calculate();
|
|
42
|
+
DeliveryPricingAdapter.log(`DeliveryEuTax -> Tax Multiplicator: ${taxRate}`);
|
|
43
|
+
applyTaxRateToTaxableRows({
|
|
44
|
+
calculationSheet: params.calculationSheet,
|
|
45
|
+
resultSheet: pricingAdapter.resultSheet(),
|
|
46
|
+
taxRate,
|
|
47
|
+
baseCategory: DeliveryPricingRowCategory.Delivery,
|
|
48
|
+
adapterKey: DeliveryEuTax.key,
|
|
49
|
+
});
|
|
50
|
+
return pricingAdapter.calculate();
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
export default DeliveryEuTax;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {} from '@unchainedshop/core';
|
|
2
|
+
import { DeliveryEuTax } from "./adapter.js";
|
|
3
|
+
export const DeliveryEuTaxPlugin = {
|
|
4
|
+
key: 'shop.unchained.pricing.delivery-eu-tax',
|
|
5
|
+
label: 'Delivery EU Tax Plugin',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
adapters: [DeliveryEuTax],
|
|
8
|
+
};
|
|
9
|
+
export default DeliveryEuTaxPlugin;
|
|
10
|
+
export { DeliveryEuTax } from "./adapter.js";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DeliveryPricingRowCategory, DeliveryPricingAdapter, } 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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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,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,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,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,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";
|
|
@@ -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
|
},
|
|
@@ -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,52 @@
|
|
|
1
|
+
import { ProductPricingAdapter, ProductPricingRowCategory, } from '@unchainedshop/core';
|
|
2
|
+
import { US_COUNTRY_CODE, isProductExemptFromUsSalesTax, resolveUsSalesTaxRate } from "../tax/us.js";
|
|
3
|
+
import resolveDeliveryLocation from "../utils/resolveDeliveryLocation.js";
|
|
4
|
+
import { applyTaxRateToTaxableRows } from "../tax/applyTaxRateToTaxableRows.js";
|
|
5
|
+
export const ProductUsSalesTax = {
|
|
6
|
+
...ProductPricingAdapter,
|
|
7
|
+
key: 'shop.unchained.pricing.product-us-sales-tax',
|
|
8
|
+
version: '1.0.0',
|
|
9
|
+
label: 'Apply US State Sales Tax 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
|
+
if (isProductExemptFromUsSalesTax(context.product)) {
|
|
21
|
+
return pricingAdapter.calculate();
|
|
22
|
+
}
|
|
23
|
+
const orderDelivery = context.order?.deliveryId
|
|
24
|
+
? await context.modules.orders.deliveries.findDelivery({
|
|
25
|
+
orderDeliveryId: context.order?.deliveryId,
|
|
26
|
+
})
|
|
27
|
+
: null;
|
|
28
|
+
const { countryCode, regionCode } = resolveDeliveryLocation({ ...context, orderDelivery });
|
|
29
|
+
if (countryCode !== US_COUNTRY_CODE)
|
|
30
|
+
return pricingAdapter.calculate();
|
|
31
|
+
const taxRate = resolveUsSalesTaxRate({
|
|
32
|
+
regionCode,
|
|
33
|
+
referenceDate: context.order?.ordered,
|
|
34
|
+
});
|
|
35
|
+
if (taxRate === null) {
|
|
36
|
+
ProductPricingAdapter.log(`ProductUsSalesTax -> unknown state '${regionCode}', no sales tax applied`);
|
|
37
|
+
return pricingAdapter.calculate();
|
|
38
|
+
}
|
|
39
|
+
ProductPricingAdapter.log(`ProductUsSalesTax -> Tax Multiplicator: ${taxRate}`);
|
|
40
|
+
applyTaxRateToTaxableRows({
|
|
41
|
+
calculationSheet: params.calculationSheet,
|
|
42
|
+
resultSheet: pricingAdapter.resultSheet(),
|
|
43
|
+
taxRate,
|
|
44
|
+
baseCategory: ProductPricingRowCategory.Item,
|
|
45
|
+
adapterKey: ProductUsSalesTax.key,
|
|
46
|
+
});
|
|
47
|
+
return pricingAdapter.calculate();
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
export default ProductUsSalesTax;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {} from '@unchainedshop/core';
|
|
2
|
+
import { ProductUsSalesTax } from "./adapter.js";
|
|
3
|
+
export const ProductUsSalesTaxPlugin = {
|
|
4
|
+
key: 'shop.unchained.pricing.product-us-sales-tax',
|
|
5
|
+
label: 'Product US Sales Tax Plugin',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
adapters: [ProductUsSalesTax],
|
|
8
|
+
};
|
|
9
|
+
export default ProductUsSalesTaxPlugin;
|
|
10
|
+
export { ProductUsSalesTax } from "./adapter.js";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/plugins",
|
|
3
3
|
"description": "Official plugin collection for the Unchained Engine with payment, delivery, and pricing adapters",
|
|
4
|
-
"version": "4.8.
|
|
4
|
+
"version": "4.8.24",
|
|
5
5
|
"main": "lib/plugins-index.js",
|
|
6
6
|
"types": "lib/plugins-index.d.ts",
|
|
7
7
|
"exports": {
|