@yosle/tropipayjs 0.1.14 → 0.1.16
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/README.md +47 -53
- package/api/TropipayAPI.d.ts +3 -1
- package/depositAccount/depositAccounts.d.ts +36 -0
- package/index.d.ts +66 -2
- package/index.js +191 -22
- package/interfaces/depositaccounts/index.d.ts +68 -0
- package/package.json +1 -1
- package/src/api/TropipayAPI.ts +18 -21
- package/src/depositAccount/depositAccounts.ts +139 -0
- package/src/hooks/TropipayHooks.ts +6 -5
- package/src/index.ts +3 -0
- package/src/interfaces/depositaccounts/index.ts +70 -0
- package/src/paymentcard/PaymentCard.ts +3 -3
- package/src/utils/TropipayUtils.ts +3 -0
- package/src/utils/errors.ts +97 -0
- package/utils/errors.d.ts +17 -0
package/README.md
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
TropipayJS - Typescript/Javascript SDK for Tropipay Payments API
|
|
2
|
-
===========
|
|
1
|
+
# TropipayJS - Typescript/Javascript SDK for Tropipay Payments API
|
|
3
2
|
|
|
4
3
|

|
|
5
|
-

|
|
4
|
+

|
|
6
5
|

|
|
7
6
|

|
|
8
7
|

