@yosle/tropipayjs 0.1.22 → 0.1.24
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.
- package/.nvmrc +1 -1
- package/.vscode/launch.json +18 -18
- package/LICENSE +9 -9
- package/README.md +152 -152
- package/api/TropipayAPI.d.ts +2 -0
- package/docs/readme.md +3 -3
- package/globals.d.ts +75 -75
- package/index.d.ts +11 -6
- package/index.js +910 -870
- package/interfaces/countries/index.d.ts +1 -1
- package/interfaces/index.d.ts +9 -6
- package/jest.config.js +5 -5
- package/package.json +49 -49
- package/paymentcard/paymentcard.spec.d.ts +1 -1
- package/rollup.config.js +24 -24
- package/src/api/TropipayAPI.ts +383 -338
- package/src/config/TropipayConfig.ts +2 -2
- package/src/constants/TropipayConstants.ts +2 -2
- package/src/depositAccount/depositAccounts.ts +139 -139
- package/src/hooks/TropipayHooks.ts +154 -154
- package/src/index.ts +28 -28
- package/src/interfaces/depositaccounts/index.ts +70 -70
- package/src/interfaces/index.js +1 -1
- package/src/interfaces/index.ts +201 -197
- package/src/interfaces/mediation/index.ts +22 -22
- package/src/interfaces/paymentlink/index.d.ts +36 -36
- package/src/interfaces/paymentlink/index.js +2 -2
- package/src/interfaces/paymentlink/index.ts +91 -91
- package/src/mediationPaymentCard/MediationPaymentCard.ts +42 -42
- package/src/paymentcard/PaymentCard.ts +123 -123
- package/src/paymentcard/paymentcard.spec.ts +79 -79
- package/src/utils/TropipayUtils.ts +126 -126
- package/src/utils/errors.ts +92 -92
- package/tsconfig.json +96 -96
package/src/api/TropipayAPI.ts
CHANGED
|
@@ -1,338 +1,383 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tropipayjs is a Typescript/Javascript library for the Tropipay API.
|
|
3
|
-
*
|
|
4
|
-
* @author Yosleivy Baez Acosta
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import axios, { Axios } from "axios";
|
|
9
|
-
import {
|
|
10
|
-
TropipayConfig,
|
|
11
|
-
AccountBalance,
|
|
12
|
-
Country,
|
|
13
|
-
PaymentLinkPayload,
|
|
14
|
-
PaymentLink,
|
|
15
|
-
MediationPaymentCardConfig,
|
|
16
|
-
LoginResponse,
|
|
17
|
-
AccountDeposits,
|
|
18
|
-
} from "../interfaces";
|
|
19
|
-
type ServerMode = "Development" | "Production";
|
|
20
|
-
import TropipayHooks from "../hooks/TropipayHooks";
|
|
21
|
-
import PaymentCard from "../paymentcard/PaymentCard";
|
|
22
|
-
import MediationPaymentCard from "../mediationPaymentCard/MediationPaymentCard";
|
|
23
|
-
import DepositAccounts from "../depositAccount/depositAccounts";
|
|
24
|
-
import { TropipayJSException, handleExceptions } from "../utils/errors";
|
|
25
|
-
export class Tropipay {
|
|
26
|
-
readonly clientId: string;
|
|
27
|
-
readonly clientSecret: string;
|
|
28
|
-
readonly scopes: String[];
|
|
29
|
-
public request: Axios;
|
|
30
|
-
public
|
|
31
|
-
public static
|
|
32
|
-
public
|
|
33
|
-
public
|
|
34
|
-
public
|
|
35
|
-
public
|
|
36
|
-
public
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
*
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this.
|
|
73
|
-
this.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
Tropipay.refreshToken
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
{
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Tropipayjs is a Typescript/Javascript library for the Tropipay API.
|
|
3
|
+
*
|
|
4
|
+
* @author Yosleivy Baez Acosta
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import axios, { Axios, AxiosError, AxiosRequestConfig } from "axios";
|
|
9
|
+
import {
|
|
10
|
+
TropipayConfig,
|
|
11
|
+
AccountBalance,
|
|
12
|
+
Country,
|
|
13
|
+
PaymentLinkPayload,
|
|
14
|
+
PaymentLink,
|
|
15
|
+
MediationPaymentCardConfig,
|
|
16
|
+
LoginResponse,
|
|
17
|
+
AccountDeposits,
|
|
18
|
+
} from "../interfaces";
|
|
19
|
+
type ServerMode = "Development" | "Production";
|
|
20
|
+
import TropipayHooks from "../hooks/TropipayHooks";
|
|
21
|
+
import PaymentCard from "../paymentcard/PaymentCard";
|
|
22
|
+
import MediationPaymentCard from "../mediationPaymentCard/MediationPaymentCard";
|
|
23
|
+
import DepositAccounts from "../depositAccount/depositAccounts";
|
|
24
|
+
import { TropipayJSException, handleExceptions } from "../utils/errors";
|
|
25
|
+
export class Tropipay {
|
|
26
|
+
readonly clientId: string;
|
|
27
|
+
readonly clientSecret: string;
|
|
28
|
+
readonly scopes: String[];
|
|
29
|
+
public request: Axios;
|
|
30
|
+
public loginRequest: Axios;
|
|
31
|
+
public static accessToken: string | null;
|
|
32
|
+
public static refreshToken: string | null;
|
|
33
|
+
public static expiresIn: number | null;
|
|
34
|
+
public serverMode: ServerMode;
|
|
35
|
+
public hooks: TropipayHooks;
|
|
36
|
+
public paymentCards: PaymentCard;
|
|
37
|
+
public depositAccounts: DepositAccounts;
|
|
38
|
+
public mediationPaymentCard: MediationPaymentCard;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Initializes a new instance of the Tropipay class.
|
|
42
|
+
*
|
|
43
|
+
* @param {TropipayConfig} config - The configuration object.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
constructor(config: TropipayConfig) {
|
|
47
|
+
// use all scopes if none is passed
|
|
48
|
+
if (!config?.scopes) {
|
|
49
|
+
this.scopes = [
|
|
50
|
+
"ALLOW_GET_PROFILE_DATA",
|
|
51
|
+
"ALLOW_PAYMENT_IN",
|
|
52
|
+
"ALLOW_EXTERNAL_CHARGE",
|
|
53
|
+
"KYC3_FULL_ALLOW",
|
|
54
|
+
"ALLOW_PAYMENT_OUT",
|
|
55
|
+
"ALLOW_MARKET_PURCHASES",
|
|
56
|
+
"ALLOW_GET_BALANCE",
|
|
57
|
+
"ALLOW_GET_MOVEMENT_LIST",
|
|
58
|
+
"ALLOW_GET_CREDENTIAL",
|
|
59
|
+
];
|
|
60
|
+
} else {
|
|
61
|
+
this.scopes = config.scopes;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!config.clientId || !config.clientSecret) {
|
|
65
|
+
throw new TropipayJSException(
|
|
66
|
+
`You must pass clientId and clientSecret in Tropipay constructor`,
|
|
67
|
+
400,
|
|
68
|
+
null
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
this.clientId = config.clientId;
|
|
73
|
+
this.clientSecret = config.clientSecret;
|
|
74
|
+
this.serverMode = config.serverMode || "Development";
|
|
75
|
+
|
|
76
|
+
const tpp_env = this.serverMode === "Production"
|
|
77
|
+
? "https://www.tropipay.com"
|
|
78
|
+
: "https://tropipay-dev.herokuapp.com";
|
|
79
|
+
this.request = axios.create({
|
|
80
|
+
baseURL: config.customTropipayUrl || tpp_env,
|
|
81
|
+
headers: {
|
|
82
|
+
"Content-Type": "application/json",
|
|
83
|
+
Accept: "application/json",
|
|
84
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Create a separate instance for login requests
|
|
89
|
+
this.loginRequest = axios.create({
|
|
90
|
+
baseURL: tpp_env,
|
|
91
|
+
headers: {
|
|
92
|
+
"Content-Type": "application/json",
|
|
93
|
+
Accept: "application/json",
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Add request interceptor for Token expired
|
|
98
|
+
this.request.interceptors.request.use(
|
|
99
|
+
async (config: any) => {
|
|
100
|
+
const currentTimestamp = Math.floor(Date.now() / 1000); // Current time in seconds
|
|
101
|
+
|
|
102
|
+
if (Tropipay.expiresIn && Tropipay.expiresIn < currentTimestamp) {
|
|
103
|
+
// Token has expired, attempt to refresh it
|
|
104
|
+
try {
|
|
105
|
+
await this.login();
|
|
106
|
+
} catch (error) {
|
|
107
|
+
// Handle token refresh error
|
|
108
|
+
Tropipay.accessToken = null;
|
|
109
|
+
Tropipay.refreshToken = null;
|
|
110
|
+
throw handleExceptions(error as any);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return config;
|
|
115
|
+
},
|
|
116
|
+
(error: AxiosError) => {
|
|
117
|
+
return Promise.reject(error);
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
this.hooks = new TropipayHooks(this);
|
|
122
|
+
this.paymentCards = new PaymentCard(this);
|
|
123
|
+
this.mediationPaymentCard = new MediationPaymentCard(this);
|
|
124
|
+
|
|
125
|
+
this.depositAccounts = new DepositAccounts(this);
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public async login() {
|
|
133
|
+
try {
|
|
134
|
+
if (Tropipay.refreshToken) {
|
|
135
|
+
const { data } = await this.loginRequest.post<LoginResponse>(
|
|
136
|
+
"/api/v2/access/token",
|
|
137
|
+
{
|
|
138
|
+
client_id: this.clientId,
|
|
139
|
+
client_secret: this.clientSecret,
|
|
140
|
+
grant_type: "refresh_token",
|
|
141
|
+
refresh_token: Tropipay.refreshToken,
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
headers: {
|
|
145
|
+
"Content-Type": "application/json",
|
|
146
|
+
Accept: "application/json",
|
|
147
|
+
},
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
return data;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// normal credetials login
|
|
154
|
+
const { data } = await this.loginRequest.post<LoginResponse>(
|
|
155
|
+
"/api/v2/access/token",
|
|
156
|
+
{
|
|
157
|
+
client_id: this.clientId,
|
|
158
|
+
client_secret: this.clientSecret,
|
|
159
|
+
grant_type: "client_credentials",
|
|
160
|
+
scope: this.scopes.join(" "), // "ALLOW_GET_PROFILE_DATA ALLOW_PAYMENT_IN ALLOW_EXTERNAL_CHARGE KYC3_FULL_ALLOW ALLOW_PAYMENT_OUT ALLOW_MARKET_PURCHASES ALLOW_GET_BALANCE ALLOW_GET_MOVEMENT_LIST ALLOW_GET_CREDENTIAL",
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
headers: {
|
|
164
|
+
"Content-Type": "application/json",
|
|
165
|
+
Accept: "application/json",
|
|
166
|
+
},
|
|
167
|
+
}
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
Tropipay.accessToken = data.access_token;
|
|
171
|
+
Tropipay.refreshToken = data.refresh_token;
|
|
172
|
+
Tropipay.expiresIn = data.expires_in;
|
|
173
|
+
Tropipay.expiresIn = data.expires_in;
|
|
174
|
+
return data;
|
|
175
|
+
} catch (error) {
|
|
176
|
+
Tropipay.accessToken = null;
|
|
177
|
+
Tropipay.refreshToken = null;
|
|
178
|
+
Tropipay.expiresIn = null;
|
|
179
|
+
Tropipay.expiresIn = null;
|
|
180
|
+
throw handleExceptions(error as any);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Get the list of all supported countries by Tropipay.
|
|
186
|
+
* @returns Array of Countries Data
|
|
187
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/bfac21259e2ff-getting-users-countries-list
|
|
188
|
+
*/
|
|
189
|
+
async countries(): Promise<Country[]> {
|
|
190
|
+
try {
|
|
191
|
+
const countries = await this.request.get("/api/v2/countries");
|
|
192
|
+
return countries.data;
|
|
193
|
+
} catch (error) {
|
|
194
|
+
throw handleExceptions(error as any);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Get user balance
|
|
199
|
+
* @returns balance Object { balance: number, pendingIn: number, pendingOut: number }
|
|
200
|
+
*/
|
|
201
|
+
async getBalance(): Promise<AccountBalance> {
|
|
202
|
+
if (!Tropipay.accessToken) {
|
|
203
|
+
await this.login();
|
|
204
|
+
}
|
|
205
|
+
try {
|
|
206
|
+
const balance = await this.request.get("/api/v2/users/balance", {
|
|
207
|
+
headers: {
|
|
208
|
+
"Content-Type": "application/json",
|
|
209
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
210
|
+
Accept: "application/json",
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
return balance.data;
|
|
214
|
+
} catch (error) {
|
|
215
|
+
throw handleExceptions(error as any);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Get the list of all detination countries supported by Tropipay.
|
|
221
|
+
* Obtaining the list of valid countries to send funds to. Useful
|
|
222
|
+
* when adding new beneficiaries to some user.
|
|
223
|
+
*
|
|
224
|
+
* @returns Array of Country Objects
|
|
225
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/3cfe5504f0524-getting-list-of-beneficiary-countries
|
|
226
|
+
*/
|
|
227
|
+
async destinations(): Promise<Country[]> {
|
|
228
|
+
try {
|
|
229
|
+
const countries = await this.request.get(
|
|
230
|
+
"/api/v2/countries/destinations"
|
|
231
|
+
);
|
|
232
|
+
return countries.data;
|
|
233
|
+
} catch (error) {
|
|
234
|
+
throw new Error(`Could not retrieve the destination countries list`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Get list of all the favorites payment links.
|
|
240
|
+
* @returns Array of account Object or throws an error
|
|
241
|
+
*/
|
|
242
|
+
async favorites() {
|
|
243
|
+
if (!Tropipay.accessToken) {
|
|
244
|
+
await this.login();
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
const favoritesList = await this.request.get(
|
|
248
|
+
"/api/v2/paymentcards/favorites",
|
|
249
|
+
{
|
|
250
|
+
headers: {
|
|
251
|
+
"Content-Type": "application/json",
|
|
252
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
253
|
+
Accept: "application/json",
|
|
254
|
+
},
|
|
255
|
+
}
|
|
256
|
+
);
|
|
257
|
+
return favoritesList?.data?.rows;
|
|
258
|
+
} catch (error) {
|
|
259
|
+
throw handleExceptions(error as any);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* List all account movements. You can optionaly specify
|
|
265
|
+
* offset and limit params for pagination.
|
|
266
|
+
* @returns
|
|
267
|
+
*/
|
|
268
|
+
async movements(offset = 0, limit = 10) {
|
|
269
|
+
if (!Tropipay.accessToken) await this.login();
|
|
270
|
+
|
|
271
|
+
try {
|
|
272
|
+
const movements = await this.request.get("/api/v2/movements", {
|
|
273
|
+
params: { limit: limit, offset: offset },
|
|
274
|
+
headers: {
|
|
275
|
+
"Content-Type": "application/json",
|
|
276
|
+
Accept: "application/json",
|
|
277
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
278
|
+
},
|
|
279
|
+
});
|
|
280
|
+
return movements.data;
|
|
281
|
+
} catch (error) {
|
|
282
|
+
throw handleExceptions(error as any);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Return profile data for current Tropipay account.
|
|
288
|
+
* @returns account object
|
|
289
|
+
*/
|
|
290
|
+
async profile() {
|
|
291
|
+
if (!Tropipay.accessToken) await this.login();
|
|
292
|
+
try {
|
|
293
|
+
const profile = await this.request.get("/api/users/profile");
|
|
294
|
+
return profile.data;
|
|
295
|
+
} catch (error) {
|
|
296
|
+
throw handleExceptions(error as any);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Obtain current Tropipay conversion rate. For example USD to EUR
|
|
302
|
+
* targetCurrency must be 'EUR'
|
|
303
|
+
* @param originCurrency Target currency code supported by Tropipay.
|
|
304
|
+
* @param targetCurrency Must be 'EUR'? (not documented by Tropipay)
|
|
305
|
+
* @returns Conversion rate (number)
|
|
306
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/85163f6f28b23-get-rate
|
|
307
|
+
*/
|
|
308
|
+
async rates(
|
|
309
|
+
originCurrency: string,
|
|
310
|
+
targetCurrency: string = "EUR"
|
|
311
|
+
): Promise<number | Error> {
|
|
312
|
+
if (!Tropipay.accessToken) {
|
|
313
|
+
await this.login();
|
|
314
|
+
}
|
|
315
|
+
try {
|
|
316
|
+
const rates = await this.request.post(
|
|
317
|
+
"/api/v2/movements/get_rate",
|
|
318
|
+
{
|
|
319
|
+
currencyFrom: originCurrency,
|
|
320
|
+
currencyTo: targetCurrency,
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
headers: {
|
|
324
|
+
"Content-Type": "application/json",
|
|
325
|
+
Accept: "application/json",
|
|
326
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
327
|
+
},
|
|
328
|
+
}
|
|
329
|
+
);
|
|
330
|
+
return rates.data.rate;
|
|
331
|
+
} catch (error) {
|
|
332
|
+
throw handleExceptions(error as any);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* (ONLY in Bussiness Accounts)
|
|
338
|
+
* An escrow payment link. This allows a payment to be made to persons
|
|
339
|
+
* belonging or not to the TropiPay platform with the particularity
|
|
340
|
+
* that the payment will be held in custody or retained until it is
|
|
341
|
+
* released with the approval of the payer.
|
|
342
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/12a128ff971e4-creating-a-mediation-payment-card
|
|
343
|
+
* @param config Payload with the payment details
|
|
344
|
+
*/
|
|
345
|
+
async createMediationPaymentCard(
|
|
346
|
+
config: MediationPaymentCardConfig
|
|
347
|
+
): Promise<PaymentLink> {
|
|
348
|
+
if (!Tropipay.accessToken) await this.login();
|
|
349
|
+
try {
|
|
350
|
+
const mediation = await this.request.post(
|
|
351
|
+
"/api/v2/paymentcards/mediation",
|
|
352
|
+
config,
|
|
353
|
+
{
|
|
354
|
+
headers: {
|
|
355
|
+
"Content-Type": "application/json",
|
|
356
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
357
|
+
Accept: "application/json",
|
|
358
|
+
},
|
|
359
|
+
}
|
|
360
|
+
);
|
|
361
|
+
return mediation.data as PaymentLink;
|
|
362
|
+
} catch (error) {
|
|
363
|
+
throw handleExceptions(error as any);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export class ClientSideUtils {
|
|
369
|
+
constructor(tropipayInstance: Tropipay) {
|
|
370
|
+
throw Error(`Not implemented yet`);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export const Scopes = {
|
|
375
|
+
ALLOW_PAYMENT_IN: "ALLOW_PAYMENT_IN",
|
|
376
|
+
ALLOW_EXTERNAL_CHARGE: "ALLOW_EXTERNAL_CHARGE",
|
|
377
|
+
KYC3_FULL_ALLOW: "KYC3_FULL_ALLOW",
|
|
378
|
+
ALLOW_PAYMENT_OUT: "ALLOW_PAYMENT_OUT",
|
|
379
|
+
ALLOW_MARKET_PURCHASES: "ALLOW_MARKET_PURCHASES",
|
|
380
|
+
ALLOW_GET_BALANCE: "ALLOW_GET_BALANCE",
|
|
381
|
+
ALLOW_GET_MOVEMENT_LIST: "ALLOW_GET_MOVEMENT_LIST",
|
|
382
|
+
ALLOW_GET_CREDENTIAL: "ALLOW_GET_CREDENTIAL",
|
|
383
|
+
};
|