@yosle/tropipayjs 0.1.14 → 0.1.15
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 +65 -2
- package/index.js +127 -2
- package/interfaces/depositaccounts/index.d.ts +27 -0
- package/package.json +1 -1
- package/src/api/TropipayAPI.ts +5 -2
- package/src/depositAccount/depositAccounts.ts +138 -0
- package/src/index.ts +3 -0
- package/src/interfaces/depositaccounts/index.ts +27 -0
- package/src/paymentcard/PaymentCard.ts +0 -1
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,68 @@ 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?: number;
|
|
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
|
+
|
|
247
|
+
declare class DepositAccounts {
|
|
248
|
+
private tropipay;
|
|
249
|
+
constructor(tropipayInstance: Tropipay);
|
|
250
|
+
/**
|
|
251
|
+
* List od all beneficiaries of this account
|
|
252
|
+
* @returns Array of DepositAccounts
|
|
253
|
+
*/
|
|
254
|
+
list(): Promise<any>;
|
|
255
|
+
/**
|
|
256
|
+
* Adds a new beneficiary to the user account.
|
|
257
|
+
* @param payload
|
|
258
|
+
* @returns
|
|
259
|
+
*/
|
|
260
|
+
create(depositAccountObj: DepositAccountConfig): Promise<any>;
|
|
261
|
+
/**
|
|
262
|
+
* This returns details of a specific
|
|
263
|
+
* Deposit Account (beneficiary) specified by its ID
|
|
264
|
+
* @param id
|
|
265
|
+
* @returns
|
|
266
|
+
*/
|
|
267
|
+
get(id: string): Promise<any>;
|
|
268
|
+
/**
|
|
269
|
+
* Updates certain beneficiary data.
|
|
270
|
+
* @param depositAccountObj
|
|
271
|
+
* @returns
|
|
272
|
+
*/
|
|
273
|
+
update(depositAccountObj: Partial<DepositAccountConfig>): Promise<any>;
|
|
274
|
+
/**
|
|
275
|
+
* (UNTESTED) Deletes the beneficiary indicated by id
|
|
276
|
+
* @param id
|
|
277
|
+
* @returns
|
|
278
|
+
*/
|
|
279
|
+
delete(id: number): Promise<any>;
|
|
280
|
+
}
|
|
281
|
+
|
|
220
282
|
/**
|
|
221
283
|
* Tropipayjs is a Typescript/Javascript library for the Tropipay API.
|
|
222
284
|
*
|
|
@@ -234,7 +296,8 @@ declare class Tropipay {
|
|
|
234
296
|
static refreshToken: string | undefined;
|
|
235
297
|
serverMode: ServerMode;
|
|
236
298
|
hooks: TropipayHooks;
|
|
237
|
-
|
|
299
|
+
paymentCards: PaymentCard;
|
|
300
|
+
depositAccounts: DepositAccounts;
|
|
238
301
|
constructor(config: TropipayConfig);
|
|
239
302
|
login(): Promise<LoginResponse>;
|
|
240
303
|
/**
|
|
@@ -322,4 +385,4 @@ declare class ServerSideUtils {
|
|
|
322
385
|
|
|
323
386
|
declare const SERVER_MODE: ServerMode$1;
|
|
324
387
|
|
|
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 };
|
|
388
|
+
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
|
@@ -230,6 +230,128 @@ class PaymentCard {
|
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
+
class DepositAccounts {
|
|
234
|
+
tropipay;
|
|
235
|
+
constructor(tropipayInstance) {
|
|
236
|
+
this.tropipay = tropipayInstance;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* List od all beneficiaries of this account
|
|
240
|
+
* @returns Array of DepositAccounts
|
|
241
|
+
*/
|
|
242
|
+
async list() {
|
|
243
|
+
if (!Tropipay.accessToken) {
|
|
244
|
+
await this.tropipay.login();
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
const deposit = await this.tropipay.request.get(`/api/v2/deposit_accounts`, {
|
|
248
|
+
headers: {
|
|
249
|
+
"Content-Type": "application/json",
|
|
250
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
251
|
+
Accept: "application/json",
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
return deposit.data;
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
throw new Error(`Could not retrieve PaymenCards list`);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Adds a new beneficiary to the user account.
|
|
262
|
+
* @param payload
|
|
263
|
+
* @returns
|
|
264
|
+
*/
|
|
265
|
+
async create(depositAccountObj) {
|
|
266
|
+
if (!Tropipay.accessToken) {
|
|
267
|
+
await this.tropipay.login();
|
|
268
|
+
}
|
|
269
|
+
try {
|
|
270
|
+
const deposit = await this.tropipay.request.post("/api/v2/deposit_accounts", depositAccountObj, {
|
|
271
|
+
headers: {
|
|
272
|
+
"Content-Type": "application/json",
|
|
273
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
274
|
+
Accept: "application/json",
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
return deposit.data;
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
throw new Error(`TropipayJS - Error creating the Deposit Accounts.`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* This returns details of a specific
|
|
285
|
+
* Deposit Account (beneficiary) specified by its ID
|
|
286
|
+
* @param id
|
|
287
|
+
* @returns
|
|
288
|
+
*/
|
|
289
|
+
async get(id) {
|
|
290
|
+
if (!Tropipay.accessToken) {
|
|
291
|
+
await this.tropipay.login();
|
|
292
|
+
}
|
|
293
|
+
try {
|
|
294
|
+
const deposit = await this.tropipay.request.get(`/api/v2/deposit_accounts/${id}`, {
|
|
295
|
+
headers: {
|
|
296
|
+
"Content-Type": "application/json",
|
|
297
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
298
|
+
Accept: "application/json",
|
|
299
|
+
},
|
|
300
|
+
});
|
|
301
|
+
return deposit.data;
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
throw new Error(`Could not retrieve deposit account`);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Updates certain beneficiary data.
|
|
309
|
+
* @param depositAccountObj
|
|
310
|
+
* @returns
|
|
311
|
+
*/
|
|
312
|
+
async update(depositAccountObj) {
|
|
313
|
+
if (!Tropipay.accessToken) {
|
|
314
|
+
await this.tropipay.login();
|
|
315
|
+
}
|
|
316
|
+
try {
|
|
317
|
+
const deposit = await this.tropipay.request.put(`/api/v2/deposit_accounts/`, {
|
|
318
|
+
headers: {
|
|
319
|
+
"Content-Type": "application/json",
|
|
320
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
321
|
+
Accept: "application/json",
|
|
322
|
+
},
|
|
323
|
+
});
|
|
324
|
+
return deposit.data;
|
|
325
|
+
}
|
|
326
|
+
catch (error) {
|
|
327
|
+
throw new Error(`Could not retrieve deposit account`);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* (UNTESTED) Deletes the beneficiary indicated by id
|
|
332
|
+
* @param id
|
|
333
|
+
* @returns
|
|
334
|
+
*/
|
|
335
|
+
async delete(id) {
|
|
336
|
+
if (!Tropipay.accessToken) {
|
|
337
|
+
await this.tropipay.login();
|
|
338
|
+
}
|
|
339
|
+
try {
|
|
340
|
+
const deposit = await this.tropipay.request.delete(`/api/v2/deposit_accounts/${id}`, {
|
|
341
|
+
headers: {
|
|
342
|
+
"Content-Type": "application/json",
|
|
343
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
344
|
+
Accept: "application/json",
|
|
345
|
+
},
|
|
346
|
+
});
|
|
347
|
+
return deposit.data;
|
|
348
|
+
}
|
|
349
|
+
catch (error) {
|
|
350
|
+
throw new Error(`Could not retrieve deposit account`);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
233
355
|
/**
|
|
234
356
|
* Tropipayjs is a Typescript/Javascript library for the Tropipay API.
|
|
235
357
|
*
|
|
@@ -244,7 +366,8 @@ class Tropipay {
|
|
|
244
366
|
static refreshToken;
|
|
245
367
|
serverMode;
|
|
246
368
|
hooks;
|
|
247
|
-
|
|
369
|
+
paymentCards;
|
|
370
|
+
depositAccounts;
|
|
248
371
|
constructor(config) {
|
|
249
372
|
this.clientId = config.clientId;
|
|
250
373
|
this.clientSecret = config.clientSecret;
|
|
@@ -260,7 +383,8 @@ class Tropipay {
|
|
|
260
383
|
},
|
|
261
384
|
});
|
|
262
385
|
this.hooks = new TropipayHooks(this);
|
|
263
|
-
this.
|
|
386
|
+
this.paymentCards = new PaymentCard(this);
|
|
387
|
+
this.depositAccounts = new DepositAccounts(this);
|
|
264
388
|
}
|
|
265
389
|
async login() {
|
|
266
390
|
try {
|
|
@@ -528,6 +652,7 @@ if (typeof window !== "undefined") {
|
|
|
528
652
|
}
|
|
529
653
|
|
|
530
654
|
exports.ClientSideUtils = ClientSideUtils;
|
|
655
|
+
exports.DepositAccounts = DepositAccounts;
|
|
531
656
|
exports.PaymentCard = PaymentCard;
|
|
532
657
|
exports.SERVER_MODE = SERVER_MODE;
|
|
533
658
|
exports.ServerSideUtils = ServerSideUtils;
|
|
@@ -0,0 +1,27 @@
|
|
|
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?: number;
|
|
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 {};
|
package/package.json
CHANGED
package/src/api/TropipayAPI.ts
CHANGED
|
@@ -19,6 +19,7 @@ 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";
|
|
22
23
|
export class Tropipay {
|
|
23
24
|
readonly clientId: string;
|
|
24
25
|
readonly clientSecret: string;
|
|
@@ -27,7 +28,8 @@ export class Tropipay {
|
|
|
27
28
|
public static refreshToken: string | undefined;
|
|
28
29
|
public serverMode: ServerMode;
|
|
29
30
|
public hooks: TropipayHooks;
|
|
30
|
-
public
|
|
31
|
+
public paymentCards: PaymentCard;
|
|
32
|
+
public depositAccounts: DepositAccounts;
|
|
31
33
|
|
|
32
34
|
constructor(config: TropipayConfig) {
|
|
33
35
|
this.clientId = config.clientId;
|
|
@@ -45,7 +47,8 @@ export class Tropipay {
|
|
|
45
47
|
},
|
|
46
48
|
});
|
|
47
49
|
this.hooks = new TropipayHooks(this);
|
|
48
|
-
this.
|
|
50
|
+
this.paymentCards = new PaymentCard(this);
|
|
51
|
+
this.depositAccounts = new DepositAccounts(this);
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
public async login() {
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { Tropipay } from "../api/TropipayAPI";
|
|
2
|
+
import { DepositAccountConfig } from "../interfaces/depositaccounts";
|
|
3
|
+
|
|
4
|
+
export class DepositAccounts {
|
|
5
|
+
private tropipay: Tropipay;
|
|
6
|
+
constructor(tropipayInstance: Tropipay) {
|
|
7
|
+
this.tropipay = tropipayInstance;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* List od all beneficiaries of this account
|
|
12
|
+
* @returns Array of DepositAccounts
|
|
13
|
+
*/
|
|
14
|
+
public async list() {
|
|
15
|
+
if (!Tropipay.accessToken) {
|
|
16
|
+
await this.tropipay.login();
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const deposit = await this.tropipay.request.get(
|
|
20
|
+
`/api/v2/deposit_accounts`,
|
|
21
|
+
{
|
|
22
|
+
headers: {
|
|
23
|
+
"Content-Type": "application/json",
|
|
24
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
25
|
+
Accept: "application/json",
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
return deposit.data;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
throw new Error(`Could not retrieve PaymenCards list`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Adds a new beneficiary to the user account.
|
|
36
|
+
* @param payload
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
public async create(depositAccountObj: DepositAccountConfig) {
|
|
40
|
+
if (!Tropipay.accessToken) {
|
|
41
|
+
await this.tropipay.login();
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const deposit = await this.tropipay.request.post(
|
|
45
|
+
"/api/v2/deposit_accounts",
|
|
46
|
+
depositAccountObj,
|
|
47
|
+
{
|
|
48
|
+
headers: {
|
|
49
|
+
"Content-Type": "application/json",
|
|
50
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
51
|
+
Accept: "application/json",
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
return deposit.data;
|
|
56
|
+
} catch (error) {
|
|
57
|
+
throw new Error(`TropipayJS - Error creating the Deposit Accounts.`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* This returns details of a specific
|
|
62
|
+
* Deposit Account (beneficiary) specified by its ID
|
|
63
|
+
* @param id
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
public async get(id: string) {
|
|
67
|
+
if (!Tropipay.accessToken) {
|
|
68
|
+
await this.tropipay.login();
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
const deposit = await this.tropipay.request.get(
|
|
72
|
+
`/api/v2/deposit_accounts/${id}`,
|
|
73
|
+
{
|
|
74
|
+
headers: {
|
|
75
|
+
"Content-Type": "application/json",
|
|
76
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
77
|
+
Accept: "application/json",
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
return deposit.data;
|
|
82
|
+
} catch (error) {
|
|
83
|
+
throw new Error(`Could not retrieve deposit account`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Updates certain beneficiary data.
|
|
89
|
+
* @param depositAccountObj
|
|
90
|
+
* @returns
|
|
91
|
+
*/
|
|
92
|
+
public async update(depositAccountObj: Partial<DepositAccountConfig>) {
|
|
93
|
+
if (!Tropipay.accessToken) {
|
|
94
|
+
await this.tropipay.login();
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const deposit = await this.tropipay.request.put(
|
|
98
|
+
`/api/v2/deposit_accounts/`,
|
|
99
|
+
{
|
|
100
|
+
headers: {
|
|
101
|
+
"Content-Type": "application/json",
|
|
102
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
103
|
+
Accept: "application/json",
|
|
104
|
+
},
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
return deposit.data;
|
|
108
|
+
} catch (error) {
|
|
109
|
+
throw new Error(`Could not retrieve deposit account`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* (UNTESTED) Deletes the beneficiary indicated by id
|
|
115
|
+
* @param id
|
|
116
|
+
* @returns
|
|
117
|
+
*/
|
|
118
|
+
public async delete(id: number) {
|
|
119
|
+
if (!Tropipay.accessToken) {
|
|
120
|
+
await this.tropipay.login();
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
const deposit = await this.tropipay.request.delete(
|
|
124
|
+
`/api/v2/deposit_accounts/${id}`,
|
|
125
|
+
{
|
|
126
|
+
headers: {
|
|
127
|
+
"Content-Type": "application/json",
|
|
128
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
129
|
+
Accept: "application/json",
|
|
130
|
+
},
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
return deposit.data;
|
|
134
|
+
} catch (error) {
|
|
135
|
+
throw new Error(`Could not retrieve deposit account`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
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,27 @@
|
|
|
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?: number;
|
|
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;
|