@riocrypto/common-server 1.0.1468 → 1.0.1469
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,9 +1,10 @@
|
|
|
1
1
|
import { Order, User } from "@riocrypto/common";
|
|
2
|
+
import { Mongoose } from "mongoose";
|
|
2
3
|
declare class InvopopClient {
|
|
3
4
|
private apiKey;
|
|
4
5
|
private baseUrl;
|
|
5
6
|
constructor(apiKey: string);
|
|
6
|
-
createJob(order: Order, user: User): Promise<{
|
|
7
|
+
createJob(mongoose: Mongoose, order: Order, user: User): Promise<{
|
|
7
8
|
id: string;
|
|
8
9
|
}>;
|
|
9
10
|
getJob(id: string): Promise<{
|
|
@@ -17,12 +17,13 @@ const secret_manager_client_1 = require("./secret-manager-client");
|
|
|
17
17
|
const axios_1 = __importDefault(require("axios"));
|
|
18
18
|
const common_1 = require("@riocrypto/common");
|
|
19
19
|
const uuid_1 = require("uuid");
|
|
20
|
+
const market_data_1 = require("../models/market-data");
|
|
20
21
|
class InvopopClient {
|
|
21
22
|
constructor(apiKey) {
|
|
22
23
|
this.apiKey = apiKey;
|
|
23
24
|
this.baseUrl = "https://api.invopop.com";
|
|
24
25
|
}
|
|
25
|
-
createJob(order, user) {
|
|
26
|
+
createJob(mongoose, order, user) {
|
|
26
27
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
27
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
29
|
const uuid = (0, uuid_1.v1)();
|
|
@@ -81,6 +82,17 @@ class InvopopClient {
|
|
|
81
82
|
if (!cfdiUseCode) {
|
|
82
83
|
throw new Error("CFDI use code not found");
|
|
83
84
|
}
|
|
85
|
+
const isUSDOrder = order.fiat === common_1.Fiat.USD;
|
|
86
|
+
const MarketData = (0, market_data_1.buildMarketData)(mongoose);
|
|
87
|
+
const marketData = yield MarketData.findOne();
|
|
88
|
+
if (!marketData) {
|
|
89
|
+
throw new common_1.NotFoundError("Market data");
|
|
90
|
+
}
|
|
91
|
+
if (isUSDOrder &&
|
|
92
|
+
(!marketData.previousDayConversionRatesFromUSD.MXN.value ||
|
|
93
|
+
!marketData.previousDayConversionRatesToUSD.MXN.value)) {
|
|
94
|
+
throw new Error("Missing previous day MXN<>USD exchange rates");
|
|
95
|
+
}
|
|
84
96
|
const { data } = yield axios_1.default.put(`${this.baseUrl}/transform/v1/jobs/${uuid}`, {
|
|
85
97
|
workflow_id: "5b123900-1035-4c8c-a97a-36b940d7a21e",
|
|
86
98
|
data: {
|
|
@@ -129,7 +141,10 @@ class InvopopClient {
|
|
|
129
141
|
item: {
|
|
130
142
|
name: "Facilitación de Compra-Venta de Activos Virtuales",
|
|
131
143
|
identities: [{ key: "mx-cfdi-prod-serv", code: "80151500" }],
|
|
132
|
-
price:
|
|
144
|
+
price: !isUSDOrder
|
|
145
|
+
? (_r = order.actualFees.platformFeeFiat) === null || _r === void 0 ? void 0 : _r.toFixed(2)
|
|
146
|
+
: (order.actualFees.platformFeeFiat || 0) *
|
|
147
|
+
marketData.previousDayConversionRatesFromUSD.MXN.value,
|
|
133
148
|
},
|
|
134
149
|
taxes: [
|
|
135
150
|
{
|