|
|
9
8
|
|
|
10
9
|
TropiPay is an electronic wallet that allows you to execute the most common financial operations of the day to day. This is SDK for Typescript and Javacript that helps you build integrations with the Tropipay platform in an easier way. Can save you a lot of time and effort implementing all the API features. You can use this library with CommonJS system (node + express) or ES6 module system (NextJS).
|
|
11
10
|
|
|
12
|
-
|
|
13
11
|
# Table of Contents
|
|
14
12
|
|
|
15
13
|
- [TropipayJS - Typescript/Javascript SDK for Tropipay Payments API](#tropipayjs---typescriptjavascript-sdk-for-tropipay-payments-api)
|
|
@@ -29,7 +27,7 @@ TropiPay is an electronic wallet that allows you to execute the most common fina
|
|
|
29
27
|
|
|
30
28
|
This library is a community effort. Tropipay may make some changes on the API specification. Use the [test environment](https://tropipay-dev.herokuapp.com) to make sure everything is working as expected.
|
|
31
29
|
|
|
32
|
-
**Note:** This library is provided as-is and serves as a client for the Tropipay API. While every effort has been made to ensure the accuracy and reliability of the library, Tropipay is solely responsible for maintaining and updating the API documentation.
|
|
30
|
+
**Note:** This library is provided as-is and serves as a client for the Tropipay API. While every effort has been made to ensure the accuracy and reliability of the library, Tropipay is solely responsible for maintaining and updating the API documentation.
|
|
33
31
|
|
|
34
32
|
The library is intended to simplify the integration process with Tropipay's services, but it is essential to consult the official documentation to ensure that you are using the API correctly and taking into account any recent changes or updates made by Tropipay.
|
|
35
33
|
|
|
@@ -37,11 +35,11 @@ The library is intended to simplify the integration process with Tropipay's serv
|
|
|
37
35
|
|
|
38
36
|
You can use npm or yarn to install this package:
|
|
39
37
|
|
|
40
|
-
|
|
38
|
+
`npm install @yosle/tropipayjs`
|
|
41
39
|
|
|
42
40
|
or
|
|
43
41
|
|
|
44
|
-
|
|
42
|
+
`yarn add @yosle/tropipayjs`
|
|
45
43
|
|
|
46
44
|
## Setting up your app credentials
|
|
47
45
|
|
|
@@ -52,18 +50,18 @@ In order to use the Tropipay API you'll need a client ID and a client secret. Si
|
|
|
52
50
|
|
|
53
51
|
## Usage
|
|
54
52
|
|
|
55
|
-
The Tropipay instance, allows you to access all the method available in the API. This Object is meant to be used
|
|
53
|
+
The Tropipay instance, allows you to access all the method available in the API. This Object is meant to be used _only in server side_. Do not use the Tropipay object on the client side (browser). This would expose your app credentials (the client secret of your account). You can create an endpoint at your back-end using express and consume it in your front-end, or use SSR if you're using NextJS.
|
|
56
54
|
|
|
57
|
-
### CommonJS
|
|
55
|
+
### CommonJS
|
|
58
56
|
|
|
59
57
|
```javascript
|
|
60
|
-
const { Tropipay } = require(
|
|
58
|
+
const { Tropipay } = require("@yosle/tropipayjs");
|
|
61
59
|
```
|
|
62
60
|
|
|
63
|
-
### ES6
|
|
61
|
+
### ES6
|
|
64
62
|
|
|
65
63
|
```javascript
|
|
66
|
-
import { Tropipay } from
|
|
64
|
+
import { Tropipay } from "@yosle/tropipayjs";
|
|
67
65
|
```
|
|
68
66
|
|
|
69
67
|
### Initialize the Tropipay class
|
|
@@ -72,7 +70,7 @@ You can instantiate the Tropipay class passing the client Id ,client secret and
|
|
|
72
70
|
|
|
73
71
|
```javascript
|
|
74
72
|
// test environment server tropipay-dev.herokuapp.com
|
|
75
|
-
const config = {
|
|
73
|
+
const config = {
|
|
76
74
|
clientId: process.env.TROPIPAY_CLIENT_ID,
|
|
77
75
|
clientSecret: process.env.TROPIPAY_CLIENT_SECRET
|
|
78
76
|
serverMode: 'Development' // it will be used as default if omited
|
|
@@ -84,48 +82,48 @@ To use your live credentials (real account) you must explicity set serverMode to
|
|
|
84
82
|
|
|
85
83
|
```javascript
|
|
86
84
|
//real account credentials
|
|
87
|
-
const config = {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
const tpp = new Tropipay(config)
|
|
85
|
+
const config = {
|
|
86
|
+
clientId: process.env.TROPIPAY_CLIENT_ID,
|
|
87
|
+
clientSecret: process.env.TROPIPAY_CLIENT_SECRET,
|
|
88
|
+
serverMode: "Production", //live account
|
|
89
|
+
};
|
|
90
|
+
const tpp = new Tropipay(config);
|
|
93
91
|
```
|
|
94
92
|
|
|
95
93
|
### Generating a Payment Link
|
|
96
94
|
|
|
97
95
|
```javascript
|
|
98
96
|
/*
|
|
99
|
-
* Example Payload
|
|
100
|
-
*/
|
|
97
|
+
* Example Payload
|
|
98
|
+
*/
|
|
101
99
|
const payload = {
|
|
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
|
-
|
|
100
|
+
reference: "my-paylink-1",
|
|
101
|
+
concept: "Bicycle",
|
|
102
|
+
favorite: "true",
|
|
103
|
+
amount: 3000,
|
|
104
|
+
currency: "EUR",
|
|
105
|
+
description: "Two wheels",
|
|
106
|
+
singleUse: "true",
|
|
107
|
+
reasonId: 4,
|
|
108
|
+
expirationDays: 1,
|
|
109
|
+
lang: "es",
|
|
110
|
+
urlSuccess: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
|
|
111
|
+
urlFailed: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
|
|
112
|
+
urlNotification: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
|
|
113
|
+
serviceDate: "2021-08-20",
|
|
114
|
+
client: {
|
|
115
|
+
name: "John",
|
|
116
|
+
lastName: "McClane",
|
|
117
|
+
address: "Ave. Guadí 232, Barcelona, Barcelona",
|
|
118
|
+
phone: "+34645553333",
|
|
119
|
+
email: "client@email.com",
|
|
120
|
+
countryId: 1,
|
|
121
|
+
termsAndConditions: "true",
|
|
122
|
+
},
|
|
123
|
+
directPayment: "true",
|
|
124
|
+
};
|
|
127
125
|
// Use inside an async function
|
|
128
|
-
const paylink = await tpp.
|
|
126
|
+
const paylink = await tpp.paymentCards.create(payload);
|
|
129
127
|
console.log(paylink.shortUrl);
|
|
130
128
|
```
|
|
131
129
|
|
|
@@ -140,15 +138,11 @@ If you have a suggestion that would make this better, please fork the repo and c
|
|
|
140
138
|
3. Commit your Changes (`git commit -m 'Add some AmazingFeature`)
|
|
141
139
|
4. Push to the Branch (`git push origin feature/AmazingFeature`)
|
|
142
140
|
5. Open a Pull Request
|
|
143
|
-
|
|
144
|
-
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
|
141
|
+
|
|
142
|
+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
|
145
143
|
|
|
146
144
|
You can also make a small [donation to the author](https://tppay.me/l94qaa3h) of the library.
|
|
147
145
|
|
|
148
146
|
# License
|
|
149
147
|
|
|
150
148
|
Distributed under the MIT License. See `LICENSE.txt` for more information.
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
package/api/TropipayAPI.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { TropipayConfig, AccountBalance, Country, PaymentLink, mediationPaymentC
|
|
|
9
9
|
type ServerMode = "Development" | "Production";
|
|
10
10
|
import { TropipayHooks } from "../hooks/TropipayHooks";
|
|
11
11
|
import { PaymentCard } from "../paymentcard/PaymentCard";
|
|
12
|
+
import { DepositAccounts } from "../depositAccount/depositAccounts";
|
|
12
13
|
export declare class Tropipay {
|
|
13
14
|
readonly clientId: string;
|
|
14
15
|
readonly clientSecret: string;
|
|
@@ -17,7 +18,8 @@ export declare class Tropipay {
|
|
|
17
18
|
static refreshToken: string | undefined;
|
|
18
19
|
serverMode: ServerMode;
|
|
19
20
|
hooks: TropipayHooks;
|
|
20
|
-
|
|
21
|
+
paymentCards: PaymentCard;
|
|
22
|
+
depositAccounts: DepositAccounts;
|
|
21
23
|
constructor(config: TropipayConfig);
|
|
22
24
|
login(): Promise<LoginResponse>;
|
|
23
25
|
/**
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Tropipay } from "../api/TropipayAPI";
|
|
2
|
+
import { DepositAccountConfig } from "../interfaces/depositaccounts";
|
|
3
|
+
export declare class DepositAccounts {
|
|
4
|
+
private tropipay;
|
|
5
|
+
constructor(tropipayInstance: Tropipay);
|
|
6
|
+
/**
|
|
7
|
+
* List od all beneficiaries of this account
|
|
8
|
+
* @returns Array of DepositAccounts
|
|
9
|
+
*/
|
|
10
|
+
list(): Promise<any>;
|
|
11
|
+
/**
|
|
12
|
+
* Adds a new beneficiary to the user account.
|
|
13
|
+
* @param payload
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
create(depositAccountObj: DepositAccountConfig): Promise<any>;
|
|
17
|
+
/**
|
|
18
|
+
* This returns details of a specific
|
|
19
|
+
* Deposit Account (beneficiary) specified by its ID
|
|
20
|
+
* @param id
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
get(id: string): Promise<any>;
|
|
24
|
+
/**
|
|
25
|
+
* Updates certain beneficiary data.
|
|
26
|
+
* @param depositAccountObj
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
update(depositAccountObj: Partial<DepositAccountConfig>): Promise<any>;
|
|
30
|
+
/**
|
|
31
|
+
* (UNTESTED) Deletes the beneficiary indicated by id
|
|
32
|
+
* @param id
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
delete(id: number): Promise<any>;
|
|
36
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -217,6 +217,69 @@ declare class PaymentCard {
|
|
|
217
217
|
get(id: string): Promise<any>;
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
+
interface DepositAccountConfig {
|
|
221
|
+
searchValue?: string;
|
|
222
|
+
alias: string;
|
|
223
|
+
userRelationTypeId: number;
|
|
224
|
+
beneficiaryType: BeneficiaryType;
|
|
225
|
+
searchBy?: number;
|
|
226
|
+
accountNumber?: string;
|
|
227
|
+
swift?: string;
|
|
228
|
+
type: DepositAccountType;
|
|
229
|
+
firstName?: string;
|
|
230
|
+
lastName?: string;
|
|
231
|
+
secondLastName?: string;
|
|
232
|
+
countryDestinationId?: number;
|
|
233
|
+
city?: string;
|
|
234
|
+
postalCode?: number;
|
|
235
|
+
address?: string;
|
|
236
|
+
documentNumber?: string;
|
|
237
|
+
phone?: string;
|
|
238
|
+
province?: string;
|
|
239
|
+
paymentType?: string;
|
|
240
|
+
documentTypeId?: number;
|
|
241
|
+
documentExpirationDate: string;
|
|
242
|
+
}
|
|
243
|
+
type INTERNAL = 1;
|
|
244
|
+
type EXTERNAL = 2;
|
|
245
|
+
type BeneficiaryType = INTERNAL | EXTERNAL;
|
|
246
|
+
type DepositAccountType = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11;
|
|
247
|
+
|
|
248
|
+
declare class DepositAccounts {
|
|
249
|
+
private tropipay;
|
|
250
|
+
constructor(tropipayInstance: Tropipay);
|
|
251
|
+
/**
|
|
252
|
+
* List od all beneficiaries of this account
|
|
253
|
+
* @returns Array of DepositAccounts
|
|
254
|
+
*/
|
|
255
|
+
list(): Promise<any>;
|
|
256
|
+
/**
|
|
257
|
+
* Adds a new beneficiary to the user account.
|
|
258
|
+
* @param payload
|
|
259
|
+
* @returns
|
|
260
|
+
*/
|
|
261
|
+
create(depositAccountObj: DepositAccountConfig): Promise<any>;
|
|
262
|
+
/**
|
|
263
|
+
* This returns details of a specific
|
|
264
|
+
* Deposit Account (beneficiary) specified by its ID
|
|
265
|
+
* @param id
|
|
266
|
+
* @returns
|
|
267
|
+
*/
|
|
268
|
+
get(id: string): Promise<any>;
|
|
269
|
+
/**
|
|
270
|
+
* Updates certain beneficiary data.
|
|
271
|
+
* @param depositAccountObj
|
|
272
|
+
* @returns
|
|
273
|
+
*/
|
|
274
|
+
update(depositAccountObj: Partial<DepositAccountConfig>): Promise<any>;
|
|
275
|
+
/**
|
|
276
|
+
* (UNTESTED) Deletes the beneficiary indicated by id
|
|
277
|
+
* @param id
|
|
278
|
+
* @returns
|
|
279
|
+
*/
|
|
280
|
+
delete(id: number): Promise<any>;
|
|
281
|
+
}
|
|
282
|
+
|
|
220
283
|
/**
|
|
221
284
|
* Tropipayjs is a Typescript/Javascript library for the Tropipay API.
|
|
222
285
|
*
|
|
@@ -234,7 +297,8 @@ declare class Tropipay {
|
|
|
234
297
|
static refreshToken: string | undefined;
|
|
235
298
|
serverMode: ServerMode;
|
|
236
299
|
hooks: TropipayHooks;
|
|
237
|
-
|
|
300
|
+
paymentCards: PaymentCard;
|
|
301
|
+
depositAccounts: DepositAccounts;
|
|
238
302
|
constructor(config: TropipayConfig);
|
|
239
303
|
login(): Promise<LoginResponse>;
|
|
240
304
|
/**
|
|
@@ -322,4 +386,4 @@ declare class ServerSideUtils {
|
|
|
322
386
|
|
|
323
387
|
declare const SERVER_MODE: ServerMode$1;
|
|
324
388
|
|
|
325
|
-
export { AccountBalance, AccountDeposits, ClientSideUtils, Country, Deposit, HookEventType, HookTargetType, LoginError, LoginResponse, PaymentCard, PaymentLink, PaymentLinkPayload, SERVER_MODE, ServerMode$1 as ServerMode, ServerSideUtils, Tropipay, TropipayConfig, TropipayCredentials, TropipayHooks, UserHook, UserHookSubscribed, mediationPaymentCardConfig };
|
|
389
|
+
export { AccountBalance, AccountDeposits, ClientSideUtils, Country, Deposit, DepositAccounts, HookEventType, HookTargetType, LoginError, LoginResponse, PaymentCard, PaymentLink, PaymentLinkPayload, SERVER_MODE, ServerMode$1 as ServerMode, ServerSideUtils, Tropipay, TropipayConfig, TropipayCredentials, TropipayHooks, UserHook, UserHookSubscribed, mediationPaymentCardConfig };
|
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,129 @@ class PaymentCard {
|
|
|
225
270
|
return paymentcard.data;
|
|
226
271
|
}
|
|
227
272
|
catch (error) {
|
|
228
|
-
throw
|
|
273
|
+
throw handleExceptions(error);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
class DepositAccounts {
|
|
279
|
+
tropipay;
|
|
280
|
+
constructor(tropipayInstance) {
|
|
281
|
+
this.tropipay = tropipayInstance;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* List od all beneficiaries of this account
|
|
285
|
+
* @returns Array of DepositAccounts
|
|
286
|
+
*/
|
|
287
|
+
async list() {
|
|
288
|
+
if (!Tropipay.accessToken) {
|
|
289
|
+
await this.tropipay.login();
|
|
290
|
+
}
|
|
291
|
+
try {
|
|
292
|
+
const deposit = await this.tropipay.request.get(`/api/v2/deposit_accounts`, {
|
|
293
|
+
headers: {
|
|
294
|
+
"Content-Type": "application/json",
|
|
295
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
296
|
+
Accept: "application/json",
|
|
297
|
+
},
|
|
298
|
+
});
|
|
299
|
+
return deposit.data;
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
return handleExceptions(error);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Adds a new beneficiary to the user account.
|
|
307
|
+
* @param payload
|
|
308
|
+
* @returns
|
|
309
|
+
*/
|
|
310
|
+
async create(depositAccountObj) {
|
|
311
|
+
if (!Tropipay.accessToken) {
|
|
312
|
+
await this.tropipay.login();
|
|
313
|
+
}
|
|
314
|
+
try {
|
|
315
|
+
const deposit = await this.tropipay.request.post("/api/v2/deposit_accounts", depositAccountObj, {
|
|
316
|
+
headers: {
|
|
317
|
+
"Content-Type": "application/json",
|
|
318
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
319
|
+
Accept: "application/json",
|
|
320
|
+
},
|
|
321
|
+
});
|
|
322
|
+
return deposit.data;
|
|
323
|
+
}
|
|
324
|
+
catch (error) {
|
|
325
|
+
return handleExceptions(error);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* This returns details of a specific
|
|
330
|
+
* Deposit Account (beneficiary) specified by its ID
|
|
331
|
+
* @param id
|
|
332
|
+
* @returns
|
|
333
|
+
*/
|
|
334
|
+
async get(id) {
|
|
335
|
+
if (!Tropipay.accessToken) {
|
|
336
|
+
await this.tropipay.login();
|
|
337
|
+
}
|
|
338
|
+
try {
|
|
339
|
+
const deposit = await this.tropipay.request.get(`/api/v2/deposit_accounts/${id}`, {
|
|
340
|
+
headers: {
|
|
341
|
+
"Content-Type": "application/json",
|
|
342
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
343
|
+
Accept: "application/json",
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
return deposit.data;
|
|
347
|
+
}
|
|
348
|
+
catch (error) {
|
|
349
|
+
return handleExceptions(error);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Updates certain beneficiary data.
|
|
354
|
+
* @param depositAccountObj
|
|
355
|
+
* @returns
|
|
356
|
+
*/
|
|
357
|
+
async update(depositAccountObj) {
|
|
358
|
+
if (!Tropipay.accessToken) {
|
|
359
|
+
await this.tropipay.login();
|
|
360
|
+
}
|
|
361
|
+
try {
|
|
362
|
+
const deposit = await this.tropipay.request.put(`/api/v2/deposit_accounts/`, {
|
|
363
|
+
headers: {
|
|
364
|
+
"Content-Type": "application/json",
|
|
365
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
366
|
+
Accept: "application/json",
|
|
367
|
+
},
|
|
368
|
+
});
|
|
369
|
+
return deposit.data;
|
|
370
|
+
}
|
|
371
|
+
catch (error) {
|
|
372
|
+
return handleExceptions(error);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* (UNTESTED) Deletes the beneficiary indicated by id
|
|
377
|
+
* @param id
|
|
378
|
+
* @returns
|
|
379
|
+
*/
|
|
380
|
+
async delete(id) {
|
|
381
|
+
if (!Tropipay.accessToken) {
|
|
382
|
+
await this.tropipay.login();
|
|
383
|
+
}
|
|
384
|
+
try {
|
|
385
|
+
const deposit = await this.tropipay.request.delete(`/api/v2/deposit_accounts/${id}`, {
|
|
386
|
+
headers: {
|
|
387
|
+
"Content-Type": "application/json",
|
|
388
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
389
|
+
Accept: "application/json",
|
|
390
|
+
},
|
|
391
|
+
});
|
|
392
|
+
return deposit.data;
|
|
393
|
+
}
|
|
394
|
+
catch (error) {
|
|
395
|
+
return handleExceptions(error);
|
|
229
396
|
}
|
|
230
397
|
}
|
|
231
398
|
}
|
|
@@ -244,7 +411,8 @@ class Tropipay {
|
|
|
244
411
|
static refreshToken;
|
|
245
412
|
serverMode;
|
|
246
413
|
hooks;
|
|
247
|
-
|
|
414
|
+
paymentCards;
|
|
415
|
+
depositAccounts;
|
|
248
416
|
constructor(config) {
|
|
249
417
|
this.clientId = config.clientId;
|
|
250
418
|
this.clientSecret = config.clientSecret;
|
|
@@ -260,7 +428,8 @@ class Tropipay {
|
|
|
260
428
|
},
|
|
261
429
|
});
|
|
262
430
|
this.hooks = new TropipayHooks(this);
|
|
263
|
-
this.
|
|
431
|
+
this.paymentCards = new PaymentCard(this);
|
|
432
|
+
this.depositAccounts = new DepositAccounts(this);
|
|
264
433
|
}
|
|
265
434
|
async login() {
|
|
266
435
|
try {
|
|
@@ -280,10 +449,7 @@ class Tropipay {
|
|
|
280
449
|
return data;
|
|
281
450
|
}
|
|
282
451
|
catch (error) {
|
|
283
|
-
|
|
284
|
-
throw new Error(`Could not obtain the access token from credentials ${error}`);
|
|
285
|
-
}
|
|
286
|
-
throw new Error(`Could not obtain the access token from credentials ${error}`);
|
|
452
|
+
throw handleExceptions(error);
|
|
287
453
|
}
|
|
288
454
|
}
|
|
289
455
|
/**
|
|
@@ -306,7 +472,7 @@ class Tropipay {
|
|
|
306
472
|
return deposits.data;
|
|
307
473
|
}
|
|
308
474
|
catch (error) {
|
|
309
|
-
throw
|
|
475
|
+
throw handleExceptions(error);
|
|
310
476
|
}
|
|
311
477
|
}
|
|
312
478
|
/**
|
|
@@ -320,7 +486,7 @@ class Tropipay {
|
|
|
320
486
|
return countries.data;
|
|
321
487
|
}
|
|
322
488
|
catch (error) {
|
|
323
|
-
throw
|
|
489
|
+
throw handleExceptions(error);
|
|
324
490
|
}
|
|
325
491
|
}
|
|
326
492
|
/**
|
|
@@ -342,7 +508,7 @@ class Tropipay {
|
|
|
342
508
|
return balance.data;
|
|
343
509
|
}
|
|
344
510
|
catch (error) {
|
|
345
|
-
throw
|
|
511
|
+
throw handleExceptions(error);
|
|
346
512
|
}
|
|
347
513
|
}
|
|
348
514
|
/**
|
|
@@ -381,7 +547,7 @@ class Tropipay {
|
|
|
381
547
|
return favoritesList?.data?.rows;
|
|
382
548
|
}
|
|
383
549
|
catch (error) {
|
|
384
|
-
throw
|
|
550
|
+
throw handleExceptions(error);
|
|
385
551
|
}
|
|
386
552
|
}
|
|
387
553
|
/**
|
|
@@ -404,7 +570,7 @@ class Tropipay {
|
|
|
404
570
|
return movements.data;
|
|
405
571
|
}
|
|
406
572
|
catch (error) {
|
|
407
|
-
throw
|
|
573
|
+
throw handleExceptions(error);
|
|
408
574
|
}
|
|
409
575
|
}
|
|
410
576
|
/**
|
|
@@ -419,7 +585,7 @@ class Tropipay {
|
|
|
419
585
|
return profile.data;
|
|
420
586
|
}
|
|
421
587
|
catch (error) {
|
|
422
|
-
throw
|
|
588
|
+
throw handleExceptions(error);
|
|
423
589
|
}
|
|
424
590
|
}
|
|
425
591
|
/**
|
|
@@ -448,7 +614,7 @@ class Tropipay {
|
|
|
448
614
|
return rates.data.rate;
|
|
449
615
|
}
|
|
450
616
|
catch (error) {
|
|
451
|
-
throw
|
|
617
|
+
throw handleExceptions(error);
|
|
452
618
|
}
|
|
453
619
|
}
|
|
454
620
|
/**
|
|
@@ -474,12 +640,14 @@ class Tropipay {
|
|
|
474
640
|
return mediation.data;
|
|
475
641
|
}
|
|
476
642
|
catch (error) {
|
|
477
|
-
throw
|
|
643
|
+
throw handleExceptions(error);
|
|
478
644
|
}
|
|
479
645
|
}
|
|
480
646
|
}
|
|
481
647
|
class ClientSideUtils {
|
|
482
|
-
constructor(tropipayInstance) {
|
|
648
|
+
constructor(tropipayInstance) {
|
|
649
|
+
throw Error(`Not implemented yet`);
|
|
650
|
+
}
|
|
483
651
|
}
|
|
484
652
|
|
|
485
653
|
class ServerSideUtils {
|
|
@@ -528,6 +696,7 @@ if (typeof window !== "undefined") {
|
|
|
528
696
|
}
|
|
529
697
|
|
|
530
698
|
exports.ClientSideUtils = ClientSideUtils;
|
|
699
|
+
exports.DepositAccounts = DepositAccounts;
|
|
531
700
|
exports.PaymentCard = PaymentCard;
|
|
532
701
|
exports.SERVER_MODE = SERVER_MODE;
|
|
533
702
|
exports.ServerSideUtils = ServerSideUtils;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export interface DepositAccountConfig {
|
|
2
|
+
searchValue?: string;
|
|
3
|
+
alias: string;
|
|
4
|
+
userRelationTypeId: number;
|
|
5
|
+
beneficiaryType: BeneficiaryType;
|
|
6
|
+
searchBy?: number;
|
|
7
|
+
accountNumber?: string;
|
|
8
|
+
swift?: string;
|
|
9
|
+
type: DepositAccountType;
|
|
10
|
+
firstName?: string;
|
|
11
|
+
lastName?: string;
|
|
12
|
+
secondLastName?: string;
|
|
13
|
+
countryDestinationId?: number;
|
|
14
|
+
city?: string;
|
|
15
|
+
postalCode?: number;
|
|
16
|
+
address?: string;
|
|
17
|
+
documentNumber?: string;
|
|
18
|
+
phone?: string;
|
|
19
|
+
province?: string;
|
|
20
|
+
paymentType?: string;
|
|
21
|
+
documentTypeId?: number;
|
|
22
|
+
documentExpirationDate: string;
|
|
23
|
+
}
|
|
24
|
+
type INTERNAL = 1;
|
|
25
|
+
type EXTERNAL = 2;
|
|
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;
|
|
68
|
+
export {};
|
package/package.json
CHANGED
package/src/api/TropipayAPI.ts
CHANGED
|
@@ -19,6 +19,8 @@ import {
|
|
|
19
19
|
type ServerMode = "Development" | "Production";
|
|
20
20
|
import { TropipayHooks } from "../hooks/TropipayHooks";
|
|
21
21
|
import { PaymentCard } from "../paymentcard/PaymentCard";
|
|
22
|
+
import { DepositAccounts } from "../depositAccount/depositAccounts";
|
|
23
|
+
import { handleExceptions } from "../utils/errors";
|
|
22
24
|
export class Tropipay {
|
|
23
25
|
readonly clientId: string;
|
|
24
26
|
readonly clientSecret: string;
|
|
@@ -27,7 +29,8 @@ export class Tropipay {
|
|
|
27
29
|
public static refreshToken: string | undefined;
|
|
28
30
|
public serverMode: ServerMode;
|
|
29
31
|
public hooks: TropipayHooks;
|
|
30
|
-
public
|
|
32
|
+
public paymentCards: PaymentCard;
|
|
33
|
+
public depositAccounts: DepositAccounts;
|
|
31
34
|
|
|
32
35
|
constructor(config: TropipayConfig) {
|
|
33
36
|
this.clientId = config.clientId;
|
|
@@ -45,7 +48,8 @@ export class Tropipay {
|
|
|
45
48
|
},
|
|
46
49
|
});
|
|
47
50
|
this.hooks = new TropipayHooks(this);
|
|
48
|
-
this.
|
|
51
|
+
this.paymentCards = new PaymentCard(this);
|
|
52
|
+
this.depositAccounts = new DepositAccounts(this);
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
public async login() {
|
|
@@ -71,14 +75,7 @@ export class Tropipay {
|
|
|
71
75
|
Tropipay.refreshToken = data.refresh_token;
|
|
72
76
|
return data;
|
|
73
77
|
} catch (error) {
|
|
74
|
-
|
|
75
|
-
throw new Error(
|
|
76
|
-
`Could not obtain the access token from credentials ${error}`
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
throw new Error(
|
|
80
|
-
`Could not obtain the access token from credentials ${error}`
|
|
81
|
-
);
|
|
78
|
+
throw handleExceptions(error as any);
|
|
82
79
|
}
|
|
83
80
|
}
|
|
84
81
|
|
|
@@ -101,7 +98,7 @@ export class Tropipay {
|
|
|
101
98
|
});
|
|
102
99
|
return deposits.data;
|
|
103
100
|
} catch (error) {
|
|
104
|
-
throw
|
|
101
|
+
throw handleExceptions(error as any);
|
|
105
102
|
}
|
|
106
103
|
}
|
|
107
104
|
|
|
@@ -115,7 +112,7 @@ export class Tropipay {
|
|
|
115
112
|
const countries = await this.request.get("/api/v2/countries");
|
|
116
113
|
return countries.data;
|
|
117
114
|
} catch (error) {
|
|
118
|
-
throw
|
|
115
|
+
throw handleExceptions(error as any);
|
|
119
116
|
}
|
|
120
117
|
}
|
|
121
118
|
/**
|
|
@@ -136,9 +133,7 @@ export class Tropipay {
|
|
|
136
133
|
});
|
|
137
134
|
return balance.data;
|
|
138
135
|
} catch (error) {
|
|
139
|
-
throw
|
|
140
|
-
`TropipayJS Error - Could not retrieve the user's balance`
|
|
141
|
-
);
|
|
136
|
+
throw handleExceptions(error as any);
|
|
142
137
|
}
|
|
143
138
|
}
|
|
144
139
|
|
|
@@ -182,7 +177,7 @@ export class Tropipay {
|
|
|
182
177
|
);
|
|
183
178
|
return favoritesList?.data?.rows;
|
|
184
179
|
} catch (error) {
|
|
185
|
-
throw
|
|
180
|
+
throw handleExceptions(error as any);
|
|
186
181
|
}
|
|
187
182
|
}
|
|
188
183
|
|
|
@@ -205,7 +200,7 @@ export class Tropipay {
|
|
|
205
200
|
});
|
|
206
201
|
return movements.data;
|
|
207
202
|
} catch (error) {
|
|
208
|
-
throw
|
|
203
|
+
throw handleExceptions(error as any);
|
|
209
204
|
}
|
|
210
205
|
}
|
|
211
206
|
|
|
@@ -219,7 +214,7 @@ export class Tropipay {
|
|
|
219
214
|
const profile = await this.request.get("/api/users/profile");
|
|
220
215
|
return profile.data;
|
|
221
216
|
} catch (error) {
|
|
222
|
-
throw
|
|
217
|
+
throw handleExceptions(error as any);
|
|
223
218
|
}
|
|
224
219
|
}
|
|
225
220
|
|
|
@@ -255,7 +250,7 @@ export class Tropipay {
|
|
|
255
250
|
);
|
|
256
251
|
return rates.data.rate;
|
|
257
252
|
} catch (error) {
|
|
258
|
-
throw
|
|
253
|
+
throw handleExceptions(error as any);
|
|
259
254
|
}
|
|
260
255
|
}
|
|
261
256
|
|
|
@@ -286,11 +281,13 @@ export class Tropipay {
|
|
|
286
281
|
);
|
|
287
282
|
return mediation.data as PaymentLink;
|
|
288
283
|
} catch (error) {
|
|
289
|
-
throw
|
|
284
|
+
throw handleExceptions(error as any);
|
|
290
285
|
}
|
|
291
286
|
}
|
|
292
287
|
}
|
|
293
288
|
|
|
294
289
|
export class ClientSideUtils {
|
|
295
|
-
constructor(tropipayInstance: Tropipay) {
|
|
290
|
+
constructor(tropipayInstance: Tropipay) {
|
|
291
|
+
throw Error(`Not implemented yet`);
|
|
292
|
+
}
|
|
296
293
|
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { AxiosError } from "axios";
|
|
2
|
+
import { Tropipay } from "../api/TropipayAPI";
|
|
3
|
+
import { DepositAccountConfig } from "../interfaces/depositaccounts";
|
|
4
|
+
import { handleExceptions } from "../utils/errors";
|
|
5
|
+
export class DepositAccounts {
|
|
6
|
+
private tropipay: Tropipay;
|
|
7
|
+
constructor(tropipayInstance: Tropipay) {
|
|
8
|
+
this.tropipay = tropipayInstance;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* List od all beneficiaries of this account
|
|
13
|
+
* @returns Array of DepositAccounts
|
|
14
|
+
*/
|
|
15
|
+
public async list() {
|
|
16
|
+
if (!Tropipay.accessToken) {
|
|
17
|
+
await this.tropipay.login();
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const deposit = await this.tropipay.request.get(
|
|
21
|
+
`/api/v2/deposit_accounts`,
|
|
22
|
+
{
|
|
23
|
+
headers: {
|
|
24
|
+
"Content-Type": "application/json",
|
|
25
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
26
|
+
Accept: "application/json",
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
return deposit.data;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return handleExceptions(error as unknown as any);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Adds a new beneficiary to the user account.
|
|
37
|
+
* @param payload
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
public async create(depositAccountObj: DepositAccountConfig) {
|
|
41
|
+
if (!Tropipay.accessToken) {
|
|
42
|
+
await this.tropipay.login();
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const deposit = await this.tropipay.request.post(
|
|
46
|
+
"/api/v2/deposit_accounts",
|
|
47
|
+
depositAccountObj,
|
|
48
|
+
{
|
|
49
|
+
headers: {
|
|
50
|
+
"Content-Type": "application/json",
|
|
51
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
52
|
+
Accept: "application/json",
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
return deposit.data;
|
|
57
|
+
} catch (error) {
|
|
58
|
+
return handleExceptions(error as unknown as any);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* This returns details of a specific
|
|
63
|
+
* Deposit Account (beneficiary) specified by its ID
|
|
64
|
+
* @param id
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
67
|
+
public async get(id: string) {
|
|
68
|
+
if (!Tropipay.accessToken) {
|
|
69
|
+
await this.tropipay.login();
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
const deposit = await this.tropipay.request.get(
|
|
73
|
+
`/api/v2/deposit_accounts/${id}`,
|
|
74
|
+
{
|
|
75
|
+
headers: {
|
|
76
|
+
"Content-Type": "application/json",
|
|
77
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
78
|
+
Accept: "application/json",
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
return deposit.data;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
return handleExceptions(error as unknown as any);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Updates certain beneficiary data.
|
|
90
|
+
* @param depositAccountObj
|
|
91
|
+
* @returns
|
|
92
|
+
*/
|
|
93
|
+
public async update(depositAccountObj: Partial<DepositAccountConfig>) {
|
|
94
|
+
if (!Tropipay.accessToken) {
|
|
95
|
+
await this.tropipay.login();
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const deposit = await this.tropipay.request.put(
|
|
99
|
+
`/api/v2/deposit_accounts/`,
|
|
100
|
+
{
|
|
101
|
+
headers: {
|
|
102
|
+
"Content-Type": "application/json",
|
|
103
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
104
|
+
Accept: "application/json",
|
|
105
|
+
},
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
return deposit.data;
|
|
109
|
+
} catch (error) {
|
|
110
|
+
return handleExceptions(error as unknown as any);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* (UNTESTED) Deletes the beneficiary indicated by id
|
|
116
|
+
* @param id
|
|
117
|
+
* @returns
|
|
118
|
+
*/
|
|
119
|
+
public async delete(id: number) {
|
|
120
|
+
if (!Tropipay.accessToken) {
|
|
121
|
+
await this.tropipay.login();
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
const deposit = await this.tropipay.request.delete(
|
|
125
|
+
`/api/v2/deposit_accounts/${id}`,
|
|
126
|
+
{
|
|
127
|
+
headers: {
|
|
128
|
+
"Content-Type": "application/json",
|
|
129
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
130
|
+
Accept: "application/json",
|
|
131
|
+
},
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
return deposit.data;
|
|
135
|
+
} catch (error) {
|
|
136
|
+
return handleExceptions(error as unknown as any);
|
|
137
|
+
}
|
|
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
|
}
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
* @license MIT
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
import { DepositAccounts } from "./depositAccount/depositAccounts";
|
|
14
|
+
|
|
13
15
|
if (typeof window !== "undefined") {
|
|
14
16
|
console.warn(
|
|
15
17
|
"DANGER This library should not be used client side, your credentials could be exposed"
|
|
@@ -21,6 +23,7 @@ export { ClientSideUtils } from "./api/TropipayAPI";
|
|
|
21
23
|
export { ServerSideUtils } from "./utils/TropipayUtils";
|
|
22
24
|
export { TropipayHooks } from "./hooks/TropipayHooks";
|
|
23
25
|
export { PaymentCard } from "./paymentcard/PaymentCard";
|
|
26
|
+
export { DepositAccounts } from "./depositAccount/depositAccounts";
|
|
24
27
|
export * from "./interfaces/index";
|
|
25
28
|
export { SERVER_MODE } from "./config/TropipayConfig";
|
|
26
29
|
export * from "./constants/TropipayConstants";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export interface DepositAccountConfig {
|
|
2
|
+
searchValue?: string;
|
|
3
|
+
alias: string;
|
|
4
|
+
userRelationTypeId: number;
|
|
5
|
+
beneficiaryType: BeneficiaryType;
|
|
6
|
+
searchBy?: number;
|
|
7
|
+
accountNumber?: string;
|
|
8
|
+
swift?: string;
|
|
9
|
+
type: DepositAccountType;
|
|
10
|
+
firstName?: string;
|
|
11
|
+
lastName?: string;
|
|
12
|
+
secondLastName?: string;
|
|
13
|
+
countryDestinationId?: number;
|
|
14
|
+
city?: string;
|
|
15
|
+
postalCode?: number;
|
|
16
|
+
address?: string;
|
|
17
|
+
documentNumber?: string;
|
|
18
|
+
phone?: string;
|
|
19
|
+
province?: string;
|
|
20
|
+
paymentType?: string;
|
|
21
|
+
documentTypeId?: number;
|
|
22
|
+
documentExpirationDate: string;
|
|
23
|
+
}
|
|
24
|
+
type INTERNAL = 1;
|
|
25
|
+
type EXTERNAL = 2;
|
|
26
|
+
|
|
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,9 +1,9 @@
|
|
|
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
7
|
constructor(tropipayInstance: Tropipay) {
|
|
8
8
|
this.tropipay = tropipayInstance;
|
|
9
9
|
}
|
|
@@ -32,7 +32,7 @@ export class PaymentCard {
|
|
|
32
32
|
);
|
|
33
33
|
return paylink.data as PaymentLink;
|
|
34
34
|
} catch (error) {
|
|
35
|
-
throw
|
|
35
|
+
throw handleExceptions(error as unknown as any);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
@@ -78,7 +78,7 @@ export class PaymentCard {
|
|
|
78
78
|
);
|
|
79
79
|
return paymentcard.data;
|
|
80
80
|
} catch (error) {
|
|
81
|
-
throw
|
|
81
|
+
throw handleExceptions(error as unknown as any);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
}
|
|
@@ -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 {};
|