@riocrypto/common-server 1.0.631 → 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 {
|
|
2
|
-
export declare const getPlatformAndPartnerFees: (amountFiat: number,
|
|
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,7 +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 getPlatformAndPartnerFees = (amountFiat,
|
|
23
|
+
const getPlatformAndPartnerFees = (amountFiat, fiat, processor, country, partnerId, brokerCustomerId, user) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
24
|
let platformFeeFiat = 0;
|
|
25
25
|
let platformFeeFiatTax = 0;
|
|
26
26
|
let partnerFeeFiat = 0;
|
|
@@ -31,24 +31,24 @@ const getPlatformAndPartnerFees = (amountFiat, order, user) => __awaiter(void 0,
|
|
|
31
31
|
if (!rioSettings) {
|
|
32
32
|
throw new common_1.RioSettingsNotFoundError();
|
|
33
33
|
}
|
|
34
|
-
if (
|
|
34
|
+
if (processor === common_1.Processor.Kapstar) {
|
|
35
35
|
const kapstarClient = yield (0, kapstar_client_1.buildKapstarClient)();
|
|
36
36
|
conversionRateToUSD = yield kapstarClient.getBRLExchangeRateUSD();
|
|
37
37
|
}
|
|
38
|
-
else if (
|
|
38
|
+
else if (fiat !== common_1.Fiat.USD) {
|
|
39
39
|
const currencyAPIClient = yield (0, currency_api_client_1.buildCurrencyAPIClient)();
|
|
40
|
-
conversionRateToUSD = yield currencyAPIClient.convert(
|
|
40
|
+
conversionRateToUSD = yield currencyAPIClient.convert(fiat, common_1.Fiat.USD);
|
|
41
41
|
}
|
|
42
|
-
else if (
|
|
42
|
+
else if (fiat === common_1.Fiat.USD) {
|
|
43
43
|
conversionRateToUSD = 1;
|
|
44
44
|
}
|
|
45
45
|
amountUSD = amountFiat * conversionRateToUSD;
|
|
46
46
|
if (!amountUSD) {
|
|
47
47
|
throw new Error("Could not convert amount to USD");
|
|
48
48
|
}
|
|
49
|
-
if (
|
|
49
|
+
if (partnerId) {
|
|
50
50
|
const Partner = (0, partner_1.buildPartner)(mongoose_1.default);
|
|
51
|
-
const partner = yield Partner.findById(
|
|
51
|
+
const partner = yield Partner.findById(partnerId);
|
|
52
52
|
if (!partner) {
|
|
53
53
|
throw new common_1.PartnerNotFoundError();
|
|
54
54
|
}
|
|
@@ -72,9 +72,9 @@ const getPlatformAndPartnerFees = (amountFiat, order, user) => __awaiter(void 0,
|
|
|
72
72
|
platformFeeFiat = amountFiat * rioSettings.platformFee;
|
|
73
73
|
partnerFeeFiat = 0;
|
|
74
74
|
}
|
|
75
|
-
if (
|
|
75
|
+
if (brokerCustomerId) {
|
|
76
76
|
const BusinessUser = (0, business_user_1.buildBusinessUser)(mongoose_1.default);
|
|
77
|
-
const brokerCustomer = yield BusinessUser.findById(
|
|
77
|
+
const brokerCustomer = yield BusinessUser.findById(brokerCustomerId);
|
|
78
78
|
if (!brokerCustomer) {
|
|
79
79
|
throw new Error("Business user not found");
|
|
80
80
|
}
|
|
@@ -87,14 +87,14 @@ const getPlatformAndPartnerFees = (amountFiat, order, user) => __awaiter(void 0,
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
if ((
|
|
91
|
-
(
|
|
92
|
-
if (
|
|
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) {
|
|
93
93
|
platformFeeFiatTax = platformFeeFiat * 0.16;
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
if (
|
|
97
|
-
if (
|
|
96
|
+
if (fiat === common_1.Fiat.PEN && processor === common_1.Processor.Interbank) {
|
|
97
|
+
if (country === common_1.Country.Peru) {
|
|
98
98
|
platformFeeFiatTax = platformFeeFiat * 0.18;
|
|
99
99
|
}
|
|
100
100
|
}
|