@nimee/calculations 1.0.4 → 1.0.5
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.d.ts +1 -1
- package/dist/prices.js +17 -11
- package/dist/prices.js.map +1 -1
- package/package.json +1 -1
- package/src/prices.ts +19 -12
package/dist/prices.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IAccountModel, IEventModel, IUserEventModel } from "@nimee/shared-types";
|
|
2
2
|
export declare const getTotalTicketsAmount: (allUsersEvent: IUserEventModel[]) => number;
|
|
3
|
-
export declare const calculateFinalPriceWithNimiFee: (
|
|
3
|
+
export declare const calculateFinalPriceWithNimiFee: (totalPriceWithoutCouponDiscount: number, event: IEventModel, account: IAccountModel, totalPriceWithCouponDiscount: number) => {
|
|
4
4
|
nimiFeePercentage: number;
|
|
5
5
|
nimiFee: number;
|
|
6
6
|
finalPriceWithNimiFee: number;
|
package/dist/prices.js
CHANGED
|
@@ -27,23 +27,29 @@ const getTotalTicketsAmount = (allUsersEvent) => {
|
|
|
27
27
|
}, 0);
|
|
28
28
|
};
|
|
29
29
|
exports.getTotalTicketsAmount = getTotalTicketsAmount;
|
|
30
|
-
|
|
30
|
+
// we need to calculate the final price with nimi fee and return the nimi fee percentage and nimi fee
|
|
31
|
+
// we need the original price becuase the fee is calculated on top of the original price
|
|
32
|
+
// then we return the coupon discount and the final price with nimi fee
|
|
33
|
+
// then we calculate the nimi fee percentage from the final price after discount with nimi fee
|
|
34
|
+
const calculateFinalPriceWithNimiFee = (totalPriceWithoutCouponDiscount, event, account, totalPriceWithCouponDiscount) => {
|
|
31
35
|
switch (event.feeCollectionType) {
|
|
32
36
|
case shared_types_1.IFeeCollectionType.PERCENTAGE_FROM_TICKET:
|
|
33
|
-
return { finalPriceWithNimiFee:
|
|
37
|
+
return { finalPriceWithNimiFee: totalPriceWithCouponDiscount, nimiFee: 0, nimiFeePercentage: account.marketFee }; // we use here marketFee (and not originalMarketFee) because we need to send the fee to payme without their fee
|
|
34
38
|
case shared_types_1.IFeeCollectionType.ON_TOP_OF_TICKET:
|
|
35
|
-
// minimum 3
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
//
|
|
39
|
-
const nimiFeePercentage = (
|
|
39
|
+
// minimum 3 so we use max
|
|
40
|
+
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)
|
|
41
|
+
const roundedFee = Math.round(unroundedFee);
|
|
42
|
+
// 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
|
|
43
|
+
const nimiFeePercentage = Math.min(59, (roundedFee / (totalPriceWithCouponDiscount + roundedFee)) * 100);
|
|
44
|
+
// 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
|
|
45
|
+
const nimiFeePercentageMinusPaymeFee = Math.max(0, nimiFeePercentage - 1.1 * 1.17);
|
|
40
46
|
return {
|
|
41
|
-
finalPriceWithNimiFee:
|
|
42
|
-
nimiFee:
|
|
43
|
-
nimiFeePercentage,
|
|
47
|
+
finalPriceWithNimiFee: roundedFee + totalPriceWithCouponDiscount,
|
|
48
|
+
nimiFee: roundedFee,
|
|
49
|
+
nimiFeePercentage: nimiFeePercentageMinusPaymeFee,
|
|
44
50
|
};
|
|
45
51
|
default:
|
|
46
|
-
return { finalPriceWithNimiFee:
|
|
52
|
+
return { finalPriceWithNimiFee: totalPriceWithCouponDiscount, nimiFee: 0, nimiFeePercentage: account.marketFee };
|
|
47
53
|
}
|
|
48
54
|
};
|
|
49
55
|
exports.calculateFinalPriceWithNimiFee = calculateFinalPriceWithNimiFee;
|
package/dist/prices.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prices.js","sourceRoot":"","sources":["../src/prices.ts"],"names":[],"mappings":";;;;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AAG,cAAc,CAAC;AADvD,QAAA,qCAAqC,yCACkB;AAEpE,0FAA0F;AAC1F,iGAAiG;AAC1F,MAAM,iBAAiB,GAAG,CAAO,SAAmB,EAAE,cAAsB,EAAE,SAAiB,EAAE,OAAe,EAAE,EAAE;IACzH,MAAM,YAAY,GAAG,IAAI,0BAAY,EAAE,CAAC;IACxC,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;IACpH,IAAI,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAA,EAAE;QACpB,MAAM,IAAI,2BAAW,CACnB,uCAAuC,EACvC,GAAG,EACH,sEAAsE,SAAS,kBAAkB,OAAO,EAAE,CAC3G,CAAC;KACH;IAED,MAAM,wBAAwB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,GAAW,EAAE,MAAyB,EAAE,EAAE,CAAC,GAAG,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACnH,IAAI,wBAAwB,KAAK,CAAC,EAAE;QAClC,OAAO,IAAI,CAAC;KACb;IAED,IAAI,cAAc,EAAE;QAClB,MAAM,qBAAqB,GAAG,IAAA,6CAAqC,EAAC,wBAAwB,EAAE,cAAc,CAAC,CAAC;QAC9G,IAAI,qBAAqB,KAAK,CAAC,EAAE;YAC/B,OAAO,IAAI,CAAC;SACb;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAA,CAAC;AAxBW,QAAA,iBAAiB,qBAwB5B"}
|
package/package.json
CHANGED
package/src/prices.ts
CHANGED
|
@@ -15,27 +15,34 @@ export const getTotalTicketsAmount = (allUsersEvent: IUserEventModel[]): number
|
|
|
15
15
|
}, 0);
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
// we need to calculate the final price with nimi fee and return the nimi fee percentage and nimi fee
|
|
19
|
+
// we need the original price becuase the fee is calculated on top of the original price
|
|
20
|
+
// then we return the coupon discount and the final price with nimi fee
|
|
21
|
+
// then we calculate the nimi fee percentage from the final price after discount with nimi fee
|
|
18
22
|
export const calculateFinalPriceWithNimiFee = (
|
|
19
|
-
|
|
23
|
+
totalPriceWithoutCouponDiscount: number,
|
|
20
24
|
event: IEventModel,
|
|
21
|
-
account: IAccountModel
|
|
25
|
+
account: IAccountModel,
|
|
26
|
+
totalPriceWithCouponDiscount: number
|
|
22
27
|
): { nimiFeePercentage: number; nimiFee: number; finalPriceWithNimiFee: number } => {
|
|
23
28
|
switch (event.feeCollectionType) {
|
|
24
29
|
case IFeeCollectionType.PERCENTAGE_FROM_TICKET:
|
|
25
|
-
return { finalPriceWithNimiFee:
|
|
30
|
+
return { finalPriceWithNimiFee: totalPriceWithCouponDiscount, nimiFee: 0, nimiFeePercentage: account.marketFee }; // we use here marketFee (and not originalMarketFee) because we need to send the fee to payme without their fee
|
|
26
31
|
case IFeeCollectionType.ON_TOP_OF_TICKET:
|
|
27
|
-
// minimum 3
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
//
|
|
31
|
-
const nimiFeePercentage = (
|
|
32
|
+
// minimum 3 so we use max
|
|
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
|
+
const roundedFee = Math.round(unroundedFee);
|
|
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
|
+
const nimiFeePercentage = Math.min(59, (roundedFee / (totalPriceWithCouponDiscount + roundedFee)) * 100);
|
|
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
|
+
const nimiFeePercentageMinusPaymeFee = Math.max(0, nimiFeePercentage - 1.1 * 1.17);
|
|
32
39
|
return {
|
|
33
|
-
finalPriceWithNimiFee:
|
|
34
|
-
nimiFee:
|
|
35
|
-
nimiFeePercentage,
|
|
40
|
+
finalPriceWithNimiFee: roundedFee + totalPriceWithCouponDiscount,
|
|
41
|
+
nimiFee: roundedFee,
|
|
42
|
+
nimiFeePercentage: nimiFeePercentageMinusPaymeFee,
|
|
36
43
|
};
|
|
37
44
|
default:
|
|
38
|
-
return { finalPriceWithNimiFee:
|
|
45
|
+
return { finalPriceWithNimiFee: totalPriceWithCouponDiscount, nimiFee: 0, nimiFeePercentage: account.marketFee };
|
|
39
46
|
}
|
|
40
47
|
};
|
|
41
48
|
export const calculateFinalPriceWithCouponDiscount = (totalPrice: number, couponDiscount: number): number =>
|