@riocrypto/common-server 1.0.632 → 1.0.633

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,5 +1,5 @@
1
- import { Order } from "@riocrypto/common";
2
- export declare const getPlatformAndPartnerFees: (amountFiat: number, order: Order) => Promise<{
1
+ import { BusinessUser, Country, Fiat, Processor, User } from "@riocrypto/common";
2
+ export declare const getPlatformAndPartnerFees: (amountFiat: number, fiat: Fiat, processor: Processor, country: Country, partnerId?: string, brokerCustomerId?: string, user?: BusinessUser | User) => Promise<{
3
3
  platformFeeFiat: number;
4
4
  platformFeeFiatTax: number;
5
5
  partnerFeeFiat: number;
@@ -20,8 +20,7 @@ const kapstar_client_1 = require("../clients/kapstar-client");
20
20
  const currency_api_client_1 = require("../clients/currency-api-client");
21
21
  const partner_1 = require("../models/partner");
22
22
  const business_user_1 = require("../models/business-user");
23
- const get_user_helper_1 = require("./get-user-helper");
24
- const getPlatformAndPartnerFees = (amountFiat, order) => __awaiter(void 0, void 0, void 0, function* () {
23
+ const getPlatformAndPartnerFees = (amountFiat, fiat, processor, country, partnerId, brokerCustomerId, user) => __awaiter(void 0, void 0, void 0, function* () {
25
24
  let platformFeeFiat = 0;
26
25
  let platformFeeFiatTax = 0;
27
26
  let partnerFeeFiat = 0;
@@ -32,28 +31,24 @@ const getPlatformAndPartnerFees = (amountFiat, order) => __awaiter(void 0, void
32
31
  if (!rioSettings) {
33
32
  throw new common_1.RioSettingsNotFoundError();
34
33
  }
35
- const user = yield (0, get_user_helper_1.getUserHelper)(order.userId, mongoose_1.default);
36
- if (!user) {
37
- throw new Error("User not found");
38
- }
39
- if (order.processor === common_1.Processor.Kapstar) {
34
+ if (processor === common_1.Processor.Kapstar) {
40
35
  const kapstarClient = yield (0, kapstar_client_1.buildKapstarClient)();
41
36
  conversionRateToUSD = yield kapstarClient.getBRLExchangeRateUSD();
42
37
  }
43
- else if (order.fiat !== common_1.Fiat.USD) {
38
+ else if (fiat !== common_1.Fiat.USD) {
44
39
  const currencyAPIClient = yield (0, currency_api_client_1.buildCurrencyAPIClient)();
45
- conversionRateToUSD = yield currencyAPIClient.convert(order.fiat, common_1.Fiat.USD);
40
+ conversionRateToUSD = yield currencyAPIClient.convert(fiat, common_1.Fiat.USD);
46
41
  }
47
- else if (order.fiat === common_1.Fiat.USD) {
42
+ else if (fiat === common_1.Fiat.USD) {
48
43
  conversionRateToUSD = 1;
49
44
  }
50
45
  amountUSD = amountFiat * conversionRateToUSD;
51
46
  if (!amountUSD) {
52
47
  throw new Error("Could not convert amount to USD");
53
48
  }
54
- if (order.partnerId) {
49
+ if (partnerId) {
55
50
  const Partner = (0, partner_1.buildPartner)(mongoose_1.default);
56
- const partner = yield Partner.findById(order.partnerId);
51
+ const partner = yield Partner.findById(partnerId);
57
52
  if (!partner) {
58
53
  throw new common_1.PartnerNotFoundError();
59
54
  }
@@ -77,9 +72,9 @@ const getPlatformAndPartnerFees = (amountFiat, order) => __awaiter(void 0, void
77
72
  platformFeeFiat = amountFiat * rioSettings.platformFee;
78
73
  partnerFeeFiat = 0;
79
74
  }
80
- if (order.brokerCustomerId) {
75
+ if (brokerCustomerId) {
81
76
  const BusinessUser = (0, business_user_1.buildBusinessUser)(mongoose_1.default);
82
- const brokerCustomer = yield BusinessUser.findById(order.brokerCustomerId);
77
+ const brokerCustomer = yield BusinessUser.findById(brokerCustomerId);
83
78
  if (!brokerCustomer) {
84
79
  throw new Error("Business user not found");
85
80
  }
@@ -92,14 +87,14 @@ const getPlatformAndPartnerFees = (amountFiat, order) => __awaiter(void 0, void
92
87
  }
93
88
  }
94
89
  }
95
- if ((order.fiat === common_1.Fiat.MXN && order.processor === common_1.Processor.SPEI) ||
96
- (order.fiat === common_1.Fiat.USD && order.processor === common_1.Processor.SPID)) {
97
- if (user.country === common_1.Country.Mexico) {
90
+ if ((fiat === common_1.Fiat.MXN && processor === common_1.Processor.SPEI) ||
91
+ (fiat === common_1.Fiat.USD && processor === common_1.Processor.SPID)) {
92
+ if (country === common_1.Country.Mexico) {
98
93
  platformFeeFiatTax = platformFeeFiat * 0.16;
99
94
  }
100
95
  }
101
- if (order.fiat === common_1.Fiat.PEN && order.processor === common_1.Processor.Interbank) {
102
- if (user.country === common_1.Country.Peru) {
96
+ if (fiat === common_1.Fiat.PEN && processor === common_1.Processor.Interbank) {
97
+ if (country === common_1.Country.Peru) {
103
98
  platformFeeFiatTax = platformFeeFiat * 0.18;
104
99
  }
105
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.632",
3
+ "version": "1.0.633",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",