@riocrypto/common-server 1.0.776 → 1.0.778

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,7 +1,7 @@
1
1
  import { Country, Fiat, Processor, User } from "@riocrypto/common";
2
2
  import { Mongoose } from "mongoose";
3
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
- platformFeeFiat: number;
4
+ platformFeeFiat: number | undefined;
5
5
  platformFeeFiatTax: number;
6
6
  partnerFeeFiat: number;
7
7
  feesComped: boolean;
@@ -19,7 +19,6 @@ const user_1 = require("../models/user");
19
19
  const calculate_aggregate_volume_1 = require("./calculate-aggregate-volume");
20
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
- console.log("user", user);
23
22
  let platformFeeFiat;
24
23
  let platformFeeFiatTax = 0;
25
24
  let partnerFeeFiat = 0;
@@ -62,6 +61,32 @@ const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, countr
62
61
  platformFeeFiat = amountFiat * netPlatformFee;
63
62
  partnerFeeFiat = amountFiat * partner.partnerFee;
64
63
  }
64
+ else if (brokerId) {
65
+ const User = (0, user_1.buildUser)(mongoose);
66
+ const brokerCustomer = yield User.findById(brokerId);
67
+ if (!brokerCustomer) {
68
+ throw new Error("Broker customer not found");
69
+ }
70
+ if (brokerCustomer === null || brokerCustomer === void 0 ? void 0 : brokerCustomer.platformFeeRanges) {
71
+ for (const range of brokerCustomer.platformFeeRanges) {
72
+ if (range.min <= Number(amountUSD) && range.max >= Number(amountUSD)) {
73
+ if (discount) {
74
+ if (discount > range.fee) {
75
+ throw new Error("Discount cannot be greater than platform fee");
76
+ }
77
+ else {
78
+ const netFee = range.fee - discount;
79
+ platformFeeFiat = amountFiat * netFee;
80
+ }
81
+ }
82
+ else {
83
+ platformFeeFiat = amountFiat * range.fee;
84
+ }
85
+ break;
86
+ }
87
+ }
88
+ }
89
+ }
65
90
  else if (user === null || user === void 0 ? void 0 : user.platformFeeRanges) {
66
91
  let volume;
67
92
  if ((_a = user === null || user === void 0 ? void 0 : user.attributes) === null || _a === void 0 ? void 0 : _a.includes(common_1.UserAttribute.summedVolumeFees)) {
@@ -71,11 +96,8 @@ const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, countr
71
96
  else {
72
97
  volume = Number(amountUSD);
73
98
  }
74
- console.log("Volume", volume);
75
99
  for (const range of user.platformFeeRanges) {
76
- console.log(range);
77
100
  if (range.min <= Number(volume) && range.max >= Number(volume)) {
78
- console.log("Hit");
79
101
  if (discount) {
80
102
  if (discount > range.fee) {
81
103
  throw new Error("Discount cannot be greater than platform fee");
@@ -91,7 +113,6 @@ const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, countr
91
113
  break;
92
114
  }
93
115
  }
94
- console.log("platformFeeFiat", platformFeeFiat);
95
116
  // @ts-ignore
96
117
  if (platformFeeFiat === undefined) {
97
118
  const netPlatformFee = rioSettings.platformFee - discount;
@@ -103,7 +124,6 @@ const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, countr
103
124
  partnerFeeFiat = 0;
104
125
  }
105
126
  else {
106
- console.log("tribeca");
107
127
  const netPlatformFee = rioSettings.platformFee - discount;
108
128
  if (netPlatformFee < 0) {
109
129
  throw new Error("Discount cannot be greater than platform fee");
@@ -111,33 +131,6 @@ const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, countr
111
131
  platformFeeFiat = amountFiat * netPlatformFee;
112
132
  partnerFeeFiat = 0;
113
133
  }
114
- if (brokerId && !platformFeeFiat) {
115
- console.log("plas");
116
- const User = (0, user_1.buildUser)(mongoose);
117
- const brokerCustomer = yield User.findById(brokerId);
118
- if (!brokerCustomer) {
119
- throw new Error("Broker customer not found");
120
- }
121
- if (brokerCustomer === null || brokerCustomer === void 0 ? void 0 : brokerCustomer.platformFeeRanges) {
122
- for (const range of brokerCustomer.platformFeeRanges) {
123
- if (range.min <= Number(amountUSD) && range.max >= Number(amountUSD)) {
124
- if (discount) {
125
- if (discount > range.fee) {
126
- throw new Error("Discount cannot be greater than platform fee");
127
- }
128
- else {
129
- const netFee = range.fee - discount;
130
- platformFeeFiat = amountFiat * netFee;
131
- }
132
- }
133
- else {
134
- platformFeeFiat = amountFiat * range.fee;
135
- }
136
- break;
137
- }
138
- }
139
- }
140
- }
141
134
  if ((fiat === common_1.Fiat.MXN && processor === common_1.Processor.SPEI) ||
142
135
  (fiat === common_1.Fiat.USD && processor === common_1.Processor.SPID)) {
143
136
  if (country === common_1.Country.Mexico) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.776",
3
+ "version": "1.0.778",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",