@yosle/tropipayjs 0.1.15 → 0.1.17
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/index.d.ts +2 -1
- package/index.js +70 -29
- package/interfaces/depositaccounts/index.d.ts +42 -1
- package/package.json +1 -1
- package/src/api/TropipayAPI.ts +13 -19
- package/src/depositAccount/depositAccounts.ts +7 -6
- package/src/hooks/TropipayHooks.ts +6 -5
- package/src/interfaces/depositaccounts/index.ts +44 -1
- package/src/paymentcard/PaymentCard.ts +3 -2
- package/src/utils/TropipayUtils.ts +3 -4
- package/src/utils/errors.ts +97 -0
- package/utils/errors.d.ts +17 -0
package/index.d.ts
CHANGED
|
@@ -225,7 +225,7 @@ interface DepositAccountConfig {
|
|
|
225
225
|
searchBy?: number;
|
|
226
226
|
accountNumber?: string;
|
|
227
227
|
swift?: string;
|
|
228
|
-
type
|
|
228
|
+
type: DepositAccountType;
|
|
229
229
|
firstName?: string;
|
|
230
230
|
lastName?: string;
|
|
231
231
|
secondLastName?: string;
|
|
@@ -243,6 +243,7 @@ interface DepositAccountConfig {
|
|
|
243
243
|
type INTERNAL = 1;
|
|
244
244
|
type EXTERNAL = 2;
|
|
245
245
|
type BeneficiaryType = INTERNAL | EXTERNAL;
|
|
246
|
+
type DepositAccountType = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11;
|
|
246
247
|
|
|
247
248
|
declare class DepositAccounts {
|
|
248
249
|
private tropipay;
|
package/index.js
CHANGED
|
@@ -28,6 +28,51 @@ function _interopNamespace(e) {
|
|
|
28
28
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
29
29
|
var crypto__namespace = /*#__PURE__*/_interopNamespace(crypto);
|
|
30
30
|
|
|
31
|
+
function handleExceptions(error) {
|
|
32
|
+
if (error instanceof axios.AxiosError) {
|
|
33
|
+
if (error.response) {
|
|
34
|
+
const axiosResponse = error.response;
|
|
35
|
+
const errorMessage = axiosResponse.data?.error?.message || "An error occurred";
|
|
36
|
+
switch (axiosResponse.status) {
|
|
37
|
+
case 401:
|
|
38
|
+
return new TropipayJSException(errorMessage, axiosResponse.status, axiosResponse.data.error);
|
|
39
|
+
case 403:
|
|
40
|
+
return new TropipayJSException(errorMessage, axiosResponse.status, axiosResponse.data.error);
|
|
41
|
+
case 404:
|
|
42
|
+
return new TropipayJSException(errorMessage, axiosResponse.status, axiosResponse.data.error);
|
|
43
|
+
// case 429:
|
|
44
|
+
// return new TooManyRequestsException(errorMessage);
|
|
45
|
+
default:
|
|
46
|
+
return new TropipayJSException(errorMessage, axiosResponse.status, axiosResponse.data.error);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else if (error.request) {
|
|
50
|
+
// Axios request was made but no response received (e.g., network error)
|
|
51
|
+
return new TropipayJSException("Request failed: No response received", 500, null);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
// Something else went wrong
|
|
55
|
+
return new TropipayJSException("An error occurred", 500, null);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return new TropipayJSException(`jsbfvbsfvbf`, 500, null);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
class TropipayJSException extends Error {
|
|
63
|
+
code; // Status code
|
|
64
|
+
error;
|
|
65
|
+
message;
|
|
66
|
+
constructor(message, code, data) {
|
|
67
|
+
super(message);
|
|
68
|
+
// Set the prototype explicitly.
|
|
69
|
+
Object.setPrototypeOf(this, TropipayJSException.prototype);
|
|
70
|
+
this.code = code;
|
|
71
|
+
this.error = data;
|
|
72
|
+
this.message = message;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
31
76
|
class TropipayHooks {
|
|
32
77
|
tropipay;
|
|
33
78
|
// ... hook-related functionality ...
|
|
@@ -69,7 +114,7 @@ class TropipayHooks {
|
|
|
69
114
|
return hooks.data;
|
|
70
115
|
}
|
|
71
116
|
catch (error) {
|
|
72
|
-
throw
|
|
117
|
+
throw handleExceptions(error);
|
|
73
118
|
}
|
|
74
119
|
}
|
|
75
120
|
/**
|
|
@@ -94,7 +139,7 @@ class TropipayHooks {
|
|
|
94
139
|
return hooks.data;
|
|
95
140
|
}
|
|
96
141
|
catch (error) {
|
|
97
|
-
throw
|
|
142
|
+
throw handleExceptions(error);
|
|
98
143
|
}
|
|
99
144
|
}
|
|
100
145
|
async update(eventType, target, value) {
|
|
@@ -116,7 +161,7 @@ class TropipayHooks {
|
|
|
116
161
|
return hooks.data;
|
|
117
162
|
}
|
|
118
163
|
catch (error) {
|
|
119
|
-
throw
|
|
164
|
+
throw handleExceptions(error);
|
|
120
165
|
}
|
|
121
166
|
}
|
|
122
167
|
async delete(eventType, target) {
|
|
@@ -135,7 +180,7 @@ class TropipayHooks {
|
|
|
135
180
|
}
|
|
136
181
|
catch (error) {
|
|
137
182
|
console.trace(error);
|
|
138
|
-
throw
|
|
183
|
+
throw handleExceptions(error);
|
|
139
184
|
}
|
|
140
185
|
}
|
|
141
186
|
async events() {
|
|
@@ -153,7 +198,7 @@ class TropipayHooks {
|
|
|
153
198
|
return hooks.data;
|
|
154
199
|
}
|
|
155
200
|
catch (error) {
|
|
156
|
-
throw
|
|
201
|
+
throw handleExceptions(error);
|
|
157
202
|
}
|
|
158
203
|
}
|
|
159
204
|
}
|
|
@@ -184,7 +229,7 @@ class PaymentCard {
|
|
|
184
229
|
return paylink.data;
|
|
185
230
|
}
|
|
186
231
|
catch (error) {
|
|
187
|
-
throw
|
|
232
|
+
throw handleExceptions(error);
|
|
188
233
|
}
|
|
189
234
|
}
|
|
190
235
|
/**
|
|
@@ -225,7 +270,7 @@ class PaymentCard {
|
|
|
225
270
|
return paymentcard.data;
|
|
226
271
|
}
|
|
227
272
|
catch (error) {
|
|
228
|
-
throw
|
|
273
|
+
throw handleExceptions(error);
|
|
229
274
|
}
|
|
230
275
|
}
|
|
231
276
|
}
|
|
@@ -254,7 +299,7 @@ class DepositAccounts {
|
|
|
254
299
|
return deposit.data;
|
|
255
300
|
}
|
|
256
301
|
catch (error) {
|
|
257
|
-
|
|
302
|
+
return handleExceptions(error);
|
|
258
303
|
}
|
|
259
304
|
}
|
|
260
305
|
/**
|
|
@@ -277,7 +322,7 @@ class DepositAccounts {
|
|
|
277
322
|
return deposit.data;
|
|
278
323
|
}
|
|
279
324
|
catch (error) {
|
|
280
|
-
|
|
325
|
+
return handleExceptions(error);
|
|
281
326
|
}
|
|
282
327
|
}
|
|
283
328
|
/**
|
|
@@ -301,7 +346,7 @@ class DepositAccounts {
|
|
|
301
346
|
return deposit.data;
|
|
302
347
|
}
|
|
303
348
|
catch (error) {
|
|
304
|
-
|
|
349
|
+
return handleExceptions(error);
|
|
305
350
|
}
|
|
306
351
|
}
|
|
307
352
|
/**
|
|
@@ -324,7 +369,7 @@ class DepositAccounts {
|
|
|
324
369
|
return deposit.data;
|
|
325
370
|
}
|
|
326
371
|
catch (error) {
|
|
327
|
-
|
|
372
|
+
return handleExceptions(error);
|
|
328
373
|
}
|
|
329
374
|
}
|
|
330
375
|
/**
|
|
@@ -347,7 +392,7 @@ class DepositAccounts {
|
|
|
347
392
|
return deposit.data;
|
|
348
393
|
}
|
|
349
394
|
catch (error) {
|
|
350
|
-
|
|
395
|
+
return handleExceptions(error);
|
|
351
396
|
}
|
|
352
397
|
}
|
|
353
398
|
}
|
|
@@ -404,10 +449,7 @@ class Tropipay {
|
|
|
404
449
|
return data;
|
|
405
450
|
}
|
|
406
451
|
catch (error) {
|
|
407
|
-
|
|
408
|
-
throw new Error(`Could not obtain the access token from credentials ${error}`);
|
|
409
|
-
}
|
|
410
|
-
throw new Error(`Could not obtain the access token from credentials ${error}`);
|
|
452
|
+
throw handleExceptions(error);
|
|
411
453
|
}
|
|
412
454
|
}
|
|
413
455
|
/**
|
|
@@ -430,7 +472,7 @@ class Tropipay {
|
|
|
430
472
|
return deposits.data;
|
|
431
473
|
}
|
|
432
474
|
catch (error) {
|
|
433
|
-
throw
|
|
475
|
+
throw handleExceptions(error);
|
|
434
476
|
}
|
|
435
477
|
}
|
|
436
478
|
/**
|
|
@@ -444,7 +486,7 @@ class Tropipay {
|
|
|
444
486
|
return countries.data;
|
|
445
487
|
}
|
|
446
488
|
catch (error) {
|
|
447
|
-
throw
|
|
489
|
+
throw handleExceptions(error);
|
|
448
490
|
}
|
|
449
491
|
}
|
|
450
492
|
/**
|
|
@@ -466,7 +508,7 @@ class Tropipay {
|
|
|
466
508
|
return balance.data;
|
|
467
509
|
}
|
|
468
510
|
catch (error) {
|
|
469
|
-
throw
|
|
511
|
+
throw handleExceptions(error);
|
|
470
512
|
}
|
|
471
513
|
}
|
|
472
514
|
/**
|
|
@@ -505,7 +547,7 @@ class Tropipay {
|
|
|
505
547
|
return favoritesList?.data?.rows;
|
|
506
548
|
}
|
|
507
549
|
catch (error) {
|
|
508
|
-
throw
|
|
550
|
+
throw handleExceptions(error);
|
|
509
551
|
}
|
|
510
552
|
}
|
|
511
553
|
/**
|
|
@@ -528,7 +570,7 @@ class Tropipay {
|
|
|
528
570
|
return movements.data;
|
|
529
571
|
}
|
|
530
572
|
catch (error) {
|
|
531
|
-
throw
|
|
573
|
+
throw handleExceptions(error);
|
|
532
574
|
}
|
|
533
575
|
}
|
|
534
576
|
/**
|
|
@@ -543,7 +585,7 @@ class Tropipay {
|
|
|
543
585
|
return profile.data;
|
|
544
586
|
}
|
|
545
587
|
catch (error) {
|
|
546
|
-
throw
|
|
588
|
+
throw handleExceptions(error);
|
|
547
589
|
}
|
|
548
590
|
}
|
|
549
591
|
/**
|
|
@@ -572,7 +614,7 @@ class Tropipay {
|
|
|
572
614
|
return rates.data.rate;
|
|
573
615
|
}
|
|
574
616
|
catch (error) {
|
|
575
|
-
throw
|
|
617
|
+
throw handleExceptions(error);
|
|
576
618
|
}
|
|
577
619
|
}
|
|
578
620
|
/**
|
|
@@ -598,12 +640,14 @@ class Tropipay {
|
|
|
598
640
|
return mediation.data;
|
|
599
641
|
}
|
|
600
642
|
catch (error) {
|
|
601
|
-
throw
|
|
643
|
+
throw handleExceptions(error);
|
|
602
644
|
}
|
|
603
645
|
}
|
|
604
646
|
}
|
|
605
647
|
class ClientSideUtils {
|
|
606
|
-
constructor(tropipayInstance) {
|
|
648
|
+
constructor(tropipayInstance) {
|
|
649
|
+
throw Error(`Not implemented yet`);
|
|
650
|
+
}
|
|
607
651
|
}
|
|
608
652
|
|
|
609
653
|
class ServerSideUtils {
|
|
@@ -624,10 +668,7 @@ class ServerSideUtils {
|
|
|
624
668
|
.createHash("sha256")
|
|
625
669
|
.update(bankOrderCode +
|
|
626
670
|
credentials.clientId +
|
|
627
|
-
|
|
628
|
-
.createHash("sha1")
|
|
629
|
-
.update(credentials.clientSecret)
|
|
630
|
-
.digest("hex") +
|
|
671
|
+
credentials.clientSecret +
|
|
631
672
|
originalCurrencyAmount)
|
|
632
673
|
.digest("hex");
|
|
633
674
|
return localSignature === signature;
|
|
@@ -6,7 +6,7 @@ export interface DepositAccountConfig {
|
|
|
6
6
|
searchBy?: number;
|
|
7
7
|
accountNumber?: string;
|
|
8
8
|
swift?: string;
|
|
9
|
-
type
|
|
9
|
+
type: DepositAccountType;
|
|
10
10
|
firstName?: string;
|
|
11
11
|
lastName?: string;
|
|
12
12
|
secondLastName?: string;
|
|
@@ -24,4 +24,45 @@ export interface DepositAccountConfig {
|
|
|
24
24
|
type INTERNAL = 1;
|
|
25
25
|
type EXTERNAL = 2;
|
|
26
26
|
export type BeneficiaryType = INTERNAL | EXTERNAL;
|
|
27
|
+
export declare const DepositAccountTypesList: {
|
|
28
|
+
/**
|
|
29
|
+
* Banco Metropolitano (Cuba) Bank Account
|
|
30
|
+
*/
|
|
31
|
+
readonly BANMET_BANK_ACCOUNT: 0;
|
|
32
|
+
/**
|
|
33
|
+
* Banco Popular de Ahorro
|
|
34
|
+
*/
|
|
35
|
+
readonly BPA_BANK_ACCOUNT: 1;
|
|
36
|
+
/**
|
|
37
|
+
* Banco de Credito y Comercio (Cuba) Bank Account
|
|
38
|
+
*/
|
|
39
|
+
readonly BANDEC_BANK_ACCOUNT: 2;
|
|
40
|
+
/**
|
|
41
|
+
* Banco Metropilitano (Cuba) card
|
|
42
|
+
*/
|
|
43
|
+
readonly BANMET_CARD: 3;
|
|
44
|
+
/**
|
|
45
|
+
* Banco Popular de Ahorro (Cuba) card
|
|
46
|
+
*/
|
|
47
|
+
readonly BPA_CARD: 4;
|
|
48
|
+
/**
|
|
49
|
+
* Not available anymore
|
|
50
|
+
* @deprecated
|
|
51
|
+
*/
|
|
52
|
+
readonly AIS_CUC_CARD: 5;
|
|
53
|
+
/**
|
|
54
|
+
* Not available
|
|
55
|
+
* @deprecated
|
|
56
|
+
*/
|
|
57
|
+
readonly AIS_USD_CARD: 6;
|
|
58
|
+
/**
|
|
59
|
+
* For international bank accounts
|
|
60
|
+
*/
|
|
61
|
+
readonly OTHER: 7;
|
|
62
|
+
/**
|
|
63
|
+
* Banco de Credito y comercio card
|
|
64
|
+
*/
|
|
65
|
+
readonly BANDEC_CARD: 8;
|
|
66
|
+
};
|
|
67
|
+
export type DepositAccountType = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11;
|
|
27
68
|
export {};
|
package/package.json
CHANGED
package/src/api/TropipayAPI.ts
CHANGED
|
@@ -20,6 +20,7 @@ type ServerMode = "Development" | "Production";
|
|
|
20
20
|
import { TropipayHooks } from "../hooks/TropipayHooks";
|
|
21
21
|
import { PaymentCard } from "../paymentcard/PaymentCard";
|
|
22
22
|
import { DepositAccounts } from "../depositAccount/depositAccounts";
|
|
23
|
+
import { handleExceptions } from "../utils/errors";
|
|
23
24
|
export class Tropipay {
|
|
24
25
|
readonly clientId: string;
|
|
25
26
|
readonly clientSecret: string;
|
|
@@ -74,14 +75,7 @@ export class Tropipay {
|
|
|
74
75
|
Tropipay.refreshToken = data.refresh_token;
|
|
75
76
|
return data;
|
|
76
77
|
} catch (error) {
|
|
77
|
-
|
|
78
|
-
throw new Error(
|
|
79
|
-
`Could not obtain the access token from credentials ${error}`
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
throw new Error(
|
|
83
|
-
`Could not obtain the access token from credentials ${error}`
|
|
84
|
-
);
|
|
78
|
+
throw handleExceptions(error as any);
|
|
85
79
|
}
|
|
86
80
|
}
|
|
87
81
|
|
|
@@ -104,7 +98,7 @@ export class Tropipay {
|
|
|
104
98
|
});
|
|
105
99
|
return deposits.data;
|
|
106
100
|
} catch (error) {
|
|
107
|
-
throw
|
|
101
|
+
throw handleExceptions(error as any);
|
|
108
102
|
}
|
|
109
103
|
}
|
|
110
104
|
|
|
@@ -118,7 +112,7 @@ export class Tropipay {
|
|
|
118
112
|
const countries = await this.request.get("/api/v2/countries");
|
|
119
113
|
return countries.data;
|
|
120
114
|
} catch (error) {
|
|
121
|
-
throw
|
|
115
|
+
throw handleExceptions(error as any);
|
|
122
116
|
}
|
|
123
117
|
}
|
|
124
118
|
/**
|
|
@@ -139,9 +133,7 @@ export class Tropipay {
|
|
|
139
133
|
});
|
|
140
134
|
return balance.data;
|
|
141
135
|
} catch (error) {
|
|
142
|
-
throw
|
|
143
|
-
`TropipayJS Error - Could not retrieve the user's balance`
|
|
144
|
-
);
|
|
136
|
+
throw handleExceptions(error as any);
|
|
145
137
|
}
|
|
146
138
|
}
|
|
147
139
|
|
|
@@ -185,7 +177,7 @@ export class Tropipay {
|
|
|
185
177
|
);
|
|
186
178
|
return favoritesList?.data?.rows;
|
|
187
179
|
} catch (error) {
|
|
188
|
-
throw
|
|
180
|
+
throw handleExceptions(error as any);
|
|
189
181
|
}
|
|
190
182
|
}
|
|
191
183
|
|
|
@@ -208,7 +200,7 @@ export class Tropipay {
|
|
|
208
200
|
});
|
|
209
201
|
return movements.data;
|
|
210
202
|
} catch (error) {
|
|
211
|
-
throw
|
|
203
|
+
throw handleExceptions(error as any);
|
|
212
204
|
}
|
|
213
205
|
}
|
|
214
206
|
|
|
@@ -222,7 +214,7 @@ export class Tropipay {
|
|
|
222
214
|
const profile = await this.request.get("/api/users/profile");
|
|
223
215
|
return profile.data;
|
|
224
216
|
} catch (error) {
|
|
225
|
-
throw
|
|
217
|
+
throw handleExceptions(error as any);
|
|
226
218
|
}
|
|
227
219
|
}
|
|
228
220
|
|
|
@@ -258,7 +250,7 @@ export class Tropipay {
|
|
|
258
250
|
);
|
|
259
251
|
return rates.data.rate;
|
|
260
252
|
} catch (error) {
|
|
261
|
-
throw
|
|
253
|
+
throw handleExceptions(error as any);
|
|
262
254
|
}
|
|
263
255
|
}
|
|
264
256
|
|
|
@@ -289,11 +281,13 @@ export class Tropipay {
|
|
|
289
281
|
);
|
|
290
282
|
return mediation.data as PaymentLink;
|
|
291
283
|
} catch (error) {
|
|
292
|
-
throw
|
|
284
|
+
throw handleExceptions(error as any);
|
|
293
285
|
}
|
|
294
286
|
}
|
|
295
287
|
}
|
|
296
288
|
|
|
297
289
|
export class ClientSideUtils {
|
|
298
|
-
constructor(tropipayInstance: Tropipay) {
|
|
290
|
+
constructor(tropipayInstance: Tropipay) {
|
|
291
|
+
throw Error(`Not implemented yet`);
|
|
292
|
+
}
|
|
299
293
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { AxiosError } from "axios";
|
|
1
2
|
import { Tropipay } from "../api/TropipayAPI";
|
|
2
3
|
import { DepositAccountConfig } from "../interfaces/depositaccounts";
|
|
3
|
-
|
|
4
|
+
import { handleExceptions } from "../utils/errors";
|
|
4
5
|
export class DepositAccounts {
|
|
5
6
|
private tropipay: Tropipay;
|
|
6
7
|
constructor(tropipayInstance: Tropipay) {
|
|
@@ -28,7 +29,7 @@ export class DepositAccounts {
|
|
|
28
29
|
);
|
|
29
30
|
return deposit.data;
|
|
30
31
|
} catch (error) {
|
|
31
|
-
|
|
32
|
+
return handleExceptions(error as unknown as any);
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
/**
|
|
@@ -54,7 +55,7 @@ export class DepositAccounts {
|
|
|
54
55
|
);
|
|
55
56
|
return deposit.data;
|
|
56
57
|
} catch (error) {
|
|
57
|
-
|
|
58
|
+
return handleExceptions(error as unknown as any);
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
/**
|
|
@@ -80,7 +81,7 @@ export class DepositAccounts {
|
|
|
80
81
|
);
|
|
81
82
|
return deposit.data;
|
|
82
83
|
} catch (error) {
|
|
83
|
-
|
|
84
|
+
return handleExceptions(error as unknown as any);
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
87
|
|
|
@@ -106,7 +107,7 @@ export class DepositAccounts {
|
|
|
106
107
|
);
|
|
107
108
|
return deposit.data;
|
|
108
109
|
} catch (error) {
|
|
109
|
-
|
|
110
|
+
return handleExceptions(error as unknown as any);
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
113
|
|
|
@@ -132,7 +133,7 @@ export class DepositAccounts {
|
|
|
132
133
|
);
|
|
133
134
|
return deposit.data;
|
|
134
135
|
} catch (error) {
|
|
135
|
-
|
|
136
|
+
return handleExceptions(error as unknown as any);
|
|
136
137
|
}
|
|
137
138
|
}
|
|
138
139
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { HookEventType, UserHookSubscribed } from "../interfaces";
|
|
2
2
|
import { Tropipay } from "../api/TropipayAPI";
|
|
3
|
+
import { handleExceptions } from "../utils/errors";
|
|
3
4
|
export class TropipayHooks {
|
|
4
5
|
private tropipay: Tropipay;
|
|
5
6
|
// ... hook-related functionality ...
|
|
@@ -52,7 +53,7 @@ export class TropipayHooks {
|
|
|
52
53
|
);
|
|
53
54
|
return hooks.data;
|
|
54
55
|
} catch (error) {
|
|
55
|
-
throw
|
|
56
|
+
throw handleExceptions(error as unknown as any);
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
/**
|
|
@@ -79,7 +80,7 @@ export class TropipayHooks {
|
|
|
79
80
|
);
|
|
80
81
|
return hooks.data;
|
|
81
82
|
} catch (error) {
|
|
82
|
-
throw
|
|
83
|
+
throw handleExceptions(error as unknown as any);
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
public async update(
|
|
@@ -108,7 +109,7 @@ export class TropipayHooks {
|
|
|
108
109
|
);
|
|
109
110
|
return hooks.data;
|
|
110
111
|
} catch (error) {
|
|
111
|
-
throw
|
|
112
|
+
throw handleExceptions(error as unknown as any);
|
|
112
113
|
}
|
|
113
114
|
}
|
|
114
115
|
async delete(eventType: HookEventType, target: string) {
|
|
@@ -129,7 +130,7 @@ export class TropipayHooks {
|
|
|
129
130
|
return hooks.data;
|
|
130
131
|
} catch (error) {
|
|
131
132
|
console.trace(error);
|
|
132
|
-
throw
|
|
133
|
+
throw handleExceptions(error as unknown as any);
|
|
133
134
|
}
|
|
134
135
|
}
|
|
135
136
|
|
|
@@ -147,7 +148,7 @@ export class TropipayHooks {
|
|
|
147
148
|
});
|
|
148
149
|
return hooks.data;
|
|
149
150
|
} catch (error) {
|
|
150
|
-
throw
|
|
151
|
+
throw handleExceptions(error as unknown as any);
|
|
151
152
|
}
|
|
152
153
|
}
|
|
153
154
|
}
|
|
@@ -6,7 +6,7 @@ export interface DepositAccountConfig {
|
|
|
6
6
|
searchBy?: number;
|
|
7
7
|
accountNumber?: string;
|
|
8
8
|
swift?: string;
|
|
9
|
-
type
|
|
9
|
+
type: DepositAccountType;
|
|
10
10
|
firstName?: string;
|
|
11
11
|
lastName?: string;
|
|
12
12
|
secondLastName?: string;
|
|
@@ -25,3 +25,46 @@ type INTERNAL = 1;
|
|
|
25
25
|
type EXTERNAL = 2;
|
|
26
26
|
|
|
27
27
|
export type BeneficiaryType = INTERNAL | EXTERNAL;
|
|
28
|
+
|
|
29
|
+
export const DepositAccountTypesList = {
|
|
30
|
+
/**
|
|
31
|
+
* Banco Metropolitano (Cuba) Bank Account
|
|
32
|
+
*/
|
|
33
|
+
BANMET_BANK_ACCOUNT: 0,
|
|
34
|
+
/**
|
|
35
|
+
* Banco Popular de Ahorro
|
|
36
|
+
*/
|
|
37
|
+
BPA_BANK_ACCOUNT: 1,
|
|
38
|
+
/**
|
|
39
|
+
* Banco de Credito y Comercio (Cuba) Bank Account
|
|
40
|
+
*/
|
|
41
|
+
BANDEC_BANK_ACCOUNT: 2,
|
|
42
|
+
/**
|
|
43
|
+
* Banco Metropilitano (Cuba) card
|
|
44
|
+
*/
|
|
45
|
+
BANMET_CARD: 3,
|
|
46
|
+
/**
|
|
47
|
+
* Banco Popular de Ahorro (Cuba) card
|
|
48
|
+
*/
|
|
49
|
+
BPA_CARD: 4,
|
|
50
|
+
/**
|
|
51
|
+
* Not available anymore
|
|
52
|
+
* @deprecated
|
|
53
|
+
*/
|
|
54
|
+
AIS_CUC_CARD: 5,
|
|
55
|
+
/**
|
|
56
|
+
* Not available
|
|
57
|
+
* @deprecated
|
|
58
|
+
*/
|
|
59
|
+
AIS_USD_CARD: 6,
|
|
60
|
+
/**
|
|
61
|
+
* For international bank accounts
|
|
62
|
+
*/
|
|
63
|
+
OTHER: 7,
|
|
64
|
+
/**
|
|
65
|
+
* Banco de Credito y comercio card
|
|
66
|
+
*/
|
|
67
|
+
BANDEC_CARD: 8,
|
|
68
|
+
} as const;
|
|
69
|
+
|
|
70
|
+
export type DepositAccountType = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Tropipay } from "../api/TropipayAPI";
|
|
2
2
|
import { PaymentLink } from "../interfaces";
|
|
3
3
|
import { PaymentLinkPayload } from "../interfaces";
|
|
4
|
+
import { handleExceptions } from "../utils/errors";
|
|
4
5
|
export class PaymentCard {
|
|
5
6
|
private tropipay: Tropipay;
|
|
6
7
|
constructor(tropipayInstance: Tropipay) {
|
|
@@ -31,7 +32,7 @@ export class PaymentCard {
|
|
|
31
32
|
);
|
|
32
33
|
return paylink.data as PaymentLink;
|
|
33
34
|
} catch (error) {
|
|
34
|
-
throw
|
|
35
|
+
throw handleExceptions(error as unknown as any);
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
@@ -77,7 +78,7 @@ export class PaymentCard {
|
|
|
77
78
|
);
|
|
78
79
|
return paymentcard.data;
|
|
79
80
|
} catch (error) {
|
|
80
|
-
throw
|
|
81
|
+
throw handleExceptions(error as unknown as any);
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as crypto from "crypto";
|
|
2
2
|
import { Tropipay } from "../api/TropipayAPI";
|
|
3
|
+
import { AxiosError, AxiosResponse } from "axios";
|
|
4
|
+
|
|
3
5
|
export class ServerSideUtils {
|
|
4
6
|
private tropipay: Tropipay;
|
|
5
7
|
constructor(tropipayInstance: Tropipay) {
|
|
@@ -30,10 +32,7 @@ export class ServerSideUtils {
|
|
|
30
32
|
.update(
|
|
31
33
|
bankOrderCode +
|
|
32
34
|
credentials.clientId +
|
|
33
|
-
|
|
34
|
-
.createHash("sha1")
|
|
35
|
-
.update(credentials.clientSecret)
|
|
36
|
-
.digest("hex") +
|
|
35
|
+
credentials.clientSecret +
|
|
37
36
|
originalCurrencyAmount
|
|
38
37
|
)
|
|
39
38
|
.digest("hex");
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { AxiosError, AxiosResponse } from "axios";
|
|
2
|
+
|
|
3
|
+
const ErrorType = {
|
|
4
|
+
VALIDATION_ERROR: "VALIDATION_ERROR", // 400
|
|
5
|
+
UNAUTHORIZED_ERROR: "UNAUTHORIZED_ERROR", // 401 (Not valid credentials)
|
|
6
|
+
FORBIDDEN_ERROR: "FORBIDDEN_ERROR", // 403 (Valid credentials but insufficient to grant access)
|
|
7
|
+
NOT_FOUND: "NOT_FOUND", // 404
|
|
8
|
+
RATE_LIMIT_ERROR: "RATE_LIMIT_ERROR", // 429 (Used only in cloudflare for now)
|
|
9
|
+
OPERATION_ERROR: "OPERATION_ERROR", // 500
|
|
10
|
+
} as const;
|
|
11
|
+
|
|
12
|
+
const ErrorCode = {
|
|
13
|
+
VALIDATION_ERROR: "VALIDATION_ERROR",
|
|
14
|
+
UNAUTHORIZED_ERROR: "UNAUTHORIZED_ERROR",
|
|
15
|
+
FORBIDDEN_ERROR: "FORBIDDEN_ERROR",
|
|
16
|
+
NOT_FOUND: "NOT_FOUND",
|
|
17
|
+
RATE_LIMIT_ERROR: "RATE_LIMIT_ERROR",
|
|
18
|
+
OPERATION_ERROR: "OPERATION_ERROR",
|
|
19
|
+
SYNTAX_ERROR: "SYNTAX_ERROR",
|
|
20
|
+
INVALID_PARAM: "INVALID_PARAM",
|
|
21
|
+
UNHANDLED_ERROR: "SERVER_ERROR",
|
|
22
|
+
} as const;
|
|
23
|
+
|
|
24
|
+
export interface ErrorDetail {
|
|
25
|
+
param: string;
|
|
26
|
+
value: string | number | null;
|
|
27
|
+
msg: string;
|
|
28
|
+
code: string;
|
|
29
|
+
location: string | null;
|
|
30
|
+
meta: unknown;
|
|
31
|
+
}
|
|
32
|
+
export function handleExceptions(
|
|
33
|
+
error: AxiosError | Error
|
|
34
|
+
): TropipayJSException {
|
|
35
|
+
if (error instanceof AxiosError) {
|
|
36
|
+
if (error.response) {
|
|
37
|
+
const axiosResponse: AxiosResponse = error.response;
|
|
38
|
+
const errorMessage =
|
|
39
|
+
axiosResponse.data?.error?.message || "An error occurred";
|
|
40
|
+
|
|
41
|
+
switch (axiosResponse.status) {
|
|
42
|
+
case 401:
|
|
43
|
+
return new TropipayJSException(
|
|
44
|
+
errorMessage,
|
|
45
|
+
axiosResponse.status,
|
|
46
|
+
axiosResponse.data.error
|
|
47
|
+
);
|
|
48
|
+
case 403:
|
|
49
|
+
return new TropipayJSException(
|
|
50
|
+
errorMessage,
|
|
51
|
+
axiosResponse.status,
|
|
52
|
+
axiosResponse.data.error
|
|
53
|
+
);
|
|
54
|
+
case 404:
|
|
55
|
+
return new TropipayJSException(
|
|
56
|
+
errorMessage,
|
|
57
|
+
axiosResponse.status,
|
|
58
|
+
axiosResponse.data.error
|
|
59
|
+
);
|
|
60
|
+
// case 429:
|
|
61
|
+
// return new TooManyRequestsException(errorMessage);
|
|
62
|
+
default:
|
|
63
|
+
return new TropipayJSException(
|
|
64
|
+
errorMessage,
|
|
65
|
+
axiosResponse.status,
|
|
66
|
+
axiosResponse.data.error
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
} else if (error.request) {
|
|
70
|
+
// Axios request was made but no response received (e.g., network error)
|
|
71
|
+
return new TropipayJSException(
|
|
72
|
+
"Request failed: No response received",
|
|
73
|
+
500,
|
|
74
|
+
null
|
|
75
|
+
);
|
|
76
|
+
} else {
|
|
77
|
+
// Something else went wrong
|
|
78
|
+
return new TropipayJSException("An error occurred", 500, null);
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
return new TropipayJSException(`jsbfvbsfvbf`, 500, null);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
class TropipayJSException extends Error {
|
|
86
|
+
code: number; // Status code
|
|
87
|
+
error: unknown;
|
|
88
|
+
message: string;
|
|
89
|
+
constructor(message: string, code: number, data: unknown) {
|
|
90
|
+
super(message);
|
|
91
|
+
// Set the prototype explicitly.
|
|
92
|
+
Object.setPrototypeOf(this, TropipayJSException.prototype);
|
|
93
|
+
this.code = code;
|
|
94
|
+
this.error = data;
|
|
95
|
+
this.message = message;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AxiosError } from "axios";
|
|
2
|
+
export interface ErrorDetail {
|
|
3
|
+
param: string;
|
|
4
|
+
value: string | number | null;
|
|
5
|
+
msg: string;
|
|
6
|
+
code: string;
|
|
7
|
+
location: string | null;
|
|
8
|
+
meta: unknown;
|
|
9
|
+
}
|
|
10
|
+
export declare function handleExceptions(error: AxiosError | Error): TropipayJSException;
|
|
11
|
+
declare class TropipayJSException extends Error {
|
|
12
|
+
code: number;
|
|
13
|
+
error: unknown;
|
|
14
|
+
message: string;
|
|
15
|
+
constructor(message: string, code: number, data: unknown);
|
|
16
|
+
}
|
|
17
|
+
export {};
|