@riocrypto/common-server 1.0.577 → 1.0.579

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,13 @@
1
+ import { BusinessUser, KapstarInvoiceResponse, User } from "@riocrypto/common";
2
+ import { Axios } from "axios";
1
3
  declare class KapstarClient {
2
- constructor();
4
+ private userId;
5
+ private apiKey;
6
+ axiosInstance: Axios;
7
+ constructor(userId: string, apiKey: string);
3
8
  getBRLExchangeRateUSD(): Promise<number>;
9
+ createInvoice(amount: number, orderId: string, user: User | BusinessUser): Promise<KapstarInvoiceResponse>;
10
+ createPIXPayment(amount: number, pixKey: string): Promise<KapstarInvoiceResponse>;
4
11
  }
5
- export declare const kapstarClient: KapstarClient;
12
+ export declare const buildKapstarClient: () => Promise<KapstarClient>;
6
13
  export {};
@@ -12,15 +12,61 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.kapstarClient = void 0;
15
+ exports.buildKapstarClient = void 0;
16
+ const common_1 = require("@riocrypto/common");
16
17
  const axios_1 = __importDefault(require("axios"));
18
+ const secret_manager_client_1 = require("./secret-manager-client");
17
19
  class KapstarClient {
18
- constructor() { }
20
+ constructor(userId, apiKey) {
21
+ this.userId = userId;
22
+ this.apiKey = apiKey;
23
+ this.axiosInstance = axios_1.default.create({
24
+ baseURL: `https://api.ecsa.finance/transaction-service/v1/external/pix-payment`,
25
+ headers: {
26
+ "User-Id": this.userId,
27
+ "X-Api-key": this.apiKey,
28
+ },
29
+ });
30
+ }
19
31
  getBRLExchangeRateUSD() {
20
32
  return __awaiter(this, void 0, void 0, function* () {
21
- const kapstarResponse = yield axios_1.default.get(`https://api.ecsa.finance/quotation-service/v1/quotation/last`);
33
+ const kapstarResponse = yield this.axiosInstance.get("/quotation-service/v1/quotation/last");
22
34
  return 1 / kapstarResponse.data;
23
35
  });
24
36
  }
37
+ createInvoice(amount, orderId, user) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ const kapstarResponse = yield this.axiosInstance.post("/transaction-service/v1/external/invoice", {
40
+ amount,
41
+ name: user.type === common_1.UserType.Business
42
+ ? user.companyName
43
+ : user.firstName + " " + user.lastName,
44
+ tax_id: user.cpf,
45
+ tags: [orderId],
46
+ });
47
+ return kapstarResponse.data;
48
+ });
49
+ }
50
+ createPIXPayment(amount, pixKey) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ const kapstarResponse = yield axios_1.default.post("/transaction-service/v1/external/pix-payment", {
53
+ amount: amount,
54
+ pix_key: pixKey,
55
+ });
56
+ return kapstarResponse.data;
57
+ });
58
+ }
25
59
  }
26
- exports.kapstarClient = new KapstarClient();
60
+ const buildKapstarClient = () => __awaiter(void 0, void 0, void 0, function* () {
61
+ const KAPSTAR_USER_ID = yield secret_manager_client_1.secretManagerClient.getSecretValue("KAPSTAR_USER_ID");
62
+ if (!KAPSTAR_USER_ID) {
63
+ throw new Error("Unable to get KAPSTAR_USER_ID");
64
+ }
65
+ const KAPSTAR_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("KAPSTAR_API_KEY");
66
+ if (!KAPSTAR_API_KEY) {
67
+ throw new Error("Unable to get KAPSTAR_API_KEY");
68
+ }
69
+ const kapstarClient = new KapstarClient(KAPSTAR_USER_ID, KAPSTAR_API_KEY);
70
+ return kapstarClient;
71
+ });
72
+ exports.buildKapstarClient = buildKapstarClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.577",
3
+ "version": "1.0.579",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -23,7 +23,7 @@
23
23
  "dependencies": {
24
24
  "@aws-sdk/client-s3": "^3.297.0",
25
25
  "@google-cloud/storage": "^6.9.5",
26
- "@riocrypto/common": "^1.0.559",
26
+ "@riocrypto/common": "^1.0.561",
27
27
  "@types/express": "^4.17.13",
28
28
  "axios": "^0.27.2",
29
29
  "ccxt": "^3.0.30",