@unchainedshop/plugins 2.6.1 → 2.7.1
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/payment/payrexx/api/index.d.ts +35 -0
- package/lib/payment/payrexx/api/index.js +100 -0
- package/lib/payment/payrexx/api/index.js.map +1 -0
- package/lib/payment/payrexx/index.d.ts +1 -0
- package/lib/payment/payrexx/index.js +139 -0
- package/lib/payment/payrexx/index.js.map +1 -0
- package/lib/payment/payrexx/middleware.d.ts +1 -0
- package/lib/payment/payrexx/middleware.js +55 -0
- package/lib/payment/payrexx/middleware.js.map +1 -0
- package/lib/payment/payrexx/payrexx.d.ts +16 -0
- package/lib/payment/payrexx/payrexx.js +19 -0
- package/lib/payment/payrexx/payrexx.js.map +1 -0
- package/lib/payment/stripe/middleware.d.ts +4 -0
- package/lib/payment/stripe/middleware.js +54 -47
- package/lib/payment/stripe/middleware.js.map +1 -1
- package/lib/plugins-index.js +3 -1
- package/lib/plugins-index.js.map +1 -1
- package/lib/pricing/delivery-swiss-tax.js +3 -0
- package/lib/pricing/delivery-swiss-tax.js.map +1 -1
- package/lib/pricing/discount-100-off.d.ts +2 -1
- package/lib/pricing/discount-100-off.js.map +1 -1
- package/lib/pricing/discount-half-price-manual.d.ts +2 -1
- package/lib/pricing/discount-half-price-manual.js.map +1 -1
- package/lib/pricing/discount-half-price.d.ts +2 -1
- package/lib/pricing/discount-half-price.js.map +1 -1
- package/lib/pricing/order-discount.d.ts +2 -1
- package/lib/pricing/order-discount.js +2 -8
- package/lib/pricing/order-discount.js.map +1 -1
- package/lib/pricing/order-items-discount.js +4 -3
- package/lib/pricing/order-items-discount.js.map +1 -1
- package/lib/pricing/product-discount.js +35 -18
- package/lib/pricing/product-discount.js.map +1 -1
- package/lib/pricing/product-swiss-tax.js +3 -0
- package/lib/pricing/product-swiss-tax.js.map +1 -1
- package/package.json +22 -22
- package/src/payment/payrexx/api/index.ts +132 -0
- package/src/payment/payrexx/index.ts +184 -0
- package/src/payment/payrexx/middleware.ts +64 -0
- package/src/payment/payrexx/payrexx.ts +25 -0
- package/src/payment/payrexx/readme.md +4 -0
- package/src/payment/stripe/middleware.ts +58 -51
- package/src/plugins-index.ts +10 -0
- package/src/pricing/delivery-swiss-tax.ts +6 -1
- package/src/pricing/discount-100-off.ts +2 -1
- package/src/pricing/discount-half-price-manual.ts +2 -1
- package/src/pricing/discount-half-price.ts +2 -1
- package/src/pricing/order-discount.ts +4 -10
- package/src/pricing/order-items-discount.ts +9 -4
- package/src/pricing/product-discount.ts +48 -20
- package/src/pricing/product-swiss-tax.ts +6 -1
|
@@ -5,8 +5,9 @@ import {
|
|
|
5
5
|
} from '@unchainedshop/types/products.pricing.js';
|
|
6
6
|
import { ProductPricingDirector, ProductPricingAdapter } from '@unchainedshop/core-products';
|
|
7
7
|
import { calculation as calcUtils } from '@unchainedshop/utils';
|
|
8
|
+
import { ProductDiscountConfiguration } from '@unchainedshop/core-products/director/ProductDiscountConfiguration.js';
|
|
8
9
|
|
|
9
|
-
const ProductDiscount: IProductPricingAdapter = {
|
|
10
|
+
const ProductDiscount: IProductPricingAdapter<ProductDiscountConfiguration> = {
|
|
10
11
|
...ProductPricingAdapter,
|
|
11
12
|
|
|
12
13
|
key: 'shop.unchained.pricing.product-discount',
|
|
@@ -21,10 +22,15 @@ const ProductDiscount: IProductPricingAdapter = {
|
|
|
21
22
|
actions: (params) => {
|
|
22
23
|
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
23
24
|
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const addDiscounts = (
|
|
26
|
+
discount: Discount<ProductDiscountConfiguration>,
|
|
27
|
+
total: number,
|
|
28
|
+
resolvedConfiguration: ProductDiscountConfiguration,
|
|
29
|
+
) => {
|
|
30
|
+
const { discountId } = discount;
|
|
31
|
+
const { isNetPrice = false, taxRate, ...meta } = resolvedConfiguration;
|
|
32
|
+
const amount = calcUtils.applyRate(resolvedConfiguration, total);
|
|
33
|
+
const isTaxable = taxRate === undefined || taxRate === null;
|
|
28
34
|
|
|
29
35
|
pricingAdapter.resultSheet().addDiscount({
|
|
30
36
|
amount: amount * -1,
|
|
@@ -33,28 +39,50 @@ const ProductDiscount: IProductPricingAdapter = {
|
|
|
33
39
|
isTaxable,
|
|
34
40
|
meta: { adapter: ProductDiscount.key, ...meta },
|
|
35
41
|
});
|
|
42
|
+
if (!isTaxable && taxRate) {
|
|
43
|
+
const taxAmount = calcUtils.getTaxAmount(amount, taxRate, isNetPrice);
|
|
44
|
+
pricingAdapter.resultSheet().addTax({
|
|
45
|
+
amount: taxAmount * -1,
|
|
46
|
+
rate: taxRate,
|
|
47
|
+
discountId,
|
|
48
|
+
baseCategory: ProductPricingRowCategory.Discount,
|
|
49
|
+
meta: { adapter: ProductDiscount.key, discountId, ...meta },
|
|
50
|
+
});
|
|
51
|
+
if (!isNetPrice) {
|
|
52
|
+
pricingAdapter.resultSheet().addDiscount({
|
|
53
|
+
amount: taxAmount,
|
|
54
|
+
discountId,
|
|
55
|
+
isNetPrice: false,
|
|
56
|
+
isTaxable: false,
|
|
57
|
+
meta: { adapter: ProductDiscount.key, discountId, ...meta },
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
36
61
|
};
|
|
37
62
|
|
|
38
63
|
return {
|
|
39
64
|
...pricingAdapter,
|
|
40
65
|
|
|
41
66
|
calculate: async () => {
|
|
42
|
-
const taxableTotal = params.calculationSheet.sum({
|
|
43
|
-
category: ProductPricingRowCategory.Item,
|
|
44
|
-
isTaxable: true,
|
|
45
|
-
});
|
|
46
|
-
const nonTaxableTotal = params.calculationSheet.sum({
|
|
47
|
-
category: ProductPricingRowCategory.Item,
|
|
48
|
-
isTaxable: false,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
67
|
params.discounts.forEach((discount) => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
68
|
+
const { configuration } = discount;
|
|
69
|
+
|
|
70
|
+
const resolvedConfiguration = configuration.customPriceConfigurationResolver
|
|
71
|
+
? configuration.customPriceConfigurationResolver(
|
|
72
|
+
params.context.product,
|
|
73
|
+
params.context.quantity,
|
|
74
|
+
params.context.configuration,
|
|
75
|
+
)
|
|
76
|
+
: configuration;
|
|
77
|
+
|
|
78
|
+
if (!resolvedConfiguration) return;
|
|
79
|
+
|
|
80
|
+
const total = params.calculationSheet.total({
|
|
81
|
+
category: ProductPricingRowCategory.Item,
|
|
82
|
+
useNetPrice: resolvedConfiguration.isNetPrice,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
addDiscounts(discount, total.amount, resolvedConfiguration);
|
|
58
86
|
});
|
|
59
87
|
|
|
60
88
|
return pricingAdapter.calculate();
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { ProductPricingDirector, ProductPricingAdapter } from '@unchainedshop/core-products';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
IProductPricingAdapter,
|
|
4
|
+
ProductPricingRowCategory,
|
|
5
|
+
} from '@unchainedshop/types/products.pricing.js';
|
|
3
6
|
import { Product } from '@unchainedshop/types/products.js';
|
|
4
7
|
import { Order } from '@unchainedshop/types/orders.js';
|
|
5
8
|
import { SwissTaxCategories } from './tax/ch.js';
|
|
@@ -73,6 +76,7 @@ export const ProductSwissTax: IProductPricingAdapter = {
|
|
|
73
76
|
pricingAdapter.resultSheet().addTax({
|
|
74
77
|
amount: taxAmount,
|
|
75
78
|
rate: taxRate,
|
|
79
|
+
baseCategory: ProductPricingRowCategory.Item,
|
|
76
80
|
meta: { adapter: ProductSwissTax.key },
|
|
77
81
|
});
|
|
78
82
|
} else {
|
|
@@ -80,6 +84,7 @@ export const ProductSwissTax: IProductPricingAdapter = {
|
|
|
80
84
|
pricingAdapter.resultSheet().addTax({
|
|
81
85
|
amount: taxAmount,
|
|
82
86
|
rate: taxRate,
|
|
87
|
+
baseCategory: ProductPricingRowCategory.Item,
|
|
83
88
|
meta: { adapter: ProductSwissTax.key },
|
|
84
89
|
});
|
|
85
90
|
}
|