@nimee/calculations 1.0.8 → 1.0.10
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/dist/prices.js +21 -10
- package/dist/prices.js.map +1 -1
- package/package.json +1 -1
- package/src/prices.ts +21 -13
- package/tests/prices.test.ts +3 -3
package/dist/prices.js
CHANGED
|
@@ -31,21 +31,32 @@ const calculateFinalPriceWithNimiFee = (totalPriceWithoutCouponDiscount, event,
|
|
|
31
31
|
}
|
|
32
32
|
// minimum 3 so we use max we totalPriceWithoutCouponDiscount because the fee is calculated on top of the original price and not the price after discount
|
|
33
33
|
const unroundedFee = Math.max(3, (totalPriceWithoutCouponDiscount * account.originalMarketFee) / 100); // here we use originalMarketFee because we need to calculate the fee on top of the original price (later we will subtract payme fee from the fee we send to payme)
|
|
34
|
-
let roundedFee =
|
|
34
|
+
let roundedFee = roundToTwoDecimals(unroundedFee);
|
|
35
35
|
// nimiFeePercentage has unknown range that need to be aware of - we get error when we send to payme with range above 60 so we use max
|
|
36
36
|
// const nimiFeePercentage = Math.min(59, (roundedFee / totalPriceWithCouponDiscount) * 100); // we use here totalPriceWithCouponDiscount because we send payme the price after the discount plus the nimiFee (roundedFee) so we need to know the percentage of the fee from the final price
|
|
37
37
|
// we need to make sure we send marketFee that is greater or equal to 0 so we use max and we must subtract payme fee from nimiFeePercentage because payme ask to send them the fee without their fee
|
|
38
38
|
// const nimiFeePercentageMinusPaymeFee = Math.max(0, nimiFeePercentage - 1.1 * 1.17);
|
|
39
|
-
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const newUnroundedFee = roundedFee + Math.abs(marketplaceFeeOfON_TOP_OF_TICKET) + 1; // so we want to add the minus fee as absolute and another small amount because the solek takes from the new value (price+new rounded fee)
|
|
44
|
-
roundedFee = Math.ceil(newUnroundedFee * 10) / 10;
|
|
45
|
-
marketplaceFeeOfON_TOP_OF_TICKET =
|
|
46
|
-
roundedFee - ((roundedFee + totalPriceWithCouponDiscount) * (account.marketFee + exports.paymeFee)) / 100; // payme takes the percentage from the price. so we calculate payme and nimi fee from the price and we substruct the result from the roundedFee
|
|
47
|
-
logger_1.default.info(`so assign new fee: ${marketplaceFeeOfON_TOP_OF_TICKET}, nimiFee: ${roundedFee}, account: ${account._id}, event: ${event._id}`);
|
|
39
|
+
const totalFee = roundToTwoDecimals(((roundedFee + totalPriceWithCouponDiscount) * (account.marketFee + exports.paymeFee)) / 100);
|
|
40
|
+
if (roundedFee < totalFee) {
|
|
41
|
+
logger_1.default.debug(`roundedFee is less than totalFee roundedFee: ${roundedFee} and totalFee: ${totalFee} for event: ${event._id}`);
|
|
42
|
+
roundedFee = totalFee;
|
|
48
43
|
}
|
|
44
|
+
const marketplaceFeeOfON_TOP_OF_TICKET = roundedFee - totalFee; // payme takes the percentage from the price. so we calculate payme and nimi fee from the price and we substruct the result from the roundedFee
|
|
45
|
+
// let marketplaceFeeOfON_TOP_OF_TICKET =
|
|
46
|
+
// roundedFee - ((roundedFee + totalPriceWithCouponDiscount) * (account.marketFee + paymeFee)) / 100; // payme takes the percentage from the price. so we calculate payme and nimi fee from the price and we substruct the result from the roundedFee
|
|
47
|
+
// if (marketplaceFeeOfON_TOP_OF_TICKET <= 0) {
|
|
48
|
+
// // means the originalMarketFee is equal or close to the marketFee+paymeFee) - happens when the price of the ticket is high and the fee of payme and nimi is high.. so we want to add more money to the fee so the seller wont lose here
|
|
49
|
+
// logger.debug(
|
|
50
|
+
// `marketplaceFee is less than 0 marketplaceFee: ${marketplaceFeeOfON_TOP_OF_TICKET} and nimiFee: ${roundedFee}, account: ${account._id}, event: ${event._id}`
|
|
51
|
+
// );
|
|
52
|
+
// const newUnroundedFee = roundedFee + Math.abs(marketplaceFeeOfON_TOP_OF_TICKET) + 1; // so we want to add the minus fee as absolute and another small amount because the solek takes from the new value (price+new rounded fee)
|
|
53
|
+
// roundedFee = Math.ceil(newUnroundedFee * 10) / 10;
|
|
54
|
+
// marketplaceFeeOfON_TOP_OF_TICKET =
|
|
55
|
+
// roundedFee - ((roundedFee + totalPriceWithCouponDiscount) * (account.marketFee + paymeFee)) / 100; // payme takes the percentage from the price. so we calculate payme and nimi fee from the price and we substruct the result from the roundedFee
|
|
56
|
+
// logger.info(
|
|
57
|
+
// `so assign new fee: ${marketplaceFeeOfON_TOP_OF_TICKET}, nimiFee: ${roundedFee}, account: ${account._id}, event: ${event._id}`
|
|
58
|
+
// );
|
|
59
|
+
// }
|
|
49
60
|
return {
|
|
50
61
|
finalPriceWithNimiFee: roundedFee + totalPriceWithCouponDiscount,
|
|
51
62
|
nimiFee: roundedFee,
|
package/dist/prices.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prices.js","sourceRoot":"","sources":["../src/prices.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAoD;AACpD,sDAAsG;AACtG,2DAAmC;AACnC,wDAAmD;AACtC,QAAA,QAAQ,GAAG,GAAG,GAAG,IAAI,CAAC;AAEnC,qGAAqG;AACrG,wFAAwF;AACxF,uEAAuE;AACvE,8FAA8F;AAC9F,MAAM,kBAAkB,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AAEjE,MAAM,8BAA8B,GAAG,CAC5C,+BAAuC,EACvC,KAAkB,EAClB,OAAsB,EACtB,4BAAoC,EACmE,EAAE;IACzG,QAAQ,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAChC,KAAK,iCAAkB,CAAC,sBAAsB;YAC5C,MAAM,sCAAsC,GAC1C,CAAC,4BAA4B,GAAG,CAAC,OAAO,CAAC,iBAAiB,GAAG,gBAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,GAAG,GAAG,CAAC;YACpG,OAAO;gBACL,qBAAqB,EAAE,4BAA4B;gBACnD,OAAO,EAAE,CAAC;gBACV,iBAAiB,EAAE,OAAO,CAAC,SAAS;g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
|
// minimum 3 so we use max we totalPriceWithoutCouponDiscount because the fee is calculated on top of the original price and not the price after discount
|
|
35
35
|
const unroundedFee = Math.max(3, (totalPriceWithoutCouponDiscount * account.originalMarketFee) / 100); // here we use originalMarketFee because we need to calculate the fee on top of the original price (later we will subtract payme fee from the fee we send to payme)
|
|
36
|
-
let roundedFee =
|
|
36
|
+
let roundedFee = roundToTwoDecimals(unroundedFee);
|
|
37
37
|
// nimiFeePercentage has unknown range that need to be aware of - we get error when we send to payme with range above 60 so we use max
|
|
38
38
|
// const nimiFeePercentage = Math.min(59, (roundedFee / totalPriceWithCouponDiscount) * 100); // we use here totalPriceWithCouponDiscount because we send payme the price after the discount plus the nimiFee (roundedFee) so we need to know the percentage of the fee from the final price
|
|
39
39
|
// we need to make sure we send marketFee that is greater or equal to 0 so we use max and we must subtract payme fee from nimiFeePercentage because payme ask to send them the fee without their fee
|
|
40
40
|
// const nimiFeePercentageMinusPaymeFee = Math.max(0, nimiFeePercentage - 1.1 * 1.17);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (marketplaceFeeOfON_TOP_OF_TICKET <= 0) {
|
|
44
|
-
// means the originalMarketFee is equal or close to the marketFee+paymeFee) - happens when the price of the ticket is high and the fee of payme and nimi is high.. so we want to add more money to the fee so the seller wont lose here
|
|
41
|
+
const totalFee = roundToTwoDecimals(((roundedFee + totalPriceWithCouponDiscount) * (account.marketFee + paymeFee)) / 100);
|
|
42
|
+
if (roundedFee < totalFee) {
|
|
45
43
|
logger.debug(
|
|
46
|
-
`
|
|
47
|
-
);
|
|
48
|
-
const newUnroundedFee = roundedFee + Math.abs(marketplaceFeeOfON_TOP_OF_TICKET) + 1; // so we want to add the minus fee as absolute and another small amount because the solek takes from the new value (price+new rounded fee)
|
|
49
|
-
roundedFee = Math.ceil(newUnroundedFee * 10) / 10;
|
|
50
|
-
marketplaceFeeOfON_TOP_OF_TICKET =
|
|
51
|
-
roundedFee - ((roundedFee + totalPriceWithCouponDiscount) * (account.marketFee + paymeFee)) / 100; // payme takes the percentage from the price. so we calculate payme and nimi fee from the price and we substruct the result from the roundedFee
|
|
52
|
-
logger.info(
|
|
53
|
-
`so assign new fee: ${marketplaceFeeOfON_TOP_OF_TICKET}, nimiFee: ${roundedFee}, account: ${account._id}, event: ${event._id}`
|
|
44
|
+
`roundedFee is less than totalFee roundedFee: ${roundedFee} and totalFee: ${totalFee} for event: ${event._id}`
|
|
54
45
|
);
|
|
46
|
+
roundedFee = totalFee;
|
|
55
47
|
}
|
|
48
|
+
const marketplaceFeeOfON_TOP_OF_TICKET = roundedFee - totalFee; // payme takes the percentage from the price. so we calculate payme and nimi fee from the price and we substruct the result from the roundedFee
|
|
49
|
+
// let marketplaceFeeOfON_TOP_OF_TICKET =
|
|
50
|
+
// roundedFee - ((roundedFee + totalPriceWithCouponDiscount) * (account.marketFee + paymeFee)) / 100; // payme takes the percentage from the price. so we calculate payme and nimi fee from the price and we substruct the result from the roundedFee
|
|
51
|
+
// if (marketplaceFeeOfON_TOP_OF_TICKET <= 0) {
|
|
52
|
+
// // means the originalMarketFee is equal or close to the marketFee+paymeFee) - happens when the price of the ticket is high and the fee of payme and nimi is high.. so we want to add more money to the fee so the seller wont lose here
|
|
53
|
+
// logger.debug(
|
|
54
|
+
// `marketplaceFee is less than 0 marketplaceFee: ${marketplaceFeeOfON_TOP_OF_TICKET} and nimiFee: ${roundedFee}, account: ${account._id}, event: ${event._id}`
|
|
55
|
+
// );
|
|
56
|
+
// const newUnroundedFee = roundedFee + Math.abs(marketplaceFeeOfON_TOP_OF_TICKET) + 1; // so we want to add the minus fee as absolute and another small amount because the solek takes from the new value (price+new rounded fee)
|
|
57
|
+
// roundedFee = Math.ceil(newUnroundedFee * 10) / 10;
|
|
58
|
+
// marketplaceFeeOfON_TOP_OF_TICKET =
|
|
59
|
+
// roundedFee - ((roundedFee + totalPriceWithCouponDiscount) * (account.marketFee + paymeFee)) / 100; // payme takes the percentage from the price. so we calculate payme and nimi fee from the price and we substruct the result from the roundedFee
|
|
60
|
+
// logger.info(
|
|
61
|
+
// `so assign new fee: ${marketplaceFeeOfON_TOP_OF_TICKET}, nimiFee: ${roundedFee}, account: ${account._id}, event: ${event._id}`
|
|
62
|
+
// );
|
|
63
|
+
// }
|
|
56
64
|
return {
|
|
57
65
|
finalPriceWithNimiFee: roundedFee + totalPriceWithCouponDiscount,
|
|
58
66
|
nimiFee: roundedFee,
|
package/tests/prices.test.ts
CHANGED
|
@@ -67,7 +67,7 @@ describe("calculateFinalPriceWithNimiFee", () => {
|
|
|
67
67
|
totalPriceWithCouponDiscount
|
|
68
68
|
);
|
|
69
69
|
|
|
70
|
-
const nimiFee = 3.
|
|
70
|
+
const nimiFee = 3.16;
|
|
71
71
|
const expectedMarketplaceFee = parseFloat(
|
|
72
72
|
(nimiFee - ((totalPriceWithCouponDiscount + nimiFee) * (paymeFee + account.marketFee)) / 100).toFixed(2)
|
|
73
73
|
);
|
|
@@ -92,11 +92,11 @@ describe("calculateFinalPriceWithNimiFee", () => {
|
|
|
92
92
|
totalPriceWithCouponDiscount
|
|
93
93
|
);
|
|
94
94
|
|
|
95
|
-
const nimiFee =
|
|
95
|
+
const nimiFee = 5.23;
|
|
96
96
|
expect(result.nimiFeePercentage).toBe(accountMarketFee);
|
|
97
97
|
expect(result.nimiFee).toBe(nimiFee);
|
|
98
98
|
expect(result.finalPriceWithNimiFee).toBe(totalPriceWithCouponDiscount + nimiFee);
|
|
99
|
-
expect(result.marketplaceFee).toBe(0
|
|
99
|
+
expect(result.marketplaceFee).toBe(0);
|
|
100
100
|
});
|
|
101
101
|
});
|
|
102
102
|
|