@unchainedshop/plugins 4.6.0 → 4.6.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.
Files changed (214) hide show
  1. package/lib/delivery/post/adapter.d.ts +2 -0
  2. package/lib/delivery/post/adapter.js +22 -0
  3. package/lib/delivery/post/index.d.ts +4 -0
  4. package/lib/delivery/post/index.js +10 -0
  5. package/lib/delivery/send-message/adapter.d.ts +2 -0
  6. package/lib/delivery/send-message/adapter.js +39 -0
  7. package/lib/delivery/send-message/index.d.ts +4 -0
  8. package/lib/delivery/send-message/index.js +10 -0
  9. package/lib/delivery/stores/adapter.d.ts +2 -0
  10. package/lib/delivery/stores/adapter.js +42 -0
  11. package/lib/delivery/stores/index.d.ts +4 -0
  12. package/lib/delivery/stores/index.js +10 -0
  13. package/lib/enrollments/licensed/adapter.d.ts +6 -0
  14. package/lib/enrollments/licensed/adapter.js +51 -0
  15. package/lib/enrollments/licensed/index.d.ts +4 -0
  16. package/lib/enrollments/licensed/index.js +10 -0
  17. package/lib/files/gridfs/api.d.ts +7 -0
  18. package/lib/files/gridfs/api.js +163 -0
  19. package/lib/files/minio/adapter.d.ts +4 -0
  20. package/lib/files/minio/adapter.js +160 -0
  21. package/lib/files/minio/api.d.ts +2 -0
  22. package/lib/files/minio/api.js +41 -0
  23. package/lib/files/temp-upload/api.d.ts +6 -0
  24. package/lib/files/temp-upload/api.js +49 -0
  25. package/lib/files/temp-upload/index.d.ts +3 -0
  26. package/lib/files/temp-upload/index.js +15 -0
  27. package/lib/filters/local-search/adapter.d.ts +2 -0
  28. package/lib/filters/local-search/adapter.js +56 -0
  29. package/lib/filters/local-search/index.d.ts +4 -0
  30. package/lib/filters/local-search/index.js +16 -0
  31. package/lib/filters/strict-equal/adapter.d.ts +2 -0
  32. package/lib/filters/strict-equal/adapter.js +23 -0
  33. package/lib/filters/strict-equal/index.d.ts +4 -0
  34. package/lib/filters/strict-equal/index.js +10 -0
  35. package/lib/payment/apple-iap/api.d.ts +2 -0
  36. package/lib/payment/apple-iap/api.js +119 -0
  37. package/lib/payment/cryptopay/adapter.d.ts +2 -0
  38. package/lib/payment/cryptopay/adapter.js +157 -0
  39. package/lib/payment/cryptopay/api.d.ts +2 -0
  40. package/lib/payment/cryptopay/api.js +23 -0
  41. package/lib/payment/datatrans-v2/adapter.d.ts +2 -0
  42. package/lib/payment/datatrans-v2/adapter.js +406 -0
  43. package/lib/payment/datatrans-v2/api.d.ts +2 -0
  44. package/lib/payment/datatrans-v2/api.js +108 -0
  45. package/lib/payment/invoice/adapter.d.ts +2 -0
  46. package/lib/payment/invoice/adapter.js +26 -0
  47. package/lib/payment/invoice/index.d.ts +4 -0
  48. package/lib/payment/invoice/index.js +10 -0
  49. package/lib/payment/invoice-prepaid/adapter.d.ts +2 -0
  50. package/lib/payment/invoice-prepaid/adapter.js +29 -0
  51. package/lib/payment/invoice-prepaid/index.d.ts +4 -0
  52. package/lib/payment/invoice-prepaid/index.js +10 -0
  53. package/lib/payment/payrexx/adapter.d.ts +2 -0
  54. package/lib/payment/payrexx/adapter.js +161 -0
  55. package/lib/payment/payrexx/api.d.ts +2 -0
  56. package/lib/payment/payrexx/api.js +97 -0
  57. package/lib/payment/postfinance-checkout/adapter.d.ts +2 -0
  58. package/lib/payment/postfinance-checkout/adapter.js +189 -0
  59. package/lib/payment/postfinance-checkout/webhook.d.ts +2 -0
  60. package/lib/payment/postfinance-checkout/webhook.js +48 -0
  61. package/lib/payment/saferpay/webhook.d.ts +2 -0
  62. package/lib/payment/saferpay/webhook.js +64 -0
  63. package/lib/payment/stripe/adapter.d.ts +2 -0
  64. package/lib/payment/stripe/adapter.js +121 -0
  65. package/lib/payment/stripe/api.d.ts +6 -0
  66. package/lib/payment/stripe/api.js +165 -0
  67. package/lib/payment/stripe/stripe.js +12 -10
  68. package/lib/presets/base.d.ts +1 -0
  69. package/lib/presets/base.js +1 -0
  70. package/lib/pricing/delivery-swiss-tax/adapter.d.ts +3 -0
  71. package/lib/pricing/delivery-swiss-tax/adapter.js +62 -0
  72. package/lib/pricing/delivery-swiss-tax/index.d.ts +4 -0
  73. package/lib/pricing/delivery-swiss-tax/index.js +10 -0
  74. package/lib/pricing/discount-100-off/adapter.d.ts +3 -0
  75. package/lib/pricing/discount-100-off/adapter.js +30 -0
  76. package/lib/pricing/discount-100-off/index.d.ts +4 -0
  77. package/lib/pricing/discount-100-off/index.js +10 -0
  78. package/lib/pricing/discount-half-price-manual/adapter.d.ts +3 -0
  79. package/lib/pricing/discount-half-price-manual/adapter.js +30 -0
  80. package/lib/pricing/discount-half-price-manual/index.d.ts +4 -0
  81. package/lib/pricing/discount-half-price-manual/index.js +10 -0
  82. package/lib/pricing/free-delivery/adapter.d.ts +3 -0
  83. package/lib/pricing/free-delivery/adapter.js +27 -0
  84. package/lib/pricing/free-delivery/index.d.ts +4 -0
  85. package/lib/pricing/free-delivery/index.js +10 -0
  86. package/lib/pricing/free-payment/adapter.d.ts +3 -0
  87. package/lib/pricing/free-payment/adapter.js +27 -0
  88. package/lib/pricing/free-payment/index.d.ts +4 -0
  89. package/lib/pricing/free-payment/index.js +10 -0
  90. package/lib/pricing/order-delivery/adapter.d.ts +3 -0
  91. package/lib/pricing/order-delivery/adapter.js +33 -0
  92. package/lib/pricing/order-delivery/index.d.ts +4 -0
  93. package/lib/pricing/order-delivery/index.js +10 -0
  94. package/lib/pricing/order-discount/adapter.d.ts +3 -0
  95. package/lib/pricing/order-discount/adapter.js +74 -0
  96. package/lib/pricing/order-discount/index.d.ts +4 -0
  97. package/lib/pricing/order-discount/index.js +10 -0
  98. package/lib/pricing/order-items/adapter.d.ts +3 -0
  99. package/lib/pricing/order-items/adapter.js +43 -0
  100. package/lib/pricing/order-items/index.d.ts +4 -0
  101. package/lib/pricing/order-items/index.js +10 -0
  102. package/lib/pricing/order-payment/adapter.d.ts +3 -0
  103. package/lib/pricing/order-payment/adapter.js +33 -0
  104. package/lib/pricing/order-payment/index.d.ts +4 -0
  105. package/lib/pricing/order-payment/index.js +10 -0
  106. package/lib/pricing/product-catalog-price/adapter.d.ts +3 -0
  107. package/lib/pricing/product-catalog-price/adapter.js +60 -0
  108. package/lib/pricing/product-catalog-price/index.d.ts +4 -0
  109. package/lib/pricing/product-catalog-price/index.js +10 -0
  110. package/lib/pricing/product-discount/adapter.d.ts +3 -0
  111. package/lib/pricing/product-discount/adapter.js +69 -0
  112. package/lib/pricing/product-discount/index.d.ts +4 -0
  113. package/lib/pricing/product-discount/index.js +10 -0
  114. package/lib/pricing/product-price-rateconversion/adapter.d.ts +3 -0
  115. package/lib/pricing/product-price-rateconversion/adapter.js +53 -0
  116. package/lib/pricing/product-price-rateconversion/index.d.ts +4 -0
  117. package/lib/pricing/product-price-rateconversion/index.js +10 -0
  118. package/lib/pricing/product-swiss-tax/adapter.d.ts +3 -0
  119. package/lib/pricing/product-swiss-tax/adapter.js +76 -0
  120. package/lib/pricing/product-swiss-tax/index.d.ts +4 -0
  121. package/lib/pricing/product-swiss-tax/index.js +10 -0
  122. package/lib/quotations/manual/adapter.d.ts +2 -0
  123. package/lib/quotations/manual/adapter.js +19 -0
  124. package/lib/quotations/manual/index.d.ts +4 -0
  125. package/lib/quotations/manual/index.js +10 -0
  126. package/lib/warehousing/erc-metadata/api.d.ts +12 -0
  127. package/lib/warehousing/erc-metadata/api.js +43 -0
  128. package/lib/warehousing/erc-metadata/index.d.ts +3 -0
  129. package/lib/warehousing/erc-metadata/index.js +15 -0
  130. package/lib/warehousing/eth-minter/adapter.d.ts +2 -0
  131. package/lib/warehousing/eth-minter/adapter.js +119 -0
  132. package/lib/warehousing/eth-minter/index.d.ts +4 -0
  133. package/lib/warehousing/eth-minter/index.js +10 -0
  134. package/lib/warehousing/store/adapter.d.ts +2 -0
  135. package/lib/warehousing/store/adapter.js +33 -0
  136. package/lib/warehousing/store/index.d.ts +4 -0
  137. package/lib/warehousing/store/index.js +10 -0
  138. package/lib/worker/budgetsms/adapter.d.ts +22 -0
  139. package/lib/worker/budgetsms/adapter.js +169 -0
  140. package/lib/worker/budgetsms/index.d.ts +4 -0
  141. package/lib/worker/budgetsms/index.js +10 -0
  142. package/lib/worker/bulk-export/adapter.d.ts +3 -0
  143. package/lib/worker/bulk-export/adapter.js +64 -0
  144. package/lib/worker/bulk-export/index.d.ts +4 -0
  145. package/lib/worker/bulk-export/index.js +10 -0
  146. package/lib/worker/bulk-export.d.ts +2 -0
  147. package/lib/worker/bulk-export.js +64 -0
  148. package/lib/worker/bulk-import/adapter.d.ts +3 -0
  149. package/lib/worker/bulk-import/adapter.js +65 -0
  150. package/lib/worker/bulk-import/api.d.ts +7 -0
  151. package/lib/worker/bulk-import/api.js +53 -0
  152. package/lib/worker/bulk-import/index.d.ts +4 -0
  153. package/lib/worker/bulk-import/index.js +18 -0
  154. package/lib/worker/bulkgate/adapter.d.ts +12 -0
  155. package/lib/worker/bulkgate/adapter.js +91 -0
  156. package/lib/worker/bulkgate/index.d.ts +4 -0
  157. package/lib/worker/bulkgate/index.js +10 -0
  158. package/lib/worker/email/adapter.d.ts +9 -0
  159. package/lib/worker/email/adapter.js +150 -0
  160. package/lib/worker/email/index.d.ts +4 -0
  161. package/lib/worker/email/index.js +10 -0
  162. package/lib/worker/enrollment-order-generator/adapter.d.ts +4 -0
  163. package/lib/worker/enrollment-order-generator/adapter.js +77 -0
  164. package/lib/worker/enrollment-order-generator/index.d.ts +4 -0
  165. package/lib/worker/enrollment-order-generator/index.js +13 -0
  166. package/lib/worker/error-notifications/adapter.d.ts +10 -0
  167. package/lib/worker/error-notifications/adapter.js +62 -0
  168. package/lib/worker/error-notifications/index.d.ts +4 -0
  169. package/lib/worker/error-notifications/index.js +13 -0
  170. package/lib/worker/export-token/adapter.d.ts +4 -0
  171. package/lib/worker/export-token/adapter.js +25 -0
  172. package/lib/worker/export-token/index.d.ts +4 -0
  173. package/lib/worker/export-token/index.js +13 -0
  174. package/lib/worker/external/adapter.d.ts +3 -0
  175. package/lib/worker/external/adapter.js +13 -0
  176. package/lib/worker/external/index.d.ts +4 -0
  177. package/lib/worker/external/index.js +10 -0
  178. package/lib/worker/heartbeat/adapter.d.ts +8 -0
  179. package/lib/worker/heartbeat/adapter.js +26 -0
  180. package/lib/worker/heartbeat/index.d.ts +4 -0
  181. package/lib/worker/heartbeat/index.js +10 -0
  182. package/lib/worker/http-request/adapter.d.ts +8 -0
  183. package/lib/worker/http-request/adapter.js +55 -0
  184. package/lib/worker/http-request/index.d.ts +4 -0
  185. package/lib/worker/http-request/index.js +10 -0
  186. package/lib/worker/message/adapter.d.ts +11 -0
  187. package/lib/worker/message/adapter.js +42 -0
  188. package/lib/worker/message/index.d.ts +4 -0
  189. package/lib/worker/message/index.js +10 -0
  190. package/lib/worker/push-notification/adapter.d.ts +9 -0
  191. package/lib/worker/push-notification/adapter.js +87 -0
  192. package/lib/worker/push-notification/index.d.ts +4 -0
  193. package/lib/worker/push-notification/index.js +10 -0
  194. package/lib/worker/twilio/adapter.d.ts +8 -0
  195. package/lib/worker/twilio/adapter.js +59 -0
  196. package/lib/worker/twilio/index.d.ts +4 -0
  197. package/lib/worker/twilio/index.js +10 -0
  198. package/lib/worker/update-coinbase-rates/adapter.d.ts +4 -0
  199. package/lib/worker/update-coinbase-rates/adapter.js +61 -0
  200. package/lib/worker/update-coinbase-rates/index.d.ts +4 -0
  201. package/lib/worker/update-coinbase-rates/index.js +13 -0
  202. package/lib/worker/update-ecb-rates/adapter.d.ts +4 -0
  203. package/lib/worker/update-ecb-rates/adapter.js +94 -0
  204. package/lib/worker/update-ecb-rates/index.d.ts +4 -0
  205. package/lib/worker/update-ecb-rates/index.js +13 -0
  206. package/lib/worker/update-token-ownership/adapter.d.ts +5 -0
  207. package/lib/worker/update-token-ownership/adapter.js +58 -0
  208. package/lib/worker/update-token-ownership/index.d.ts +4 -0
  209. package/lib/worker/update-token-ownership/index.js +13 -0
  210. package/lib/worker/zombie-killer/adapter.d.ts +13 -0
  211. package/lib/worker/zombie-killer/adapter.js +90 -0
  212. package/lib/worker/zombie-killer/index.d.ts +4 -0
  213. package/lib/worker/zombie-killer/index.js +10 -0
  214. package/package.json +1 -1
