@riocrypto/common-server 1.0.782 → 1.0.783

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, discount: number, partnerId?: string, brokerId?: string, user?: User) => Promise<{
3
+ export declare const getPlatformAndPartnerFees: (mongoose: Mongoose, amountFiat: number, fiat: Fiat, processor: Processor, country: Country, partnerId?: string, brokerId?: string, user?: User, markup?: number, discount?: number) => 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, discount, partnerId, brokerId, user) => __awaiter(void 0, void 0, void 0, function* () {
20
+ const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, country, partnerId, brokerId, user, markup, discount) => __awaiter(void 0, void 0, void 0, function* () {
21
21
  var _a, _b;
22
22
  let platformFeeFiat;
23
23
  let platformFeeFiatTax = 0;
@@ -30,6 +30,9 @@ const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, countr
30
30
  if (!rioSettings) {
31
31
  throw new common_1.RioSettingsNotFoundError();
32
32
  }
33
+ if (discount && markup) {
34
+ throw new Error("Cannot specify markup and discount");
35
+ }
33
36
  if (processor === common_1.Processor.Kapstar) {
34
37
  const kapstarClient = yield (0, kapstar_client_1.buildKapstarClient)();
35
38
  conversionRateToUSD = yield kapstarClient.getBRLExchangeRateUSD();
@@ -54,10 +57,16 @@ const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, countr
54
57
  if (partner.feesComped) {
55
58
  feesComped = true;
56
59
  }
57
- if (discount > partner.platformFee) {
60
+ if (discount && discount > partner.platformFee) {
58
61
  throw new Error("Discount cannot be greater than platform fee");
59
62
  }
60
- const netPlatformFee = partner.platformFee - discount;
63
+ let netPlatformFee = partner.platformFee;
64
+ if (discount) {
65
+ netPlatformFee -= discount;
66
+ }
67
+ if (markup) {
68
+ netPlatformFee += markup;
69
+ }
61
70
  platformFeeFiat = amountFiat * netPlatformFee;
62
71
  partnerFeeFiat = amountFiat * partner.partnerFee;
63
72
  }
@@ -87,6 +96,10 @@ const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, countr
87
96
  platformFeeFiat = amountFiat * netFee;
88
97
  }
89
98
  }
99
+ else if (markup) {
100
+ const netFee = range.fee + markup;
101
+ platformFeeFiat = amountFiat * netFee;
102
+ }
90
103
  else {
91
104
  platformFeeFiat = amountFiat * range.fee;
92
105
  }
@@ -110,6 +123,10 @@ const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, countr
110
123
  if (discount > range.fee) {
111
124
  throw new Error("Discount cannot be greater than platform fee");
112
125
  }
126
+ else if (markup) {
127
+ const netFee = range.fee + markup;
128
+ platformFeeFiat = amountFiat * netFee;
129
+ }
113
130
  else {
114
131
  const netFee = range.fee - discount;
115
132
  platformFeeFiat = amountFiat * netFee;
@@ -123,7 +140,13 @@ const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, countr
123
140
  }
124
141
  // @ts-ignore
125
142
  if (platformFeeFiat === undefined) {
126
- const netPlatformFee = rioSettings.platformFee - discount;
143
+ let netPlatformFee = rioSettings.platformFee;
144
+ if (discount) {
145
+ netPlatformFee -= discount;
146
+ }
147
+ if (markup) {
148
+ netPlatformFee += markup;
149
+ }
127
150
  if (netPlatformFee < 0) {
128
151
  throw new Error("Discount cannot be greater than platform fee");
129
152
  }
@@ -132,7 +155,13 @@ const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, countr
132
155
  partnerFeeFiat = 0;
133
156
  }
134
157
  else {
135
- const netPlatformFee = rioSettings.platformFee - discount;
158
+ let netPlatformFee = rioSettings.platformFee;
159
+ if (discount) {
160
+ netPlatformFee -= discount;
161
+ }
162
+ if (markup) {
163
+ netPlatformFee += markup;
164
+ }
136
165
  if (netPlatformFee < 0) {
137
166
  throw new Error("Discount cannot be greater than platform fee");
138
167
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.782",
3
+ "version": "1.0.783",
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.688",
27
+ "@riocrypto/common": "^1.0.689",
28
28
  "@types/express": "^4.17.13",
29
29
  "axios": "^0.27.2",
30
30
  "ccxt": "^3.0.30",