@riocrypto/common-server 1.0.745 → 1.0.747

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.
@@ -1,6 +1,6 @@
1
1
  import { Country, Fiat, Processor, User } from "@riocrypto/common";
2
2
  import { Mongoose } from "mongoose";
3
- export declare const getPlatformAndPartnerFees: (mongoose: Mongoose, amountFiat: number, fiat: Fiat, processor: Processor, country: Country, partnerId?: string, brokerId?: string, user?: User) => Promise<{
3
+ export declare const getPlatformAndPartnerFees: (mongoose: Mongoose, amountFiat: number, fiat: Fiat, processor: Processor, country: Country, discount: number, partnerId?: string, brokerId?: string, user?: User) => Promise<{
4
4
  platformFeeFiat: number;
5
5
  platformFeeFiatTax: number;
6
6
  partnerFeeFiat: number;
@@ -17,7 +17,7 @@ const currency_api_client_1 = require("../clients/currency-api-client");
17
17
  const partner_1 = require("../models/partner");
18
18
  const user_1 = require("../models/user");
19
19
  const calculate_aggregate_volume_1 = require("./calculate-aggregate-volume");
20
- const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, country, partnerId, brokerId, user) => __awaiter(void 0, void 0, void 0, function* () {
20
+ const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, country, discount, partnerId, brokerId, user) => __awaiter(void 0, void 0, void 0, function* () {
21
21
  var _a;
22
22
  let platformFeeFiat;
23
23
  let platformFeeFiatTax = 0;
@@ -54,7 +54,11 @@ const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, countr
54
54
  if (partner.feesComped) {
55
55
  feesComped = true;
56
56
  }
57
- platformFeeFiat = amountFiat * partner.platformFee;
57
+ if (discount > partner.platformFee) {
58
+ throw new Error("Discount cannot be greater than platform fee");
59
+ }
60
+ const netPlatformFee = partner.platformFee - discount;
61
+ platformFeeFiat = amountFiat * netPlatformFee;
58
62
  partnerFeeFiat = amountFiat * partner.partnerFee;
59
63
  }
60
64
  else if (user === null || user === void 0 ? void 0 : user.platformFeeRanges) {
@@ -68,18 +72,37 @@ const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, countr
68
72
  }
69
73
  for (const range of user.platformFeeRanges) {
70
74
  if (range.min <= Number(volume) && range.max >= Number(volume)) {
71
- platformFeeFiat = amountFiat * range.fee;
75
+ if (discount) {
76
+ if (discount > range.fee) {
77
+ throw new Error("Discount cannot be greater than platform fee");
78
+ }
79
+ else {
80
+ const netFee = range.fee - discount;
81
+ platformFeeFiat = amountFiat * netFee;
82
+ }
83
+ }
84
+ else {
85
+ platformFeeFiat = amountFiat * range.fee;
86
+ }
72
87
  break;
73
88
  }
74
89
  }
75
90
  // @ts-ignore
76
91
  if (platformFeeFiat === undefined) {
77
- platformFeeFiat = amountFiat * rioSettings.platformFee;
92
+ const netPlatformFee = rioSettings.platformFee - discount;
93
+ if (netPlatformFee < 0) {
94
+ throw new Error("Discount cannot be greater than platform fee");
95
+ }
96
+ platformFeeFiat = amountFiat * netPlatformFee;
78
97
  }
79
98
  partnerFeeFiat = 0;
80
99
  }
81
100
  else {
82
- platformFeeFiat = amountFiat * rioSettings.platformFee;
101
+ const netPlatformFee = rioSettings.platformFee - discount;
102
+ if (netPlatformFee < 0) {
103
+ throw new Error("Discount cannot be greater than platform fee");
104
+ }
105
+ platformFeeFiat = amountFiat * netPlatformFee;
83
106
  partnerFeeFiat = 0;
84
107
  }
85
108
  if (brokerId) {
@@ -91,7 +114,18 @@ const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, countr
91
114
  if (brokerCustomer === null || brokerCustomer === void 0 ? void 0 : brokerCustomer.platformFeeRanges) {
92
115
  for (const range of brokerCustomer.platformFeeRanges) {
93
116
  if (range.min <= Number(amountUSD) && range.max >= Number(amountUSD)) {
94
- platformFeeFiat = amountFiat * range.fee;
117
+ if (discount) {
118
+ if (discount > range.fee) {
119
+ throw new Error("Discount cannot be greater than platform fee");
120
+ }
121
+ else {
122
+ const netFee = range.fee - discount;
123
+ platformFeeFiat = amountFiat * netFee;
124
+ }
125
+ }
126
+ else {
127
+ platformFeeFiat = amountFiat * range.fee;
128
+ }
95
129
  break;
96
130
  }
97
131
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.745",
3
+ "version": "1.0.747",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -24,7 +24,7 @@
24
24
  "@aws-sdk/client-s3": "^3.297.0",
25
25
  "@everapi/currencyapi-js": "^1.0.6",
26
26
  "@google-cloud/storage": "^6.9.5",
27
- "@riocrypto/common": "^1.0.662",
27
+ "@riocrypto/common": "^1.0.663",
28
28
  "@types/express": "^4.17.13",
29
29
  "axios": "^0.27.2",
30
30
  "ccxt": "^3.0.30",