@unchainedshop/plugins 4.7.2 → 4.8.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/README.md +2 -0
- package/lib/delivery/post.d.ts +1 -0
- package/lib/delivery/post.js +23 -0
- package/lib/delivery/send-message.d.ts +1 -0
- package/lib/delivery/send-message.js +40 -0
- package/lib/delivery/stores.d.ts +1 -0
- package/lib/delivery/stores.js +43 -0
- package/lib/enrollments/licensed.d.ts +4 -0
- package/lib/enrollments/licensed.js +52 -0
- package/lib/events/node-event-emitter.d.ts +1 -3
- package/lib/events/node-event-emitter.js +3 -3
- package/lib/files/gridfs/adapter.d.ts +2 -2
- package/lib/files/gridfs/adapter.js +5 -2
- package/lib/files/gridfs/handler-express.d.ts +9 -0
- package/lib/files/gridfs/handler-express.js +110 -0
- package/lib/files/gridfs/handler-fastify.d.ts +3 -0
- package/lib/files/gridfs/handler-fastify.js +138 -0
- package/lib/files/gridfs/index.d.ts +4 -5
- package/lib/files/gridfs/index.js +3 -30
- package/lib/files/minio/handler-express.d.ts +2 -0
- package/lib/files/minio/handler-express.js +36 -0
- package/lib/files/minio/handler-fastify.d.ts +3 -0
- package/lib/files/minio/handler-fastify.js +40 -0
- package/lib/files/minio/index.d.ts +5 -4
- package/lib/files/minio/index.js +157 -18
- package/lib/filters/local-search.d.ts +3 -0
- package/lib/filters/local-search.js +66 -0
- package/lib/filters/strict-equal.d.ts +1 -0
- package/lib/filters/strict-equal.js +24 -0
- package/lib/payment/apple-iap/adapter.d.ts +1 -2
- package/lib/payment/apple-iap/adapter.js +3 -2
- package/lib/payment/apple-iap/handler-express.d.ts +2 -0
- package/lib/payment/apple-iap/handler-express.js +103 -0
- package/lib/payment/apple-iap/handler-fastify.d.ts +3 -0
- package/lib/payment/apple-iap/handler-fastify.js +102 -0
- package/lib/payment/apple-iap/index.d.ts +4 -6
- package/lib/payment/apple-iap/index.js +3 -28
- package/lib/payment/braintree.d.ts +1 -0
- package/lib/payment/braintree.js +138 -0
- package/lib/payment/cryptopay/handler-express.d.ts +2 -0
- package/lib/payment/cryptopay/handler-express.js +19 -0
- package/lib/payment/cryptopay/handler-fastify.d.ts +3 -0
- package/lib/payment/cryptopay/handler-fastify.js +17 -0
- package/lib/payment/cryptopay/index.d.ts +4 -5
- package/lib/payment/cryptopay/index.js +3 -31
- package/lib/payment/cryptopay/plugin.d.ts +3 -0
- package/lib/payment/cryptopay/plugin.js +159 -0
- package/lib/payment/datatrans-v2/handler-express.d.ts +1 -0
- package/lib/payment/datatrans-v2/handler-express.js +71 -0
- package/lib/payment/datatrans-v2/handler-fastify.d.ts +2 -0
- package/lib/payment/datatrans-v2/handler-fastify.js +71 -0
- package/lib/payment/datatrans-v2/index.d.ts +1 -4
- package/lib/payment/datatrans-v2/index.js +400 -17
- package/lib/payment/invoice-prepaid.d.ts +1 -0
- package/lib/payment/invoice-prepaid.js +30 -0
- package/lib/payment/invoice.d.ts +1 -0
- package/lib/payment/invoice.js +27 -0
- package/lib/payment/paypal-checkout.d.ts +1 -0
- package/lib/payment/paypal-checkout.js +87 -0
- package/lib/payment/payrexx/handler-express.d.ts +1 -0
- package/lib/payment/payrexx/handler-express.js +85 -0
- package/lib/payment/payrexx/handler-fastify.d.ts +2 -0
- package/lib/payment/payrexx/handler-fastify.js +91 -0
- package/lib/payment/payrexx/index.d.ts +1 -4
- package/lib/payment/payrexx/index.js +158 -19
- package/lib/payment/postfinance-checkout/handler-express.d.ts +1 -0
- package/lib/payment/postfinance-checkout/handler-express.js +37 -0
- package/lib/payment/postfinance-checkout/handler-fastify.d.ts +2 -0
- package/lib/payment/postfinance-checkout/handler-fastify.js +40 -0
- package/lib/payment/postfinance-checkout/index.d.ts +0 -5
- package/lib/payment/postfinance-checkout/index.js +186 -25
- package/lib/payment/saferpay/adapter.js +2 -1
- package/lib/payment/saferpay/handler-express.d.ts +1 -0
- package/lib/payment/saferpay/handler-express.js +59 -0
- package/lib/payment/saferpay/handler-fastify.d.ts +2 -0
- package/lib/payment/saferpay/handler-fastify.js +62 -0
- package/lib/payment/saferpay/index.d.ts +4 -5
- package/lib/payment/saferpay/index.js +3 -29
- package/lib/payment/stripe/handler-express.d.ts +5 -0
- package/lib/payment/stripe/handler-express.js +121 -0
- package/lib/payment/stripe/handler-fastify.d.ts +6 -0
- package/lib/payment/stripe/handler-fastify.js +131 -0
- package/lib/payment/stripe/index.d.ts +1 -4
- package/lib/payment/stripe/index.js +116 -22
- package/lib/payment/stripe/stripe.js +4 -1
- package/lib/presets/all-express.d.ts +6 -0
- package/lib/presets/all-express.js +26 -0
- package/lib/presets/all-fastify.d.ts +6 -0
- package/lib/presets/all-fastify.js +49 -0
- package/lib/presets/all.d.ts +70 -1
- package/lib/presets/all.js +27 -41
- package/lib/presets/base-express.d.ts +2 -0
- package/lib/presets/base-express.js +5 -0
- package/lib/presets/base-fastify.d.ts +3 -0
- package/lib/presets/base-fastify.js +16 -0
- package/lib/presets/base.d.ts +25 -1
- package/lib/presets/base.js +25 -56
- package/lib/presets/countries/ch.d.ts +2 -1
- package/lib/presets/countries/ch.js +2 -7
- package/lib/presets/crypto-express.d.ts +3 -0
- package/lib/presets/crypto-express.js +8 -0
- package/lib/presets/crypto-fastify.d.ts +3 -0
- package/lib/presets/crypto-fastify.js +11 -0
- package/lib/presets/crypto.d.ts +7 -3
- package/lib/presets/crypto.js +7 -18
- package/lib/pricing/delivery-swiss-tax.d.ts +2 -0
- package/lib/pricing/delivery-swiss-tax.js +62 -0
- package/lib/pricing/discount-100-off.d.ts +2 -0
- package/lib/pricing/discount-100-off.js +30 -0
- package/lib/pricing/discount-half-price-manual.d.ts +2 -0
- package/lib/pricing/discount-half-price-manual.js +30 -0
- package/lib/pricing/discount-half-price.d.ts +2 -0
- package/lib/pricing/discount-half-price.js +33 -0
- package/lib/pricing/free-delivery.d.ts +2 -0
- package/lib/pricing/free-delivery.js +27 -0
- package/lib/pricing/free-payment.d.ts +2 -0
- package/lib/pricing/free-payment.js +27 -0
- package/lib/pricing/order-delivery.d.ts +2 -0
- package/lib/pricing/order-delivery.js +33 -0
- package/lib/pricing/order-discount.d.ts +2 -0
- package/lib/pricing/order-discount.js +74 -0
- package/lib/pricing/order-items-discount.d.ts +2 -0
- package/lib/pricing/order-items-discount.js +50 -0
- package/lib/pricing/order-items.d.ts +2 -0
- package/lib/pricing/order-items.js +43 -0
- package/lib/pricing/order-payment.d.ts +2 -0
- package/lib/pricing/order-payment.js +33 -0
- package/lib/pricing/order-round.d.ts +10 -0
- package/lib/pricing/order-round.js +135 -0
- package/lib/pricing/product-catalog-price-options.d.ts +2 -0
- package/lib/pricing/product-catalog-price-options.js +51 -0
- package/lib/pricing/product-catalog-price.d.ts +2 -0
- package/lib/pricing/product-catalog-price.js +60 -0
- package/lib/pricing/product-discount.d.ts +2 -0
- package/lib/pricing/product-discount.js +69 -0
- package/lib/pricing/product-price-rateconversion.d.ts +2 -0
- package/lib/pricing/product-price-rateconversion.js +53 -0
- package/lib/pricing/product-round.d.ts +10 -0
- package/lib/pricing/product-round.js +44 -0
- package/lib/pricing/product-swiss-tax.d.ts +2 -0
- package/lib/pricing/product-swiss-tax.js +76 -0
- package/lib/quotations/manual.d.ts +1 -0
- package/lib/quotations/manual.js +20 -0
- package/lib/warehousing/eth-minter.d.ts +1 -0
- package/lib/warehousing/eth-minter.js +120 -0
- package/lib/warehousing/store.d.ts +1 -0
- package/lib/warehousing/store.js +34 -0
- package/lib/worker/budgetsms.d.ts +9 -0
- package/lib/worker/budgetsms.js +169 -0
- package/lib/worker/bulk-export.d.ts +2 -0
- package/lib/worker/bulk-export.js +64 -0
- package/lib/worker/bulk-import.d.ts +2 -0
- package/lib/worker/bulk-import.js +65 -0
- package/lib/worker/bulkgate.d.ts +1 -0
- package/lib/worker/bulkgate.js +91 -0
- package/lib/worker/email.d.ts +1 -0
- package/lib/worker/email.js +136 -0
- package/lib/worker/enrollment-order-generator.d.ts +1 -0
- package/lib/worker/enrollment-order-generator.js +77 -0
- package/lib/worker/error-notifications.d.ts +9 -0
- package/lib/worker/error-notifications.js +61 -0
- package/lib/worker/export-token.d.ts +4 -0
- package/lib/worker/export-token.js +26 -0
- package/lib/worker/external.d.ts +2 -0
- package/lib/worker/external.js +13 -0
- package/lib/worker/heartbeat.d.ts +1 -0
- package/lib/worker/heartbeat.js +26 -0
- package/lib/worker/http-request.d.ts +8 -0
- package/lib/worker/http-request.js +56 -0
- package/lib/worker/message.d.ts +10 -0
- package/lib/worker/message.js +42 -0
- package/lib/worker/push-notification.d.ts +1 -0
- package/lib/worker/push-notification.js +87 -0
- package/lib/worker/twilio.d.ts +1 -0
- package/lib/worker/twilio.js +59 -0
- package/lib/worker/update-coinbase-rates.d.ts +1 -0
- package/lib/worker/update-coinbase-rates.js +59 -0
- package/lib/worker/update-ecb-rates.d.ts +1 -0
- package/lib/worker/update-ecb-rates.js +92 -0
- package/lib/worker/update-token-ownership.d.ts +3 -0
- package/lib/worker/update-token-ownership.js +57 -0
- package/lib/worker/zombie-killer.d.ts +13 -0
- package/lib/worker/zombie-killer.js +91 -0
- package/package.json +9 -14
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { PaymentPricingAdapter, PaymentPricingDirector, } from '@unchainedshop/core';
|
|
2
|
+
export const PaymentFreePrice = {
|
|
3
|
+
...PaymentPricingAdapter,
|
|
4
|
+
key: 'shop.unchained.pricing.payment-free',
|
|
5
|
+
label: 'Free Payment',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
orderIndex: 0,
|
|
8
|
+
isActivatedFor: () => {
|
|
9
|
+
return true;
|
|
10
|
+
},
|
|
11
|
+
actions: (params) => {
|
|
12
|
+
const pricingAdapter = PaymentPricingAdapter.actions(params);
|
|
13
|
+
return {
|
|
14
|
+
...pricingAdapter,
|
|
15
|
+
calculate: async () => {
|
|
16
|
+
pricingAdapter.resultSheet().addFee({
|
|
17
|
+
amount: 0,
|
|
18
|
+
isNetPrice: false,
|
|
19
|
+
isTaxable: false,
|
|
20
|
+
meta: { adapter: PaymentFreePrice.key },
|
|
21
|
+
});
|
|
22
|
+
return pricingAdapter.calculate();
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
PaymentPricingDirector.registerAdapter(PaymentFreePrice);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { OrderPricingDirector, OrderPricingAdapter, DeliveryPricingSheet, } from '@unchainedshop/core';
|
|
2
|
+
export const OrderDelivery = {
|
|
3
|
+
...OrderPricingAdapter,
|
|
4
|
+
key: 'shop.unchained.pricing.order-delivery',
|
|
5
|
+
version: '1.0.0',
|
|
6
|
+
label: 'Add Delivery Fees to Order',
|
|
7
|
+
orderIndex: 10,
|
|
8
|
+
isActivatedFor: () => {
|
|
9
|
+
return true;
|
|
10
|
+
},
|
|
11
|
+
actions: (params) => {
|
|
12
|
+
const pricingAdapter = OrderPricingAdapter.actions(params);
|
|
13
|
+
const { order, orderDelivery } = params.context;
|
|
14
|
+
return {
|
|
15
|
+
...pricingAdapter,
|
|
16
|
+
calculate: async () => {
|
|
17
|
+
if (!orderDelivery)
|
|
18
|
+
return null;
|
|
19
|
+
const pricing = DeliveryPricingSheet({
|
|
20
|
+
calculation: orderDelivery.calculation,
|
|
21
|
+
currencyCode: order.currencyCode,
|
|
22
|
+
});
|
|
23
|
+
const tax = pricing.taxSum();
|
|
24
|
+
const shipping = pricing.gross();
|
|
25
|
+
pricingAdapter
|
|
26
|
+
.resultSheet()
|
|
27
|
+
.addDelivery({ amount: shipping, taxAmount: tax, meta: { adapter: OrderDelivery.key } });
|
|
28
|
+
return pricingAdapter.calculate();
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
OrderPricingDirector.registerAdapter(OrderDelivery);
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { OrderPricingRowCategory, OrderPricingDirector, OrderPricingAdapter, DeliveryPricingSheet, PaymentPricingSheet, ProductPricingSheet, resolveRatioAndTaxDivisorForPricingSheet, } from '@unchainedshop/core';
|
|
2
|
+
import { calculation as calcUtils } from '@unchainedshop/utils';
|
|
3
|
+
export const OrderDiscount = {
|
|
4
|
+
...OrderPricingAdapter,
|
|
5
|
+
key: 'shop.unchained.pricing.order-discount',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
label: 'Apply Discounts on Total Order Value',
|
|
8
|
+
orderIndex: 40,
|
|
9
|
+
isActivatedFor: () => {
|
|
10
|
+
return true;
|
|
11
|
+
},
|
|
12
|
+
actions: (params) => {
|
|
13
|
+
const pricingAdapter = OrderPricingAdapter.actions(params);
|
|
14
|
+
const { order, orderDelivery, orderPositions, orderPayment } = params.context;
|
|
15
|
+
return {
|
|
16
|
+
...pricingAdapter,
|
|
17
|
+
calculate: async () => {
|
|
18
|
+
if (!order)
|
|
19
|
+
return pricingAdapter.calculate();
|
|
20
|
+
const totalAmountOfItems = params.calculationSheet.total({
|
|
21
|
+
category: OrderPricingRowCategory.Items,
|
|
22
|
+
useNetPrice: false,
|
|
23
|
+
}).amount;
|
|
24
|
+
const totalAmountOfPaymentAndDelivery = params.calculationSheet.total({
|
|
25
|
+
category: OrderPricingRowCategory.Payment,
|
|
26
|
+
useNetPrice: false,
|
|
27
|
+
}).amount +
|
|
28
|
+
params.calculationSheet.total({
|
|
29
|
+
category: OrderPricingRowCategory.Delivery,
|
|
30
|
+
useNetPrice: false,
|
|
31
|
+
}).amount;
|
|
32
|
+
const itemShares = orderPositions.map((orderPosition) => resolveRatioAndTaxDivisorForPricingSheet(ProductPricingSheet({
|
|
33
|
+
calculation: orderPosition.calculation,
|
|
34
|
+
currencyCode: order.currencyCode,
|
|
35
|
+
quantity: orderPosition.quantity,
|
|
36
|
+
}), totalAmountOfItems));
|
|
37
|
+
const deliveryShare = resolveRatioAndTaxDivisorForPricingSheet(DeliveryPricingSheet({
|
|
38
|
+
calculation: orderDelivery?.calculation || [],
|
|
39
|
+
currencyCode: order.currencyCode,
|
|
40
|
+
}), totalAmountOfPaymentAndDelivery);
|
|
41
|
+
const paymentShare = resolveRatioAndTaxDivisorForPricingSheet(PaymentPricingSheet({
|
|
42
|
+
calculation: orderPayment?.calculation || [],
|
|
43
|
+
currencyCode: order.currencyCode,
|
|
44
|
+
}), totalAmountOfPaymentAndDelivery);
|
|
45
|
+
let amountLeft = totalAmountOfPaymentAndDelivery + totalAmountOfItems;
|
|
46
|
+
params.discounts.forEach(({ configuration, discountId }) => {
|
|
47
|
+
const leftInDiscountToSplit = calcUtils.calculateAmountToSplit({ ...configuration }, Math.min(totalAmountOfItems, amountLeft));
|
|
48
|
+
const [itemsDiscountAmount, itemsTaxAmount] = calcUtils.applyDiscountToMultipleShares(itemShares, Math.max(0, Math.min(amountLeft, leftInDiscountToSplit)));
|
|
49
|
+
amountLeft -= itemsDiscountAmount;
|
|
50
|
+
const fixedRate = Number(configuration.fixedRate) > 0
|
|
51
|
+
? Math.max(0, configuration.fixedRate - itemsDiscountAmount)
|
|
52
|
+
: undefined;
|
|
53
|
+
const leftInFeesToSplit = calcUtils.calculateAmountToSplit({ ...configuration, fixedRate }, Math.min(totalAmountOfPaymentAndDelivery, amountLeft));
|
|
54
|
+
const [deliveryAndPaymentDiscountAmount, deliveryAndPaymentTaxAmount] = calcUtils.applyDiscountToMultipleShares([deliveryShare, paymentShare], Math.max(0, Math.min(amountLeft, leftInFeesToSplit)));
|
|
55
|
+
amountLeft -= deliveryAndPaymentDiscountAmount;
|
|
56
|
+
const discountAmount = (itemsDiscountAmount + deliveryAndPaymentDiscountAmount) * -1;
|
|
57
|
+
const taxAmount = (itemsTaxAmount + deliveryAndPaymentTaxAmount) * -1;
|
|
58
|
+
if (discountAmount) {
|
|
59
|
+
pricingAdapter.resultSheet().addDiscount({
|
|
60
|
+
amount: discountAmount,
|
|
61
|
+
taxAmount,
|
|
62
|
+
discountId,
|
|
63
|
+
meta: {
|
|
64
|
+
adapter: OrderDiscount.key,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return pricingAdapter.calculate();
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
OrderPricingDirector.registerAdapter(OrderDiscount);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ProductPricingSheet, OrderPricingDirector, OrderPricingAdapter, OrderPricingRowCategory, resolveRatioAndTaxDivisorForPricingSheet, } from '@unchainedshop/core';
|
|
2
|
+
import { calculation as calcUtils } from '@unchainedshop/utils';
|
|
3
|
+
export const OrderItemsDiscount = {
|
|
4
|
+
...OrderPricingAdapter,
|
|
5
|
+
key: 'shop.unchained.pricing.order-items-discount',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
label: 'Apply Discounts on Total Value Of Goods',
|
|
8
|
+
orderIndex: 30,
|
|
9
|
+
isActivatedFor: () => {
|
|
10
|
+
return true;
|
|
11
|
+
},
|
|
12
|
+
actions: (params) => {
|
|
13
|
+
const pricingAdapter = OrderPricingAdapter.actions(params);
|
|
14
|
+
const { order, orderPositions } = params.context;
|
|
15
|
+
return {
|
|
16
|
+
...pricingAdapter,
|
|
17
|
+
calculate: async () => {
|
|
18
|
+
const totalAmountOfItems = params.calculationSheet.total({
|
|
19
|
+
category: OrderPricingRowCategory.Items,
|
|
20
|
+
useNetPrice: false,
|
|
21
|
+
}).amount;
|
|
22
|
+
const itemShares = orderPositions.map((orderPosition) => resolveRatioAndTaxDivisorForPricingSheet(ProductPricingSheet({
|
|
23
|
+
calculation: orderPosition.calculation,
|
|
24
|
+
currencyCode: order.currencyCode,
|
|
25
|
+
quantity: orderPosition.quantity,
|
|
26
|
+
}), totalAmountOfItems));
|
|
27
|
+
let amountLeft = totalAmountOfItems;
|
|
28
|
+
params.discounts.forEach(({ configuration, discountId }) => {
|
|
29
|
+
const leftInItemsToSplit = calcUtils.calculateAmountToSplit({ ...configuration }, totalAmountOfItems);
|
|
30
|
+
const [itemsDiscountAmount, itemsTaxAmount] = calcUtils.applyDiscountToMultipleShares(itemShares, Math.max(0, Math.min(amountLeft, leftInItemsToSplit)));
|
|
31
|
+
amountLeft -= itemsDiscountAmount;
|
|
32
|
+
const discountAmount = itemsDiscountAmount * -1;
|
|
33
|
+
const taxAmount = itemsTaxAmount * -1;
|
|
34
|
+
if (discountAmount) {
|
|
35
|
+
pricingAdapter.resultSheet().addDiscount({
|
|
36
|
+
amount: discountAmount,
|
|
37
|
+
taxAmount,
|
|
38
|
+
discountId,
|
|
39
|
+
meta: {
|
|
40
|
+
adapter: OrderItemsDiscount.key,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return pricingAdapter.calculate();
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
OrderPricingDirector.registerAdapter(OrderItemsDiscount);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { OrderPricingDirector, OrderPricingAdapter, ProductPricingSheet, } from '@unchainedshop/core';
|
|
2
|
+
export const OrderItems = {
|
|
3
|
+
...OrderPricingAdapter,
|
|
4
|
+
key: 'shop.unchained.pricing.order-items',
|
|
5
|
+
version: '1.0.0',
|
|
6
|
+
label: 'Add Total Value Of Goods to Order',
|
|
7
|
+
orderIndex: 0,
|
|
8
|
+
isActivatedFor: () => {
|
|
9
|
+
return true;
|
|
10
|
+
},
|
|
11
|
+
actions: (params) => {
|
|
12
|
+
const pricingAdapter = OrderPricingAdapter.actions(params);
|
|
13
|
+
const { order, orderPositions } = params.context;
|
|
14
|
+
return {
|
|
15
|
+
...pricingAdapter,
|
|
16
|
+
calculate: async () => {
|
|
17
|
+
const totalAndTaxesOfAllItems = orderPositions.reduce((current, orderPosition) => {
|
|
18
|
+
const pricing = ProductPricingSheet({
|
|
19
|
+
calculation: orderPosition.calculation,
|
|
20
|
+
currencyCode: order.currencyCode,
|
|
21
|
+
quantity: orderPosition.quantity,
|
|
22
|
+
});
|
|
23
|
+
const tax = pricing.taxSum();
|
|
24
|
+
const items = pricing.gross();
|
|
25
|
+
return {
|
|
26
|
+
taxes: current.taxes + tax,
|
|
27
|
+
items: current.items + items,
|
|
28
|
+
};
|
|
29
|
+
}, {
|
|
30
|
+
taxes: 0,
|
|
31
|
+
items: 0,
|
|
32
|
+
});
|
|
33
|
+
pricingAdapter.resultSheet().addItems({
|
|
34
|
+
amount: totalAndTaxesOfAllItems.items,
|
|
35
|
+
taxAmount: totalAndTaxesOfAllItems.taxes,
|
|
36
|
+
meta: { adapter: OrderItems.key },
|
|
37
|
+
});
|
|
38
|
+
return pricingAdapter.calculate();
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
OrderPricingDirector.registerAdapter(OrderItems);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { OrderPricingDirector, OrderPricingAdapter, PaymentPricingSheet, } from '@unchainedshop/core';
|
|
2
|
+
export const OrderPayment = {
|
|
3
|
+
...OrderPricingAdapter,
|
|
4
|
+
key: 'shop.unchained.pricing.order-payment',
|
|
5
|
+
version: '1.0.0',
|
|
6
|
+
label: 'Add Payment Fees to Order',
|
|
7
|
+
orderIndex: 10,
|
|
8
|
+
isActivatedFor: () => {
|
|
9
|
+
return true;
|
|
10
|
+
},
|
|
11
|
+
actions: (params) => {
|
|
12
|
+
const pricingAdapter = OrderPricingAdapter.actions(params);
|
|
13
|
+
const { order, orderPayment } = params.context;
|
|
14
|
+
return {
|
|
15
|
+
...pricingAdapter,
|
|
16
|
+
calculate: async () => {
|
|
17
|
+
if (!orderPayment)
|
|
18
|
+
return null;
|
|
19
|
+
const pricing = PaymentPricingSheet({
|
|
20
|
+
calculation: orderPayment.calculation,
|
|
21
|
+
currencyCode: order.currencyCode,
|
|
22
|
+
});
|
|
23
|
+
const tax = pricing.taxSum();
|
|
24
|
+
const paymentFees = pricing.gross();
|
|
25
|
+
pricingAdapter
|
|
26
|
+
.resultSheet()
|
|
27
|
+
.addPayment({ amount: paymentFees, taxAmount: tax, meta: { adapter: OrderPayment.key } });
|
|
28
|
+
return pricingAdapter.calculate();
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
OrderPricingDirector.registerAdapter(OrderPayment);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type IOrderPricingAdapter } from '@unchainedshop/core';
|
|
2
|
+
interface PriceRoundSettings {
|
|
3
|
+
defaultPrecision: number;
|
|
4
|
+
roundTo: (value: number, precision: number, currencyCode: string) => number;
|
|
5
|
+
}
|
|
6
|
+
export declare const OrderPriceRound: IOrderPricingAdapter & {
|
|
7
|
+
configure: (params: PriceRoundSettings) => void;
|
|
8
|
+
settings: PriceRoundSettings;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { OrderPricingAdapter, OrderPricingDirector, OrderPricingRowCategory, } from '@unchainedshop/core';
|
|
2
|
+
const calculateDifference = (amount, currencyCode) => {
|
|
3
|
+
const roundedAmount = OrderPriceRound.settings.roundTo(amount, OrderPriceRound.settings.defaultPrecision, currencyCode);
|
|
4
|
+
return roundedAmount - amount;
|
|
5
|
+
};
|
|
6
|
+
export const OrderPriceRound = {
|
|
7
|
+
...OrderPricingAdapter,
|
|
8
|
+
key: 'shop.unchained.pricing.order-round',
|
|
9
|
+
version: '1.0.0',
|
|
10
|
+
label: 'Round order price to the next precision number',
|
|
11
|
+
orderIndex: 90,
|
|
12
|
+
isActivatedFor: () => {
|
|
13
|
+
return true;
|
|
14
|
+
},
|
|
15
|
+
settings: {
|
|
16
|
+
defaultPrecision: 5,
|
|
17
|
+
roundTo: (value, precision) => precision !== 0 ? Math.round(value / precision) * precision : value,
|
|
18
|
+
},
|
|
19
|
+
configure({ defaultPrecision, roundTo }) {
|
|
20
|
+
if (defaultPrecision)
|
|
21
|
+
this.settings.defaultPrecision = defaultPrecision;
|
|
22
|
+
if (roundTo)
|
|
23
|
+
this.settings.roundTo = roundTo;
|
|
24
|
+
},
|
|
25
|
+
actions: (params) => {
|
|
26
|
+
const pricingAdapter = OrderPricingAdapter.actions(params);
|
|
27
|
+
return {
|
|
28
|
+
...pricingAdapter,
|
|
29
|
+
calculate: async () => {
|
|
30
|
+
const { currencyCode } = params.context;
|
|
31
|
+
if (!currencyCode)
|
|
32
|
+
return pricingAdapter.calculate();
|
|
33
|
+
const { amount: deliveryAmount } = params.calculationSheet.total({
|
|
34
|
+
category: OrderPricingRowCategory.Delivery,
|
|
35
|
+
useNetPrice: true,
|
|
36
|
+
});
|
|
37
|
+
if (deliveryAmount) {
|
|
38
|
+
const taxes = params.calculationSheet.taxSum({
|
|
39
|
+
baseCategory: OrderPricingRowCategory.Delivery,
|
|
40
|
+
});
|
|
41
|
+
const deliveryTaxRate = taxes / deliveryAmount;
|
|
42
|
+
const deliveryDifference = calculateDifference(deliveryAmount, currencyCode);
|
|
43
|
+
pricingAdapter.resultSheet().addDelivery({
|
|
44
|
+
amount: deliveryDifference,
|
|
45
|
+
taxAmount: deliveryTaxRate * deliveryDifference,
|
|
46
|
+
meta: {
|
|
47
|
+
adapter: OrderPriceRound.key,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const { amount: discountAmount } = params.calculationSheet.total({
|
|
52
|
+
category: OrderPricingRowCategory.Discounts,
|
|
53
|
+
useNetPrice: true,
|
|
54
|
+
});
|
|
55
|
+
if (discountAmount) {
|
|
56
|
+
const taxes = params.calculationSheet.taxSum({
|
|
57
|
+
baseCategory: OrderPricingRowCategory.Discounts,
|
|
58
|
+
});
|
|
59
|
+
const discountTaxRate = taxes / discountAmount;
|
|
60
|
+
const discountsDifference = calculateDifference(discountAmount, currencyCode);
|
|
61
|
+
pricingAdapter.resultSheet().addDiscount({
|
|
62
|
+
amount: discountsDifference,
|
|
63
|
+
taxAmount: discountsDifference * discountTaxRate,
|
|
64
|
+
meta: {
|
|
65
|
+
adapter: OrderPriceRound.key,
|
|
66
|
+
},
|
|
67
|
+
discountId: null,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const { amount: itemsAmount } = params.calculationSheet.total({
|
|
71
|
+
category: OrderPricingRowCategory.Items,
|
|
72
|
+
useNetPrice: true,
|
|
73
|
+
});
|
|
74
|
+
if (itemsAmount) {
|
|
75
|
+
const taxes = params.calculationSheet.taxSum({
|
|
76
|
+
baseCategory: OrderPricingRowCategory.Items,
|
|
77
|
+
});
|
|
78
|
+
const itemTaxRate = taxes / itemsAmount;
|
|
79
|
+
const itemsDifference = calculateDifference(itemsAmount, currencyCode);
|
|
80
|
+
pricingAdapter.resultSheet().addItems({
|
|
81
|
+
amount: itemsDifference,
|
|
82
|
+
taxAmount: itemsDifference * itemTaxRate,
|
|
83
|
+
meta: {
|
|
84
|
+
adapter: OrderPriceRound.key,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const { amount: paymentAmount } = params.calculationSheet.total({
|
|
89
|
+
category: OrderPricingRowCategory.Payment,
|
|
90
|
+
useNetPrice: true,
|
|
91
|
+
});
|
|
92
|
+
if (paymentAmount) {
|
|
93
|
+
const taxes = params.calculationSheet.taxSum({
|
|
94
|
+
baseCategory: OrderPricingRowCategory.Payment,
|
|
95
|
+
});
|
|
96
|
+
const paymentTaxRate = taxes / paymentAmount;
|
|
97
|
+
const paymentsDifference = calculateDifference(paymentAmount, currencyCode);
|
|
98
|
+
pricingAdapter.resultSheet().addPayment({
|
|
99
|
+
amount: paymentsDifference,
|
|
100
|
+
taxAmount: paymentsDifference * paymentTaxRate,
|
|
101
|
+
meta: {
|
|
102
|
+
adapter: OrderPriceRound.key,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
const priorTaxesAmount = params.calculationSheet.taxSum({
|
|
107
|
+
category: OrderPricingRowCategory.Taxes,
|
|
108
|
+
});
|
|
109
|
+
const additionalRoundedTaxes = pricingAdapter.resultSheet().taxSum({
|
|
110
|
+
category: OrderPricingRowCategory.Taxes,
|
|
111
|
+
});
|
|
112
|
+
const taxesAmount = priorTaxesAmount + additionalRoundedTaxes;
|
|
113
|
+
if (taxesAmount) {
|
|
114
|
+
const taxDifference = calculateDifference(taxesAmount, currencyCode);
|
|
115
|
+
pricingAdapter.resultSheet().calculation.push({
|
|
116
|
+
category: OrderPricingRowCategory.Taxes,
|
|
117
|
+
amount: taxDifference,
|
|
118
|
+
meta: {
|
|
119
|
+
adapter: OrderPriceRound.key,
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
pricingAdapter.resultSheet().calculation.push({
|
|
123
|
+
category: null,
|
|
124
|
+
amount: taxDifference,
|
|
125
|
+
meta: {
|
|
126
|
+
adapter: OrderPriceRound.key,
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return pricingAdapter.calculate();
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
OrderPricingDirector.registerAdapter(OrderPriceRound);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ProductPricingDirector, ProductPricingAdapter, } from '@unchainedshop/core';
|
|
2
|
+
export const ProductPriceOptions = {
|
|
3
|
+
...ProductPricingAdapter,
|
|
4
|
+
key: 'shop.unchained.pricing.product-price-options',
|
|
5
|
+
version: '1.0',
|
|
6
|
+
label: 'Add Gross Price of Options',
|
|
7
|
+
orderIndex: 1,
|
|
8
|
+
isActivatedFor: () => {
|
|
9
|
+
return true;
|
|
10
|
+
},
|
|
11
|
+
actions: (params) => {
|
|
12
|
+
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
13
|
+
const { countryCode, currencyCode, quantity, modules } = params.context;
|
|
14
|
+
return {
|
|
15
|
+
...pricingAdapter,
|
|
16
|
+
async calculatePriceForProduct(product) {
|
|
17
|
+
const price = await modules.products.prices.price(product, {
|
|
18
|
+
countryCode,
|
|
19
|
+
currencyCode,
|
|
20
|
+
quantity,
|
|
21
|
+
});
|
|
22
|
+
if (price) {
|
|
23
|
+
const itemTotal = price.amount * quantity;
|
|
24
|
+
pricingAdapter.resultSheet().addItem({
|
|
25
|
+
amount: itemTotal,
|
|
26
|
+
isTaxable: Boolean(price.isTaxable),
|
|
27
|
+
isNetPrice: Boolean(price.isNetPrice),
|
|
28
|
+
meta: { adapter: ProductPriceOptions.key },
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
async calculate() {
|
|
33
|
+
const { configuration } = params.context;
|
|
34
|
+
const productIds = configuration?.flatMap(({ key, value }) => {
|
|
35
|
+
if (key === 'option')
|
|
36
|
+
return [value];
|
|
37
|
+
return [];
|
|
38
|
+
});
|
|
39
|
+
if (!productIds?.length) {
|
|
40
|
+
return pricingAdapter.calculate();
|
|
41
|
+
}
|
|
42
|
+
const options = await modules.products.findProducts({
|
|
43
|
+
productIds,
|
|
44
|
+
});
|
|
45
|
+
await Promise.all(options.map(this.calculatePriceForProduct));
|
|
46
|
+
return pricingAdapter.calculate();
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
ProductPricingDirector.registerAdapter(ProductPriceOptions);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ProductPricingDirector, ProductPricingAdapter, } from '@unchainedshop/core';
|
|
2
|
+
import { ProductType } from '@unchainedshop/core-products';
|
|
3
|
+
export const ProductPrice = {
|
|
4
|
+
...ProductPricingAdapter,
|
|
5
|
+
key: 'shop.unchained.pricing.product-price',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
label: 'Add Gross Price to Product',
|
|
8
|
+
orderIndex: 0,
|
|
9
|
+
isActivatedFor: () => {
|
|
10
|
+
return true;
|
|
11
|
+
},
|
|
12
|
+
actions: (params) => {
|
|
13
|
+
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
14
|
+
return {
|
|
15
|
+
...pricingAdapter,
|
|
16
|
+
calculate: async () => {
|
|
17
|
+
const { product, countryCode, currencyCode, quantity, modules } = params.context;
|
|
18
|
+
const price = await modules.products.prices.price(product, {
|
|
19
|
+
countryCode,
|
|
20
|
+
currencyCode,
|
|
21
|
+
quantity,
|
|
22
|
+
});
|
|
23
|
+
if (price) {
|
|
24
|
+
const itemTotal = price.amount * quantity;
|
|
25
|
+
pricingAdapter.resultSheet().addItem({
|
|
26
|
+
amount: itemTotal,
|
|
27
|
+
isTaxable: Boolean(price.isTaxable),
|
|
28
|
+
isNetPrice: Boolean(price.isNetPrice),
|
|
29
|
+
meta: { adapter: ProductPrice.key },
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
else if (product.type === ProductType.BUNDLE_PRODUCT) {
|
|
33
|
+
for (const bundleItem of product.bundleItems || []) {
|
|
34
|
+
const bundledProduct = await modules.products.findProduct({
|
|
35
|
+
productId: bundleItem.productId,
|
|
36
|
+
});
|
|
37
|
+
if (bundledProduct) {
|
|
38
|
+
const bundleItemPrice = await modules.products.prices.price(bundledProduct, {
|
|
39
|
+
countryCode,
|
|
40
|
+
currencyCode,
|
|
41
|
+
quantity: bundleItem.quantity * quantity,
|
|
42
|
+
});
|
|
43
|
+
if (bundleItemPrice) {
|
|
44
|
+
const bundleItemTotal = bundleItemPrice.amount * bundleItem.quantity * quantity;
|
|
45
|
+
pricingAdapter.resultSheet().addItem({
|
|
46
|
+
amount: bundleItemTotal,
|
|
47
|
+
isTaxable: Boolean(bundleItemPrice.isTaxable),
|
|
48
|
+
isNetPrice: Boolean(bundleItemPrice.isNetPrice),
|
|
49
|
+
meta: { adapter: ProductPrice.key },
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return pricingAdapter.calculate();
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
ProductPricingDirector.registerAdapter(ProductPrice);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { calculation as calcUtils } from '@unchainedshop/utils';
|
|
2
|
+
import { ProductPricingDirector, ProductPricingAdapter, ProductPricingRowCategory, } from '@unchainedshop/core';
|
|
3
|
+
export const ProductDiscount = {
|
|
4
|
+
...ProductPricingAdapter,
|
|
5
|
+
key: 'shop.unchained.pricing.product-discount',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
label: 'Apply Discounts on Product Price',
|
|
8
|
+
orderIndex: 30,
|
|
9
|
+
isActivatedFor: () => {
|
|
10
|
+
return true;
|
|
11
|
+
},
|
|
12
|
+
actions: (params) => {
|
|
13
|
+
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
14
|
+
const addDiscounts = (discount, total, resolvedConfiguration) => {
|
|
15
|
+
const { discountId } = discount;
|
|
16
|
+
const { isNetPrice = false, taxRate, ...meta } = resolvedConfiguration;
|
|
17
|
+
const amount = calcUtils.applyRate(resolvedConfiguration, total);
|
|
18
|
+
const isTaxable = taxRate === undefined || taxRate === null;
|
|
19
|
+
pricingAdapter.resultSheet().addDiscount({
|
|
20
|
+
amount: amount * -1,
|
|
21
|
+
discountId,
|
|
22
|
+
isNetPrice,
|
|
23
|
+
isTaxable,
|
|
24
|
+
meta: { adapter: ProductDiscount.key, ...meta },
|
|
25
|
+
});
|
|
26
|
+
if (!isTaxable && taxRate) {
|
|
27
|
+
const taxAmount = calcUtils.getTaxAmount(amount, taxRate, isNetPrice);
|
|
28
|
+
pricingAdapter.resultSheet().addTax({
|
|
29
|
+
amount: taxAmount * -1,
|
|
30
|
+
rate: taxRate,
|
|
31
|
+
discountId,
|
|
32
|
+
baseCategory: ProductPricingRowCategory.Discount,
|
|
33
|
+
meta: { adapter: ProductDiscount.key, discountId, ...meta },
|
|
34
|
+
});
|
|
35
|
+
if (!isNetPrice) {
|
|
36
|
+
pricingAdapter.resultSheet().addDiscount({
|
|
37
|
+
amount: taxAmount,
|
|
38
|
+
discountId,
|
|
39
|
+
isNetPrice: false,
|
|
40
|
+
isTaxable: false,
|
|
41
|
+
meta: { adapter: ProductDiscount.key, discountId, ...meta },
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
...pricingAdapter,
|
|
48
|
+
calculate: async () => {
|
|
49
|
+
params.discounts.forEach((discount) => {
|
|
50
|
+
if (!discount)
|
|
51
|
+
return;
|
|
52
|
+
const { configuration } = discount;
|
|
53
|
+
const resolvedConfiguration = configuration.customPriceConfigurationResolver
|
|
54
|
+
? configuration.customPriceConfigurationResolver(params.context.product, params.context.quantity, params.context.configuration)
|
|
55
|
+
: configuration;
|
|
56
|
+
if (!resolvedConfiguration)
|
|
57
|
+
return;
|
|
58
|
+
const total = params.calculationSheet.total({
|
|
59
|
+
category: ProductPricingRowCategory.Item,
|
|
60
|
+
useNetPrice: resolvedConfiguration.isNetPrice,
|
|
61
|
+
});
|
|
62
|
+
addDiscounts(discount, total.amount, resolvedConfiguration);
|
|
63
|
+
});
|
|
64
|
+
return pricingAdapter.calculate();
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
ProductPricingDirector.registerAdapter(ProductDiscount);
|