@nimee/calculations 1.0.3 → 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 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: (totalPrice: number, event: IEventModel, account: IAccountModel) => {
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
- const calculateFinalPriceWithNimiFee = (totalPrice, event, account) => {
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: totalPrice, nimiFee: 0, nimiFeePercentage: account.marketFee };
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 5
36
- const unroundedValue = Math.max(3, (totalPrice * account.originalMarketFee) / 100);
37
- const roundedValue = Math.round(unroundedValue * 2) / 2;
38
- const nimiFeePercentageUnrounded = (roundedValue / totalPrice) * 100;
39
- const nimiFeePercentage = Math.round(nimiFeePercentageUnrounded * 2) / 2;
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: roundedValue + totalPrice,
42
- nimiFee: roundedValue,
43
- nimiFeePercentage,
47
+ finalPriceWithNimiFee: roundedFee + totalPriceWithCouponDiscount,
48
+ nimiFee: roundedFee,
49
+ nimiFeePercentage: nimiFeePercentageMinusPaymeFee,
44
50
  };
45
51
  default:
46
- return { finalPriceWithNimiFee: totalPrice, nimiFee: 0, nimiFeePercentage: account.marketFee };
52
+ return { finalPriceWithNimiFee: totalPriceWithCouponDiscount, nimiFee: 0, nimiFeePercentage: account.marketFee };
47
53
  }
48
54
  };
49
55
  exports.calculateFinalPriceWithNimiFee = calculateFinalPriceWithNimiFee;
@@ -1 +1 @@
1
- {"version":3,"file":"prices.js","sourceRoot":"","sources":["../src/prices.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAoD;AACpD,sDAAsG;AACtG,oDAAkD;AAClD,wDAAmD;AAEnD,+EAA+E;AACxE,MAAM,qBAAqB,GAAG,CAAC,aAAgC,EAAU,EAAE;IAChF,OAAO,aAAa,CAAC,MAAM,CAAC,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nB,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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nimee/calculations",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "nimi calculations like prices for back and front",
5
5
  "main": "dist/index.js",
6
6
  "author": "dan goldberg",
@@ -28,7 +28,7 @@
28
28
  "types": "dist/index.d.ts",
29
29
  "dependencies": {
30
30
  "@nimee/api-clients": "^1.1.15",
31
- "@nimee/error-handler": "^0.0.7",
31
+ "@nimee/error-handler": "^0.0.9",
32
32
  "axios": "1.2.1"
33
33
  }
34
34
  }
package/src/prices.ts CHANGED
@@ -15,28 +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
- totalPrice: number,
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: totalPrice, nimiFee: 0, nimiFeePercentage: account.marketFee };
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 5
28
- const unroundedValue = Math.max(3, (totalPrice * account.originalMarketFee) / 100);
29
- const roundedValue = Math.round(unroundedValue * 2) / 2;
30
-
31
- const nimiFeePercentageUnrounded = (roundedValue / totalPrice) * 100;
32
- const nimiFeePercentage = Math.round(nimiFeePercentageUnrounded * 2) / 2;
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);
33
39
  return {
34
- finalPriceWithNimiFee: roundedValue + totalPrice,
35
- nimiFee: roundedValue,
36
- nimiFeePercentage,
40
+ finalPriceWithNimiFee: roundedFee + totalPriceWithCouponDiscount,
41
+ nimiFee: roundedFee,
42
+ nimiFeePercentage: nimiFeePercentageMinusPaymeFee,
37
43
  };
38
44
  default:
39
- return { finalPriceWithNimiFee: totalPrice, nimiFee: 0, nimiFeePercentage: account.marketFee };
45
+ return { finalPriceWithNimiFee: totalPriceWithCouponDiscount, nimiFee: 0, nimiFeePercentage: account.marketFee };
40
46
  }
41
47
  };
42
48
  export const calculateFinalPriceWithCouponDiscount = (totalPrice: number, couponDiscount: number): number =>