@@ -0,0 +1,33 @@
1
+ import { 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
+ export default OrderDelivery;
@@ -0,0 +1,4 @@
1
+ import { type IPlugin } from '@unchainedshop/core';
2
+ export declare const OrderDeliveryPlugin: IPlugin;
3
+ export default OrderDeliveryPlugin;
4
+ export { OrderDelivery } from './adapter.ts';
@@ -0,0 +1,10 @@
1
+ import {} from '@unchainedshop/core';
2
+ import { OrderDelivery } from "./adapter.js";
3
+ export const OrderDeliveryPlugin = {
4
+ key: 'shop.unchained.pricing.order-delivery',
5
+ label: 'Order Delivery Pricing Plugin',
6
+ version: '1.0.0',
7
+ adapters: [OrderDelivery],
8
+ };
9
+ export default OrderDeliveryPlugin;
10
+ export { OrderDelivery } from "./adapter.js";
@@ -0,0 +1,3 @@
1
+ import { type IOrderPricingAdapter, type OrderDiscountConfiguration } from '@unchainedshop/core';
2
+ export declare const OrderDiscount: IOrderPricingAdapter<OrderDiscountConfiguration>;
3
+ export default OrderDiscount;
@@ -0,0 +1,74 @@
1
+ import { OrderPricingRowCategory, 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
+ export default OrderDiscount;
@@ -0,0 +1,4 @@
1
+ import { type IPlugin } from '@unchainedshop/core';
2
+ export declare const OrderDiscountPlugin: IPlugin;
3
+ export default OrderDiscountPlugin;
4
+ export { OrderDiscount } from './adapter.ts';
@@ -0,0 +1,10 @@
1
+ import {} from '@unchainedshop/core';
2
+ import { OrderDiscount } from "./adapter.js";
3
+ export const OrderDiscountPlugin = {
4
+ key: 'shop.unchained.pricing.order-discount',
5
+ label: 'Order Discount Pricing Plugin',
6
+ version: '1.0.0',
7
+ adapters: [OrderDiscount],
8
+ };
9
+ export default OrderDiscountPlugin;
10
+ export { OrderDiscount } from "./adapter.js";
@@ -0,0 +1,3 @@
1
+ import { type IOrderPricingAdapter } from '@unchainedshop/core';
2
+ export declare const OrderItems: IOrderPricingAdapter;
3
+ export default OrderItems;
@@ -0,0 +1,43 @@
1
+ import { 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
+ export default OrderItems;
@@ -0,0 +1,4 @@
1
+ import { type IPlugin } from '@unchainedshop/core';
2
+ export declare const OrderItemsPlugin: IPlugin;
3
+ export default OrderItemsPlugin;
4
+ export { OrderItems } from './adapter.ts';
@@ -0,0 +1,10 @@
1
+ import {} from '@unchainedshop/core';
2
+ import { OrderItems } from "./adapter.js";
3
+ export const OrderItemsPlugin = {
4
+ key: 'shop.unchained.pricing.order-items',
5
+ label: 'Order Items Pricing Plugin',
6
+ version: '1.0.0',
7
+ adapters: [OrderItems],
8
+ };
9
+ export default OrderItemsPlugin;
10
+ export { OrderItems } from "./adapter.js";
@@ -0,0 +1,3 @@
1
+ import { type IOrderPricingAdapter } from '@unchainedshop/core';
2
+ export declare const OrderPayment: IOrderPricingAdapter;
3
+ export default OrderPayment;
@@ -0,0 +1,33 @@
1
+ import { 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
+ export default OrderPayment;
@@ -0,0 +1,4 @@
1
+ import { type IPlugin } from '@unchainedshop/core';
2
+ export declare const OrderPaymentPlugin: IPlugin;
3
+ export default OrderPaymentPlugin;
4
+ export { OrderPayment } from './adapter.ts';
@@ -0,0 +1,10 @@
1
+ import {} from '@unchainedshop/core';
2
+ import { OrderPayment } from "./adapter.js";
3
+ export const OrderPaymentPlugin = {
4
+ key: 'shop.unchained.pricing.order-payment',
5
+ label: 'Order Payment Pricing Plugin',
6
+ version: '1.0.0',
7
+ adapters: [OrderPayment],
8
+ };
9
+ export default OrderPaymentPlugin;
10
+ export { OrderPayment } from "./adapter.js";
@@ -0,0 +1,3 @@
1
+ import { type IProductPricingAdapter } from '@unchainedshop/core';
2
+ export declare const ProductPrice: IProductPricingAdapter;
3
+ export default ProductPrice;
@@ -0,0 +1,60 @@
1
+ import { 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
+ export default ProductPrice;
@@ -0,0 +1,4 @@
1
+ import { type IPlugin } from '@unchainedshop/core';
2
+ export declare const ProductPricePlugin: IPlugin;
3
+ export default ProductPricePlugin;
4
+ export { ProductPrice } from './adapter.ts';
@@ -0,0 +1,10 @@
1
+ import {} from '@unchainedshop/core';
2
+ import { ProductPrice } from "./adapter.js";
3
+ export const ProductPricePlugin = {
4
+ key: 'shop.unchained.pricing.product-catalog',
5
+ label: 'Product Catalog Price Plugin',
6
+ version: '1.0.0',
7
+ adapters: [ProductPrice],
8
+ };
9
+ export default ProductPricePlugin;
10
+ export { ProductPrice } from "./adapter.js";
@@ -0,0 +1,3 @@
1
+ import { type ProductDiscountConfiguration, type IProductPricingAdapter } from '@unchainedshop/core';
2
+ export declare const ProductDiscount: IProductPricingAdapter<ProductDiscountConfiguration>;
3
+ export default ProductDiscount;
@@ -0,0 +1,69 @@
1
+ import { calculation as calcUtils } from '@unchainedshop/utils';
2
+ import { 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
+ export default ProductDiscount;
@@ -0,0 +1,4 @@
1
+ import { type IPlugin } from '@unchainedshop/core';
2
+ export declare const ProductDiscountPlugin: IPlugin;
3
+ export default ProductDiscountPlugin;
4
+ export { ProductDiscount } from './adapter.ts';
@@ -0,0 +1,10 @@
1
+ import {} from '@unchainedshop/core';
2
+ import { ProductDiscount } from "./adapter.js";
3
+ export const ProductDiscountPlugin = {
4
+ key: 'shop.unchained.pricing.product-discount',
5
+ label: 'Product Discount Pricing Plugin',
6
+ version: '1.0.0',
7
+ adapters: [ProductDiscount],
8
+ };
9
+ export default ProductDiscountPlugin;
10
+ export { ProductDiscount } from "./adapter.js";
@@ -0,0 +1,3 @@
1
+ import { type IProductPricingAdapter } from '@unchainedshop/core';
2
+ export declare const ProductPriceRateConversion: IProductPricingAdapter;
3
+ export default ProductPriceRateConversion;
@@ -0,0 +1,53 @@
1
+ import { ProductPricingAdapter } from '@unchainedshop/core';
2
+ export const ProductPriceRateConversion = {
3
+ ...ProductPricingAdapter,
4
+ key: 'shop.unchained.pricing.rate-conversion',
5
+ version: '1.0.0',
6
+ label: 'Generic rate conversion plugin that converts between rates if entry in DB exists.',
7
+ orderIndex: 10,
8
+ isActivatedFor: () => {
9
+ return true;
10
+ },
11
+ actions: (params) => {
12
+ const pricingAdapter = ProductPricingAdapter.actions(params);
13
+ const { modules } = params.context;
14
+ return {
15
+ ...pricingAdapter,
16
+ calculate: async () => {
17
+ const { product, countryCode, quantity, currencyCode: targetCurrency } = params.context;
18
+ const { calculation = [] } = params.calculationSheet;
19
+ if (calculation?.length) {
20
+ return pricingAdapter.calculate();
21
+ }
22
+ const productPrice = await modules.products.prices.price(product, {
23
+ countryCode,
24
+ quantity,
25
+ });
26
+ if (!productPrice) {
27
+ return pricingAdapter.calculate();
28
+ }
29
+ const fromCurrencyObj = await modules.currencies.findCurrency({
30
+ isoCode: productPrice.currencyCode,
31
+ });
32
+ const targetCurrencyObj = await modules.currencies.findCurrency({
33
+ isoCode: targetCurrency,
34
+ });
35
+ if (!targetCurrencyObj?.isActive || !fromCurrencyObj?.isActive)
36
+ return pricingAdapter.calculate();
37
+ const rateData = await modules.products.prices.rates.getRate(fromCurrencyObj, targetCurrencyObj);
38
+ if (rateData && rateData.rate > 0) {
39
+ const convertedAmount = Math.round(productPrice.amount * rateData.rate);
40
+ pricingAdapter.resultSheet().resetCalculation(params.calculationSheet);
41
+ pricingAdapter.resultSheet().addItem({
42
+ amount: convertedAmount * quantity,
43
+ isTaxable: Boolean(productPrice?.isTaxable),
44
+ isNetPrice: Boolean(productPrice?.isNetPrice),
45
+ meta: { adapter: ProductPriceRateConversion.key, rate: rateData.rate },
46
+ });
47
+ }
48
+ return pricingAdapter.calculate();
49
+ },
50
+ };
51
+ },
52
+ };
53
+ export default ProductPriceRateConversion;
@@ -0,0 +1,4 @@
1
+ import { type IPlugin } from '@unchainedshop/core';
2
+ export declare const ProductPriceRateConversionPlugin: IPlugin;
3
+ export default ProductPriceRateConversionPlugin;
4
+ export { ProductPriceRateConversion } from './adapter.ts';
@@ -0,0 +1,10 @@
1
+ import {} from '@unchainedshop/core';
2
+ import { ProductPriceRateConversion } from "./adapter.js";
3
+ export const ProductPriceRateConversionPlugin = {
4
+ key: 'shop.unchained.pricing.rate-conversion',
5
+ label: 'Product Price Rate Conversion Plugin',
6
+ version: '1.0.0',
7
+ adapters: [ProductPriceRateConversion],
8
+ };
9
+ export default ProductPriceRateConversionPlugin;
10
+ export { ProductPriceRateConversion } from "./adapter.js";
@@ -0,0 +1,3 @@
1
+ import { type IProductPricingAdapter } from '@unchainedshop/core';
2
+ export declare const ProductSwissTax: IProductPricingAdapter;
3
+ export default ProductSwissTax;
@@ -0,0 +1,76 @@
1
+ import { ProductPricingAdapter, ProductPricingRowCategory, } from '@unchainedshop/core';
2
+ import { resolveTaxCategoryFromDeliveryProvider, resolveTaxCategoryFromProduct, SwissTaxCategories, } from "../tax/ch.js";
3
+ import isDeliveryAddressInCountry from "../utils/isDeliveryAddressInCountry.js";
4
+ export const ProductSwissTax = {
5
+ ...ProductPricingAdapter,
6
+ key: 'shop.unchained.pricing.product-swiss-tax',
7
+ version: '1.0.0',
8
+ label: 'Apply Swiss Tax on Product',
9
+ orderIndex: 80,
10
+ isActivatedFor: () => {
11
+ return true;
12
+ },
13
+ actions: (params) => {
14
+ const pricingAdapter = ProductPricingAdapter.actions(params);
15
+ const { context } = params;
16
+ return {
17
+ ...pricingAdapter,
18
+ calculate: async () => {
19
+ const orderDelivery = context.order?.deliveryId
20
+ ? await context.modules.orders.deliveries.findDelivery({
21
+ orderDeliveryId: context.order?.deliveryId,
22
+ })
23
+ : null;
24
+ if (!isDeliveryAddressInCountry({
25
+ ...context,
26
+ orderDelivery,
27
+ }, ['CH', 'LI'])) {
28
+ return pricingAdapter.calculate();
29
+ }
30
+ let taxCategory = resolveTaxCategoryFromProduct(context.product);
31
+ if (!taxCategory) {
32
+ const provider = orderDelivery?.deliveryProviderId
33
+ ? await context.modules.delivery.findProvider({
34
+ deliveryProviderId: orderDelivery?.deliveryProviderId,
35
+ })
36
+ : null;
37
+ if (provider)
38
+ taxCategory = resolveTaxCategoryFromDeliveryProvider(provider);
39
+ }
40
+ if (!taxCategory)
41
+ taxCategory = SwissTaxCategories.DEFAULT;
42
+ const taxRate = taxCategory.rate(context.order?.ordered);
43
+ ProductPricingAdapter.log(`ProductSwissTax -> Tax Multiplicator: ${taxRate}`);
44
+ params.calculationSheet.filterBy({ isTaxable: true }).forEach(({ isNetPrice, ...row }) => {
45
+ if (!isNetPrice) {
46
+ const taxAmount = row.amount - row.amount / (1 + taxRate);
47
+ pricingAdapter.resultSheet().calculation.push({
48
+ ...row,
49
+ amount: -taxAmount,
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
+ }
70
+ });
71
+ return pricingAdapter.calculate();
72
+ },
73
+ };
74
+ },
75
+ };
76
+ export default ProductSwissTax;
@@ -0,0 +1,4 @@
1
+ import { type IPlugin } from '@unchainedshop/core';
2
+ export declare const ProductSwissTaxPlugin: IPlugin;
3
+ export default ProductSwissTaxPlugin;
4
+ export { ProductSwissTax } from './adapter.ts';
@@ -0,0 +1,10 @@
1
+ import {} from '@unchainedshop/core';
2
+ import { ProductSwissTax } from "./adapter.js";
3
+ export const ProductSwissTaxPlugin = {
4
+ key: 'shop.unchained.pricing.product-swiss-tax',
5
+ label: 'Product Swiss Tax Plugin',
6
+ version: '1.0.0',
7
+ adapters: [ProductSwissTax],
8
+ };
9
+ export default ProductSwissTaxPlugin;
10
+ export { ProductSwissTax } from "./adapter.js";
@@ -0,0 +1,2 @@
1
+ import { type IQuotationAdapter } from '@unchainedshop/core';
2
+ export declare const ManualOffering: IQuotationAdapter;
@@ -0,0 +1,19 @@
1
+ import { QuotationAdapter } from '@unchainedshop/core';
2
+ export const ManualOffering = {
3
+ ...QuotationAdapter,
4
+ key: 'shop.unchained.quotations.manual',
5
+ version: '1.0.0',
6
+ label: 'Manual Offerings',
7
+ orderIndex: 0,
8
+ isActivatedFor: () => true,
9
+ actions: (params) => {
10
+ return {
11
+ ...QuotationAdapter.actions(params),
12
+ quote: async () => {
13
+ return {
14
+ expires: new Date(new Date().getTime() + 3600 * 1000),
15
+ };
16
+ },
17
+ };
18
+ },
19
+ };