@unchainedshop/plugins 4.8.2 → 4.8.4

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.
@@ -26,10 +26,13 @@ const getMarketplaceSplits = async ({ order, orderPayment, config, }) => {
26
26
  currencyCode: order.currencyCode,
27
27
  });
28
28
  const { amount: total } = pricing.total({ useNetPrice: false });
29
- return Promise.all(config
29
+ const roundedTotal = Math.round(total);
30
+ const splits = await Promise.all(config
30
31
  .filter((item) => item.key === 'marketplaceSplit')
31
32
  .map((item) => {
32
- const [subMerchantId, staticDiscountId, sharePercentage] = item.value || ''.split(';').map((f) => f.trim());
33
+ const [subMerchantId, staticDiscountId, sharePercentage] = (item.value || '')
34
+ .split(';')
35
+ .map((f) => f.trim());
33
36
  const { amount: discountSum } = pricingForOrderPayment.total({
34
37
  category: PaymentPricingRowCategory.Discount,
35
38
  discountId: staticDiscountId,
@@ -43,6 +46,14 @@ const getMarketplaceSplits = async ({ order, orderPayment, config, }) => {
43
46
  commission,
44
47
  };
45
48
  }));
49
+ if (splits.length > 0) {
50
+ const currentSum = splits.reduce((sum, split) => sum + split.amount, 0);
51
+ const difference = roundedTotal - currentSum;
52
+ if (difference !== 0) {
53
+ splits[splits.length - 1].amount += difference;
54
+ }
55
+ }
56
+ return splits;
46
57
  };
47
58
  const Datatrans = {
48
59
  ...PaymentAdapter,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unchainedshop/plugins",
3
3
  "description": "Official plugin collection for the Unchained Engine with payment, delivery, and pricing adapters",
4
- "version": "4.8.2",
4
+ "version": "4.8.4",
5
5
  "main": "lib/plugins-index.js",
6
6
  "types": "lib/plugins-index.d.ts",
7
7
  "exports": {