@unchainedshop/plugins 4.6.2 → 4.7.2
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 +0 -2
- package/lib/events/node-event-emitter.d.ts +3 -1
- package/lib/events/node-event-emitter.js +3 -3
- package/lib/files/gridfs/adapter.d.ts +2 -2
- package/lib/files/gridfs/adapter.js +2 -5
- package/lib/files/gridfs/index.d.ts +5 -4
- package/lib/files/gridfs/index.js +30 -3
- package/lib/files/minio/index.d.ts +4 -5
- package/lib/files/minio/index.js +18 -157
- package/lib/payment/apple-iap/adapter.d.ts +2 -1
- package/lib/payment/apple-iap/adapter.js +2 -3
- package/lib/payment/apple-iap/index.d.ts +6 -4
- package/lib/payment/apple-iap/index.js +28 -3
- package/lib/payment/cryptopay/index.d.ts +5 -4
- package/lib/payment/cryptopay/index.js +31 -3
- package/lib/payment/datatrans-v2/index.d.ts +4 -1
- package/lib/payment/datatrans-v2/index.js +17 -400
- package/lib/payment/payrexx/index.d.ts +4 -1
- package/lib/payment/payrexx/index.js +19 -158
- package/lib/payment/postfinance-checkout/index.d.ts +5 -0
- package/lib/payment/postfinance-checkout/index.js +25 -186
- package/lib/payment/saferpay/adapter.js +1 -2
- package/lib/payment/saferpay/index.d.ts +5 -4
- package/lib/payment/saferpay/index.js +29 -3
- package/lib/payment/stripe/index.d.ts +4 -1
- package/lib/payment/stripe/index.js +22 -116
- package/lib/payment/stripe/stripe.js +2 -5
- package/lib/presets/all.d.ts +1 -70
- package/lib/presets/all.js +41 -27
- package/lib/presets/base.d.ts +1 -25
- package/lib/presets/base.js +56 -25
- package/lib/presets/countries/ch.d.ts +1 -2
- package/lib/presets/countries/ch.js +7 -2
- package/lib/presets/crypto.d.ts +3 -7
- package/lib/presets/crypto.js +18 -7
- package/package.json +15 -10
- package/lib/delivery/post.d.ts +0 -1
- package/lib/delivery/post.js +0 -23
- package/lib/delivery/send-message.d.ts +0 -1
- package/lib/delivery/send-message.js +0 -40
- package/lib/delivery/stores.d.ts +0 -1
- package/lib/delivery/stores.js +0 -43
- package/lib/enrollments/licensed.d.ts +0 -4
- package/lib/enrollments/licensed.js +0 -52
- package/lib/files/gridfs/handler-express.d.ts +0 -9
- package/lib/files/gridfs/handler-express.js +0 -110
- package/lib/files/gridfs/handler-fastify.d.ts +0 -3
- package/lib/files/gridfs/handler-fastify.js +0 -138
- package/lib/files/minio/handler-express.d.ts +0 -2
- package/lib/files/minio/handler-express.js +0 -36
- package/lib/files/minio/handler-fastify.d.ts +0 -3
- package/lib/files/minio/handler-fastify.js +0 -40
- package/lib/filters/local-search.d.ts +0 -3
- package/lib/filters/local-search.js +0 -66
- package/lib/filters/strict-equal.d.ts +0 -1
- package/lib/filters/strict-equal.js +0 -24
- package/lib/payment/apple-iap/handler-express.d.ts +0 -2
- package/lib/payment/apple-iap/handler-express.js +0 -103
- package/lib/payment/apple-iap/handler-fastify.d.ts +0 -3
- package/lib/payment/apple-iap/handler-fastify.js +0 -102
- package/lib/payment/braintree.d.ts +0 -1
- package/lib/payment/braintree.js +0 -138
- package/lib/payment/cryptopay/handler-express.d.ts +0 -2
- package/lib/payment/cryptopay/handler-express.js +0 -19
- package/lib/payment/cryptopay/handler-fastify.d.ts +0 -3
- package/lib/payment/cryptopay/handler-fastify.js +0 -17
- package/lib/payment/cryptopay/plugin.d.ts +0 -3
- package/lib/payment/cryptopay/plugin.js +0 -159
- package/lib/payment/datatrans-v2/handler-express.d.ts +0 -1
- package/lib/payment/datatrans-v2/handler-express.js +0 -71
- package/lib/payment/datatrans-v2/handler-fastify.d.ts +0 -2
- package/lib/payment/datatrans-v2/handler-fastify.js +0 -71
- package/lib/payment/invoice-prepaid.d.ts +0 -1
- package/lib/payment/invoice-prepaid.js +0 -30
- package/lib/payment/invoice.d.ts +0 -1
- package/lib/payment/invoice.js +0 -27
- package/lib/payment/paypal-checkout.d.ts +0 -1
- package/lib/payment/paypal-checkout.js +0 -87
- package/lib/payment/payrexx/handler-express.d.ts +0 -1
- package/lib/payment/payrexx/handler-express.js +0 -85
- package/lib/payment/payrexx/handler-fastify.d.ts +0 -2
- package/lib/payment/payrexx/handler-fastify.js +0 -91
- package/lib/payment/postfinance-checkout/handler-express.d.ts +0 -1
- package/lib/payment/postfinance-checkout/handler-express.js +0 -37
- package/lib/payment/postfinance-checkout/handler-fastify.d.ts +0 -2
- package/lib/payment/postfinance-checkout/handler-fastify.js +0 -40
- package/lib/payment/saferpay/handler-express.d.ts +0 -1
- package/lib/payment/saferpay/handler-express.js +0 -59
- package/lib/payment/saferpay/handler-fastify.d.ts +0 -2
- package/lib/payment/saferpay/handler-fastify.js +0 -62
- package/lib/payment/stripe/handler-express.d.ts +0 -5
- package/lib/payment/stripe/handler-express.js +0 -121
- package/lib/payment/stripe/handler-fastify.d.ts +0 -6
- package/lib/payment/stripe/handler-fastify.js +0 -131
- package/lib/presets/all-express.d.ts +0 -6
- package/lib/presets/all-express.js +0 -26
- package/lib/presets/all-fastify.d.ts +0 -6
- package/lib/presets/all-fastify.js +0 -49
- package/lib/presets/base-express.d.ts +0 -2
- package/lib/presets/base-express.js +0 -5
- package/lib/presets/base-fastify.d.ts +0 -3
- package/lib/presets/base-fastify.js +0 -16
- package/lib/presets/crypto-express.d.ts +0 -3
- package/lib/presets/crypto-express.js +0 -8
- package/lib/presets/crypto-fastify.d.ts +0 -3
- package/lib/presets/crypto-fastify.js +0 -11
- package/lib/pricing/delivery-swiss-tax.d.ts +0 -2
- package/lib/pricing/delivery-swiss-tax.js +0 -62
- package/lib/pricing/discount-100-off.d.ts +0 -2
- package/lib/pricing/discount-100-off.js +0 -30
- package/lib/pricing/discount-half-price-manual.d.ts +0 -2
- package/lib/pricing/discount-half-price-manual.js +0 -30
- package/lib/pricing/discount-half-price.d.ts +0 -2
- package/lib/pricing/discount-half-price.js +0 -33
- package/lib/pricing/free-delivery.d.ts +0 -2
- package/lib/pricing/free-delivery.js +0 -27
- package/lib/pricing/free-payment.d.ts +0 -2
- package/lib/pricing/free-payment.js +0 -27
- package/lib/pricing/order-delivery.d.ts +0 -2
- package/lib/pricing/order-delivery.js +0 -33
- package/lib/pricing/order-discount.d.ts +0 -2
- package/lib/pricing/order-discount.js +0 -74
- package/lib/pricing/order-items-discount.d.ts +0 -2
- package/lib/pricing/order-items-discount.js +0 -50
- package/lib/pricing/order-items.d.ts +0 -2
- package/lib/pricing/order-items.js +0 -43
- package/lib/pricing/order-payment.d.ts +0 -2
- package/lib/pricing/order-payment.js +0 -33
- package/lib/pricing/order-round.d.ts +0 -10
- package/lib/pricing/order-round.js +0 -135
- package/lib/pricing/product-catalog-price-options.d.ts +0 -2
- package/lib/pricing/product-catalog-price-options.js +0 -51
- package/lib/pricing/product-catalog-price.d.ts +0 -2
- package/lib/pricing/product-catalog-price.js +0 -60
- package/lib/pricing/product-discount.d.ts +0 -2
- package/lib/pricing/product-discount.js +0 -69
- package/lib/pricing/product-price-rateconversion.d.ts +0 -2
- package/lib/pricing/product-price-rateconversion.js +0 -53
- package/lib/pricing/product-round.d.ts +0 -10
- package/lib/pricing/product-round.js +0 -44
- package/lib/pricing/product-swiss-tax.d.ts +0 -2
- package/lib/pricing/product-swiss-tax.js +0 -76
- package/lib/quotations/manual.d.ts +0 -1
- package/lib/quotations/manual.js +0 -20
- package/lib/warehousing/eth-minter.d.ts +0 -1
- package/lib/warehousing/eth-minter.js +0 -120
- package/lib/warehousing/store.d.ts +0 -1
- package/lib/warehousing/store.js +0 -34
- package/lib/worker/budgetsms.d.ts +0 -9
- package/lib/worker/budgetsms.js +0 -169
- package/lib/worker/bulk-export.d.ts +0 -2
- package/lib/worker/bulk-export.js +0 -64
- package/lib/worker/bulk-import.d.ts +0 -2
- package/lib/worker/bulk-import.js +0 -65
- package/lib/worker/bulkgate.d.ts +0 -1
- package/lib/worker/bulkgate.js +0 -91
- package/lib/worker/email.d.ts +0 -1
- package/lib/worker/email.js +0 -136
- package/lib/worker/enrollment-order-generator.d.ts +0 -1
- package/lib/worker/enrollment-order-generator.js +0 -77
- package/lib/worker/error-notifications.d.ts +0 -9
- package/lib/worker/error-notifications.js +0 -61
- package/lib/worker/export-token.d.ts +0 -4
- package/lib/worker/export-token.js +0 -26
- package/lib/worker/external.d.ts +0 -2
- package/lib/worker/external.js +0 -13
- package/lib/worker/heartbeat.d.ts +0 -1
- package/lib/worker/heartbeat.js +0 -26
- package/lib/worker/http-request.d.ts +0 -8
- package/lib/worker/http-request.js +0 -56
- package/lib/worker/message.d.ts +0 -10
- package/lib/worker/message.js +0 -42
- package/lib/worker/push-notification.d.ts +0 -1
- package/lib/worker/push-notification.js +0 -87
- package/lib/worker/twilio.d.ts +0 -1
- package/lib/worker/twilio.js +0 -59
- package/lib/worker/update-coinbase-rates.d.ts +0 -1
- package/lib/worker/update-coinbase-rates.js +0 -59
- package/lib/worker/update-ecb-rates.d.ts +0 -1
- package/lib/worker/update-ecb-rates.js +0 -92
- package/lib/worker/update-token-ownership.d.ts +0 -3
- package/lib/worker/update-token-ownership.js +0 -57
- package/lib/worker/zombie-killer.d.ts +0 -13
- package/lib/worker/zombie-killer.js +0 -91
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { DeliveryPricingRowCategory, DeliveryPricingAdapter, DeliveryPricingDirector, } from '@unchainedshop/core';
|
|
2
|
-
import { resolveTaxCategoryFromDeliveryProvider, SwissTaxCategories } from "./tax/ch.js";
|
|
3
|
-
import isDeliveryAddressInCountry from "./utils/isDeliveryAddressInCountry.js";
|
|
4
|
-
export const DeliverySwissTax = {
|
|
5
|
-
...DeliveryPricingAdapter,
|
|
6
|
-
key: 'shop.unchained.pricing.delivery-swiss-tax',
|
|
7
|
-
version: '1.0.0',
|
|
8
|
-
label: 'Apply Swiss Tax on Delivery Fees',
|
|
9
|
-
orderIndex: 80,
|
|
10
|
-
isActivatedFor: (context) => {
|
|
11
|
-
if (!context.order)
|
|
12
|
-
return false;
|
|
13
|
-
if (!context.orderDelivery)
|
|
14
|
-
return false;
|
|
15
|
-
return isDeliveryAddressInCountry({
|
|
16
|
-
order: context.order,
|
|
17
|
-
orderDelivery: context.orderDelivery,
|
|
18
|
-
countryCode: context.countryCode,
|
|
19
|
-
}, ['CH', 'LI']);
|
|
20
|
-
},
|
|
21
|
-
actions: (params) => {
|
|
22
|
-
const pricingAdapter = DeliveryPricingAdapter.actions(params);
|
|
23
|
-
const { context } = params;
|
|
24
|
-
return {
|
|
25
|
-
...pricingAdapter,
|
|
26
|
-
calculate: async () => {
|
|
27
|
-
const taxCategory = resolveTaxCategoryFromDeliveryProvider(context.provider) || SwissTaxCategories.DEFAULT;
|
|
28
|
-
const taxRate = taxCategory.rate(context.order?.ordered);
|
|
29
|
-
DeliveryPricingAdapter.log(`DeliverySwissTax -> Tax Multiplicator: ${taxRate}`);
|
|
30
|
-
params.calculationSheet.filterBy({ isTaxable: true }).forEach(({ isNetPrice, ...row }) => {
|
|
31
|
-
if (!isNetPrice) {
|
|
32
|
-
const taxAmount = row.amount - row.amount / (1 + taxRate);
|
|
33
|
-
pricingAdapter.resultSheet().calculation.push({
|
|
34
|
-
...row,
|
|
35
|
-
amount: -taxAmount,
|
|
36
|
-
isTaxable: false,
|
|
37
|
-
isNetPrice: false,
|
|
38
|
-
meta: { adapter: DeliverySwissTax.key },
|
|
39
|
-
});
|
|
40
|
-
pricingAdapter.resultSheet().addTax({
|
|
41
|
-
amount: taxAmount,
|
|
42
|
-
rate: taxRate,
|
|
43
|
-
baseCategory: DeliveryPricingRowCategory.Delivery,
|
|
44
|
-
meta: { adapter: DeliverySwissTax.key },
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
const taxAmount = row.amount * taxRate;
|
|
49
|
-
pricingAdapter.resultSheet().addTax({
|
|
50
|
-
amount: taxAmount,
|
|
51
|
-
rate: taxRate,
|
|
52
|
-
baseCategory: DeliveryPricingRowCategory.Delivery,
|
|
53
|
-
meta: { adapter: DeliverySwissTax.key },
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
return pricingAdapter.calculate();
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
DeliveryPricingDirector.registerAdapter(DeliverySwissTax);
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { OrderDiscountDirector, OrderDiscountAdapter, } from '@unchainedshop/core';
|
|
2
|
-
export const HundredOff = {
|
|
3
|
-
...OrderDiscountAdapter,
|
|
4
|
-
key: 'shop.unchained.discount.100-off',
|
|
5
|
-
label: '100 Off',
|
|
6
|
-
version: '1.0.0',
|
|
7
|
-
orderIndex: 10,
|
|
8
|
-
isManualAdditionAllowed: async () => {
|
|
9
|
-
return true;
|
|
10
|
-
},
|
|
11
|
-
isManualRemovalAllowed: async () => {
|
|
12
|
-
return true;
|
|
13
|
-
},
|
|
14
|
-
actions: async ({ context }) => ({
|
|
15
|
-
...(await OrderDiscountAdapter.actions({ context })),
|
|
16
|
-
isValidForSystemTriggering: async () => {
|
|
17
|
-
return false;
|
|
18
|
-
},
|
|
19
|
-
isValidForCodeTriggering: async ({ code }) => {
|
|
20
|
-
return code.toUpperCase() === '100OFF';
|
|
21
|
-
},
|
|
22
|
-
discountForPricingAdapterKey: ({ pricingAdapterKey }) => {
|
|
23
|
-
if (pricingAdapterKey === 'shop.unchained.pricing.order-discount') {
|
|
24
|
-
return { fixedRate: 10000 };
|
|
25
|
-
}
|
|
26
|
-
return null;
|
|
27
|
-
},
|
|
28
|
-
}),
|
|
29
|
-
};
|
|
30
|
-
OrderDiscountDirector.registerAdapter(HundredOff);
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { OrderDiscountDirector, OrderDiscountAdapter, } from '@unchainedshop/core';
|
|
2
|
-
export const HalfPriceManual = {
|
|
3
|
-
...OrderDiscountAdapter,
|
|
4
|
-
key: 'shop.unchained.discount.half-price-manual',
|
|
5
|
-
label: 'Half Price Manual',
|
|
6
|
-
version: '1.0.0',
|
|
7
|
-
orderIndex: 10,
|
|
8
|
-
isManualAdditionAllowed: async () => {
|
|
9
|
-
return true;
|
|
10
|
-
},
|
|
11
|
-
isManualRemovalAllowed: async () => {
|
|
12
|
-
return true;
|
|
13
|
-
},
|
|
14
|
-
actions: async ({ context }) => ({
|
|
15
|
-
...(await OrderDiscountAdapter.actions({ context })),
|
|
16
|
-
isValidForSystemTriggering: async () => {
|
|
17
|
-
return false;
|
|
18
|
-
},
|
|
19
|
-
isValidForCodeTriggering: async ({ code }) => {
|
|
20
|
-
return code === 'HALFPRICE';
|
|
21
|
-
},
|
|
22
|
-
discountForPricingAdapterKey({ pricingAdapterKey }) {
|
|
23
|
-
if (pricingAdapterKey === 'shop.unchained.pricing.product-discount') {
|
|
24
|
-
return { rate: 0.5 };
|
|
25
|
-
}
|
|
26
|
-
return null;
|
|
27
|
-
},
|
|
28
|
-
}),
|
|
29
|
-
};
|
|
30
|
-
OrderDiscountDirector.registerAdapter(HalfPriceManual);
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { OrderDiscountDirector, OrderDiscountAdapter, } from '@unchainedshop/core';
|
|
2
|
-
export const HalfPrice = {
|
|
3
|
-
...OrderDiscountAdapter,
|
|
4
|
-
key: 'shop.unchained.discount.half-price',
|
|
5
|
-
label: 'Half Price',
|
|
6
|
-
version: '1.0.0',
|
|
7
|
-
orderIndex: 10,
|
|
8
|
-
isManualAdditionAllowed: async () => {
|
|
9
|
-
return false;
|
|
10
|
-
},
|
|
11
|
-
isManualRemovalAllowed: async () => {
|
|
12
|
-
return false;
|
|
13
|
-
},
|
|
14
|
-
actions: async ({ context }) => ({
|
|
15
|
-
...(await OrderDiscountAdapter.actions({ context })),
|
|
16
|
-
isValidForSystemTriggering: async () => {
|
|
17
|
-
const { order } = context;
|
|
18
|
-
const user = await context.modules.users.findUserById(order.userId);
|
|
19
|
-
const isUserEligibleForHalfPrice = user?.tags && user.tags.indexOf('half-price') !== -1;
|
|
20
|
-
return !!isUserEligibleForHalfPrice;
|
|
21
|
-
},
|
|
22
|
-
isValidForCodeTriggering: async () => {
|
|
23
|
-
return false;
|
|
24
|
-
},
|
|
25
|
-
discountForPricingAdapterKey({ pricingAdapterKey }) {
|
|
26
|
-
if (pricingAdapterKey === 'shop.unchained.pricing.product-discount') {
|
|
27
|
-
return { rate: 0.5 };
|
|
28
|
-
}
|
|
29
|
-
return null;
|
|
30
|
-
},
|
|
31
|
-
}),
|
|
32
|
-
};
|
|
33
|
-
OrderDiscountDirector.registerAdapter(HalfPrice);
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { DeliveryPricingAdapter, DeliveryPricingDirector, } from '@unchainedshop/core';
|
|
2
|
-
export const DeliveryFreePrice = {
|
|
3
|
-
...DeliveryPricingAdapter,
|
|
4
|
-
key: 'shop.unchained.pricing.delivery-free',
|
|
5
|
-
label: 'Free Delivery',
|
|
6
|
-
version: '1.0.0',
|
|
7
|
-
orderIndex: 0,
|
|
8
|
-
isActivatedFor: () => {
|
|
9
|
-
return true;
|
|
10
|
-
},
|
|
11
|
-
actions: (params) => {
|
|
12
|
-
const pricingAdapter = DeliveryPricingAdapter.actions(params);
|
|
13
|
-
return {
|
|
14
|
-
...pricingAdapter,
|
|
15
|
-
calculate: async () => {
|
|
16
|
-
pricingAdapter.resultSheet().addFee({
|
|
17
|
-
amount: 0,
|
|
18
|
-
isTaxable: false,
|
|
19
|
-
isNetPrice: false,
|
|
20
|
-
meta: { adapter: DeliveryFreePrice.key },
|
|
21
|
-
});
|
|
22
|
-
return pricingAdapter.calculate();
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
DeliveryPricingDirector.registerAdapter(DeliveryFreePrice);
|
|
@@ -1,27 +0,0 @@
|
|
|
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);
|
|
@@ -1,33 +0,0 @@
|
|
|
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);
|
|
@@ -1,74 +0,0 @@
|
|
|
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);
|
|
@@ -1,50 +0,0 @@
|
|
|
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);
|
|
@@ -1,43 +0,0 @@
|
|
|
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);
|
|
@@ -1,33 +0,0 @@
|
|
|
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);
|
|
@@ -1,10 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,135 +0,0 @@
|
|
|
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);
|