@yosle/tropipayjs 0.1.4 → 0.1.5
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 +53 -13
- package/docs/images/app-credentials-menu.png +0 -0
- package/docs/images/confirmation-code-screen.png +0 -0
- package/index.d.ts +28 -19
- package/index.js +58 -43
- package/index.ts +64 -47
- package/package.json +5 -1
- package/dist/index.d.ts +0 -59
- package/dist/index.js +0 -187
- package/dist/interfaces/countries/index.d.ts +0 -0
- package/dist/interfaces/countries/index.js +0 -2
- package/dist/interfaces/index.d.ts +0 -0
- package/dist/interfaces/index.js +0 -2
- package/dist/interfaces/paymentlink/index.d.ts +0 -36
- package/dist/interfaces/paymentlink/index.js +0 -2
package/README.md
CHANGED
|
@@ -1,28 +1,68 @@
|
|
|
1
|
-
TropipayJS -
|
|
1
|
+
TropipayJS -Typescript/Javascript SDK for Tropipay Payments API
|
|
2
2
|
===========
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
3
7
|
|
|
4
|
-
TropiPay is an electronic wallet that allows you to execute the most common financial operations of the day to day. This is
|
|
8
|
+
TropiPay is an electronic wallet that allows you to execute the most common financial operations of the day to day. This is an 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 (like node + express) or ES6 module system (NextJS).
|
|
5
9
|
|
|
6
|
-
|
|
10
|
+
## Project status
|
|
11
|
+
This library is still under development so using it in the live (real account) isn't recommended yet.
|
|
12
|
+
|
|
13
|
+
# Table of Contents
|
|
14
|
+
* [Getting started](#getting-started)
|
|
15
|
+
* [Setting up your credentials](#setting-up-your-app-credentials)
|
|
16
|
+
* [Documentation](#documentation)
|
|
17
|
+
* [Examples](#examples)
|
|
18
|
+
* [Contribute and Help](#contributing-and-help)
|
|
19
|
+
|
|
20
|
+
# Getting started
|
|
7
21
|
You can use npm or yarn to install this package:
|
|
8
22
|
|
|
9
|
-
|
|
10
|
-
`yarn add tropipayjs`
|
|
23
|
+
```npm install @yosle/tropipayjs```
|
|
11
24
|
|
|
12
|
-
|
|
13
|
-
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.
|
|
25
|
+
or
|
|
14
26
|
|
|
15
|
-
|
|
16
|
-
|
|
27
|
+
```yarn add @yosle/tropipayjs```
|
|
28
|
+
|
|
29
|
+
## Setting up your app credentials
|
|
30
|
+

|
|
31
|
+

|
|
32
|
+
In order to use the Tropipay API you'll need a client ID and a client secret. Sign up with your [Tropipay](www.tropipay.com) account, go to the App Menu->Applications and credentials. You'll be asked to enter a confirmation code (use 123456 in the test enviroment). _Make sure you test everything in the [test enviroment](https://tropipay-dev.herokuapp.com) first before using your real account._ Create an app and configure the client id an client secret for the app.
|
|
33
|
+
|
|
34
|
+
## How to use
|
|
35
|
+
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.
|
|
17
36
|
|
|
18
|
-
|
|
37
|
+
### CommonJS
|
|
38
|
+
```javascript
|
|
39
|
+
const { Tropipay } = require('@yosle/tropipayjs')
|
|
40
|
+
```
|
|
41
|
+
### ES6
|
|
42
|
+
```javascript
|
|
43
|
+
import { Tropipay } from '@yosle/tropipayjs'
|
|
44
|
+
```
|
|
45
|
+
### Initialize the Tropipay class
|
|
46
|
+
```javascript
|
|
47
|
+
const tpp = new Tropipay("yourclientidhere",
|
|
48
|
+
"yourclientsecrethere")
|
|
49
|
+
```
|
|
50
|
+
## Generating a Payment Link
|
|
51
|
+
```javascript
|
|
52
|
+
const paylink = await tpp.createPayLink(payload)
|
|
53
|
+
```
|
|
19
54
|
|
|
20
|
-
#
|
|
55
|
+
# Documentation
|
|
56
|
+
Examples using express + nodejs and NextJS will be added soon.
|
|
21
57
|
|
|
22
|
-
# Contributing
|
|
23
|
-
|
|
58
|
+
# Contributing
|
|
59
|
+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
|
24
60
|
|
|
61
|
+
Please make sure to update tests as appropriate.
|
|
25
62
|
|
|
63
|
+
You can also make a small [donation to the author](https://tppay.me/l94qaa3h).
|
|
64
|
+
## License
|
|
65
|
+
[MIT License](https://choosealicense.com/licenses/mit/)
|
|
26
66
|
|
|
27
67
|
|
|
28
68
|
|
|
Binary file
|
|
Binary file
|
package/index.d.ts
CHANGED
|
@@ -38,26 +38,26 @@ interface PaymentLink extends PaymentLinkPayload {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
* Tropipayjs is a
|
|
42
|
-
*
|
|
43
|
-
* @author Yosleivy
|
|
41
|
+
* Tropipayjs is a Typescript/Javascript library for the Tropipay API. CommonJs and
|
|
42
|
+
* ES6 modules are supported.
|
|
43
|
+
* @author Yosleivy Baez Acosta
|
|
44
44
|
*
|
|
45
45
|
*/
|
|
46
46
|
|
|
47
47
|
declare type ServerMode = 'Development' | 'Production';
|
|
48
48
|
declare class Tropipay {
|
|
49
|
-
readonly
|
|
50
|
-
readonly
|
|
51
|
-
request: Axios;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
readonly clientId: string;
|
|
50
|
+
readonly clientSecret: string;
|
|
51
|
+
protected request: Axios;
|
|
52
|
+
protected accessToken: string | undefined;
|
|
53
|
+
protected refreshToken: string | undefined;
|
|
54
|
+
protected serverMode: ServerMode;
|
|
55
55
|
constructor(client_id: string, client_secret: string, server_mode?: ServerMode);
|
|
56
56
|
login(): Promise<LoginResponse>;
|
|
57
57
|
/**
|
|
58
|
-
* Create a paymentLink
|
|
59
|
-
* @param payload
|
|
60
|
-
* @returns Promise<PaymentLink> or
|
|
58
|
+
* Create a paymentLink with the specified options.
|
|
59
|
+
* @param payload PaymentLinkPayload Object.
|
|
60
|
+
* @returns Promise<PaymentLink> or throws an Exception.
|
|
61
61
|
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
62
62
|
*/
|
|
63
63
|
createPayLink(payload: PaymentLinkPayload): Promise<PaymentLink>;
|
|
@@ -69,19 +69,28 @@ declare class Tropipay {
|
|
|
69
69
|
getDepositAccounts(): Promise<AccountDeposits[] | Error>;
|
|
70
70
|
/**
|
|
71
71
|
* Get the list of all supported countries by Tropipay.
|
|
72
|
-
* @returns Array of Countries
|
|
73
|
-
* @see
|
|
72
|
+
* @returns Array of Countries Data
|
|
73
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/bfac21259e2ff-getting-users-countries-list
|
|
74
74
|
*/
|
|
75
|
-
countries(): Promise<Country[]
|
|
75
|
+
countries(): Promise<Country[]>;
|
|
76
76
|
/**
|
|
77
|
-
* Get list of all
|
|
77
|
+
* Get the list of all detination countries supported by Tropipay.
|
|
78
|
+
* Obtaining the list of valid countries to send funds to. Useful
|
|
79
|
+
* when adding new beneficiaries to some user.
|
|
80
|
+
*
|
|
81
|
+
* @returns Array of Country Objects
|
|
82
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/3cfe5504f0524-getting-list-of-beneficiary-countries
|
|
83
|
+
*/
|
|
84
|
+
destinations(): Promise<Country[]>;
|
|
85
|
+
/**
|
|
86
|
+
* Get list of all the favorites accounts. This endpoint is not documented
|
|
87
|
+
* in the official Tropipay documentation.
|
|
78
88
|
* @returns
|
|
79
|
-
* @see
|
|
80
89
|
*/
|
|
81
90
|
favorites(): Promise<any>;
|
|
82
91
|
/**
|
|
83
|
-
* List all movements
|
|
84
|
-
*
|
|
92
|
+
* List all account movements. You can optionaly specify
|
|
93
|
+
* offset and limit params for pagination.
|
|
85
94
|
* @returns
|
|
86
95
|
*/
|
|
87
96
|
movements(offset?: number, limit?: number): Promise<any>;
|
package/index.js
CHANGED
|
@@ -9,38 +9,38 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
9
9
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Tropipayjs is a
|
|
13
|
-
*
|
|
14
|
-
* @author Yosleivy
|
|
12
|
+
* Tropipayjs is a Typescript/Javascript library for the Tropipay API. CommonJs and
|
|
13
|
+
* ES6 modules are supported.
|
|
14
|
+
* @author Yosleivy Baez Acosta
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
17
|
class Tropipay {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
clientId;
|
|
19
|
+
clientSecret;
|
|
20
20
|
request;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
accessToken;
|
|
22
|
+
refreshToken;
|
|
23
|
+
serverMode;
|
|
24
24
|
constructor(client_id, client_secret, server_mode = 'Development') {
|
|
25
|
-
this.
|
|
26
|
-
this.
|
|
27
|
-
this.
|
|
25
|
+
this.clientId = client_id;
|
|
26
|
+
this.clientSecret = client_secret;
|
|
27
|
+
this.serverMode = server_mode;
|
|
28
28
|
this.request = axios__default["default"].create({
|
|
29
|
-
baseURL: this.
|
|
29
|
+
baseURL: this.serverMode === 'Production'
|
|
30
30
|
? 'https://www.tropipay.com'
|
|
31
31
|
: 'https://tropipay-dev.herokuapp.com',
|
|
32
32
|
headers: {
|
|
33
33
|
'Content-Type': 'application/json',
|
|
34
34
|
Accept: 'application/json',
|
|
35
|
-
Authorization: `Bearer ${this.
|
|
35
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
async login() {
|
|
40
40
|
try {
|
|
41
41
|
const { data } = await this.request.post('/api/v2/access/token', {
|
|
42
|
-
client_id: this.
|
|
43
|
-
client_secret: this.
|
|
42
|
+
client_id: this.clientId,
|
|
43
|
+
client_secret: this.clientSecret,
|
|
44
44
|
grant_type: "client_credentials",
|
|
45
45
|
scope: "ALLOW_GET_PROFILE_DATA ALLOW_PAYMENT_IN ALLOW_EXTERNAL_CHARGE KYC3_FULL_ALLOW ALLOW_PAYMENT_OUT ALLOW_MARKET_PURCHASES ALLOW_GET_BALANCE ALLOW_GET_MOVEMENT_LIST ALLOW_GET_CREDENTIAL "
|
|
46
46
|
}, {
|
|
@@ -49,8 +49,8 @@ class Tropipay {
|
|
|
49
49
|
// Accept: 'application/json',
|
|
50
50
|
// }
|
|
51
51
|
});
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
52
|
+
this.accessToken = data.access_token;
|
|
53
|
+
this.refreshToken = data.refresh_token;
|
|
54
54
|
return data;
|
|
55
55
|
}
|
|
56
56
|
catch (error) {
|
|
@@ -62,27 +62,27 @@ class Tropipay {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
|
-
* Create a paymentLink
|
|
66
|
-
* @param payload
|
|
67
|
-
* @returns Promise<PaymentLink> or
|
|
65
|
+
* Create a paymentLink with the specified options.
|
|
66
|
+
* @param payload PaymentLinkPayload Object.
|
|
67
|
+
* @returns Promise<PaymentLink> or throws an Exception.
|
|
68
68
|
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
69
69
|
*/
|
|
70
70
|
async createPayLink(payload) {
|
|
71
|
-
if (!this.
|
|
71
|
+
if (!this.accessToken) {
|
|
72
72
|
await this.login();
|
|
73
73
|
}
|
|
74
74
|
try {
|
|
75
75
|
const paylink = await this.request.post('/api/v2/paymentcards', payload, {
|
|
76
76
|
headers: {
|
|
77
77
|
// 'Content-Type': 'application/json',
|
|
78
|
-
Authorization: `Bearer ${this.
|
|
78
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
79
79
|
// Accept: 'application/json'
|
|
80
80
|
}
|
|
81
81
|
});
|
|
82
82
|
return paylink.data;
|
|
83
83
|
}
|
|
84
84
|
catch (error) {
|
|
85
|
-
throw new Error(`
|
|
85
|
+
throw new Error(`Could not obtain the access tokemn with the given credentials.`);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
@@ -91,7 +91,7 @@ class Tropipay {
|
|
|
91
91
|
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6OTgyOTQ1Mg-get-deposit-accounts-list
|
|
92
92
|
*/
|
|
93
93
|
async getDepositAccounts() {
|
|
94
|
-
if (!this.
|
|
94
|
+
if (!this.accessToken) {
|
|
95
95
|
await this.login();
|
|
96
96
|
}
|
|
97
97
|
try {
|
|
@@ -104,15 +104,12 @@ class Tropipay {
|
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
106
|
* Get the list of all supported countries by Tropipay.
|
|
107
|
-
* @returns Array of Countries
|
|
108
|
-
* @see
|
|
107
|
+
* @returns Array of Countries Data
|
|
108
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/bfac21259e2ff-getting-users-countries-list
|
|
109
109
|
*/
|
|
110
110
|
async countries() {
|
|
111
|
-
if (!this.access_token) {
|
|
112
|
-
await this.login();
|
|
113
|
-
}
|
|
114
111
|
try {
|
|
115
|
-
const countries = await this.request.get('/api/countries');
|
|
112
|
+
const countries = await this.request.get('/api/v2/countries');
|
|
116
113
|
return countries.data;
|
|
117
114
|
}
|
|
118
115
|
catch (error) {
|
|
@@ -120,29 +117,47 @@ class Tropipay {
|
|
|
120
117
|
}
|
|
121
118
|
}
|
|
122
119
|
/**
|
|
123
|
-
* Get list of all
|
|
120
|
+
* Get the list of all detination countries supported by Tropipay.
|
|
121
|
+
* Obtaining the list of valid countries to send funds to. Useful
|
|
122
|
+
* when adding new beneficiaries to some user.
|
|
123
|
+
*
|
|
124
|
+
* @returns Array of Country Objects
|
|
125
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/3cfe5504f0524-getting-list-of-beneficiary-countries
|
|
126
|
+
*/
|
|
127
|
+
async destinations() {
|
|
128
|
+
try {
|
|
129
|
+
const countries = await this.request.get('/api/v2/countries/destinations');
|
|
130
|
+
return countries.data;
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
throw new Error(`Could not retrieve the destination countries list`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get list of all the favorites accounts. This endpoint is not documented
|
|
138
|
+
* in the official Tropipay documentation.
|
|
124
139
|
* @returns
|
|
125
|
-
* @see
|
|
126
140
|
*/
|
|
127
141
|
async favorites() {
|
|
128
|
-
if (!this.
|
|
142
|
+
if (!this.accessToken) {
|
|
129
143
|
await this.login();
|
|
130
144
|
}
|
|
131
145
|
try {
|
|
132
|
-
const
|
|
133
|
-
|
|
146
|
+
const favoritesList = await this.request.get('/api/v2/paymentcards/favorites');
|
|
147
|
+
console.log(favoritesList);
|
|
148
|
+
return favoritesList.data;
|
|
134
149
|
}
|
|
135
150
|
catch (error) {
|
|
136
|
-
throw new Error(`Could not retrieve favorites list`);
|
|
151
|
+
throw new Error(`Could not retrieve favorites list ${error}`);
|
|
137
152
|
}
|
|
138
153
|
}
|
|
139
154
|
/**
|
|
140
|
-
* List all movements
|
|
141
|
-
*
|
|
155
|
+
* List all account movements. You can optionaly specify
|
|
156
|
+
* offset and limit params for pagination.
|
|
142
157
|
* @returns
|
|
143
158
|
*/
|
|
144
159
|
async movements(offset = 0, limit = 10) {
|
|
145
|
-
if (!this.
|
|
160
|
+
if (!this.accessToken) {
|
|
146
161
|
await this.login();
|
|
147
162
|
}
|
|
148
163
|
try {
|
|
@@ -150,7 +165,7 @@ class Tropipay {
|
|
|
150
165
|
headers: {
|
|
151
166
|
'Content-Type': 'application/json',
|
|
152
167
|
Accept: 'application/json',
|
|
153
|
-
Authorization: `Bearer ${this.
|
|
168
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
154
169
|
} });
|
|
155
170
|
return movements.data;
|
|
156
171
|
}
|
|
@@ -163,7 +178,7 @@ class Tropipay {
|
|
|
163
178
|
* @returns
|
|
164
179
|
*/
|
|
165
180
|
async profile() {
|
|
166
|
-
if (!this.
|
|
181
|
+
if (!this.accessToken) {
|
|
167
182
|
await this.login();
|
|
168
183
|
}
|
|
169
184
|
try {
|
|
@@ -176,7 +191,7 @@ class Tropipay {
|
|
|
176
191
|
}
|
|
177
192
|
async getRates(payload = { currencyFrom: "EUR" }) {
|
|
178
193
|
console.log(payload);
|
|
179
|
-
if (!this.
|
|
194
|
+
if (!this.accessToken) {
|
|
180
195
|
await this.login();
|
|
181
196
|
}
|
|
182
197
|
try {
|
|
@@ -184,7 +199,7 @@ class Tropipay {
|
|
|
184
199
|
headers: {
|
|
185
200
|
'Content-Type': 'application/json',
|
|
186
201
|
Accept: 'application/json',
|
|
187
|
-
Authorization: `Bearer ${this.
|
|
202
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
188
203
|
} });
|
|
189
204
|
return rates.data;
|
|
190
205
|
}
|
package/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Tropipayjs is a
|
|
3
|
-
*
|
|
4
|
-
* @author Yosleivy
|
|
2
|
+
* Tropipayjs is a Typescript/Javascript library for the Tropipay API. CommonJs and
|
|
3
|
+
* ES6 modules are supported.
|
|
4
|
+
* @author Yosleivy Baez Acosta
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
|
|
@@ -13,29 +13,29 @@ type ServerMode = 'Development' | 'Production'
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
export class Tropipay {
|
|
16
|
-
readonly
|
|
17
|
-
readonly
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
readonly clientId: string;
|
|
17
|
+
readonly clientSecret: string;
|
|
18
|
+
protected request: Axios;
|
|
19
|
+
protected accessToken: string | undefined;
|
|
20
|
+
protected refreshToken: string | undefined;
|
|
21
|
+
protected serverMode: ServerMode;
|
|
22
22
|
|
|
23
23
|
constructor(
|
|
24
24
|
client_id: string,
|
|
25
25
|
client_secret: string,
|
|
26
26
|
server_mode: ServerMode = 'Development') {
|
|
27
|
-
this.
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
27
|
+
this.clientId = client_id;
|
|
28
|
+
this.clientSecret = client_secret
|
|
29
|
+
this.serverMode = server_mode
|
|
30
30
|
|
|
31
31
|
this.request = axios.create({
|
|
32
|
-
baseURL: this.
|
|
32
|
+
baseURL: this.serverMode === 'Production'
|
|
33
33
|
? 'https://www.tropipay.com'
|
|
34
34
|
: 'https://tropipay-dev.herokuapp.com',
|
|
35
35
|
headers: {
|
|
36
36
|
'Content-Type': 'application/json',
|
|
37
37
|
Accept: 'application/json',
|
|
38
|
-
Authorization: `Bearer ${this.
|
|
38
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
39
39
|
|
|
40
40
|
}
|
|
41
41
|
})
|
|
@@ -45,8 +45,8 @@ export class Tropipay {
|
|
|
45
45
|
async login() {
|
|
46
46
|
try {
|
|
47
47
|
const { data } = await this.request.post<LoginResponse>('/api/v2/access/token', {
|
|
48
|
-
client_id: this.
|
|
49
|
-
client_secret: this.
|
|
48
|
+
client_id: this.clientId,
|
|
49
|
+
client_secret: this.clientSecret,
|
|
50
50
|
grant_type: "client_credentials",
|
|
51
51
|
scope: "ALLOW_GET_PROFILE_DATA ALLOW_PAYMENT_IN ALLOW_EXTERNAL_CHARGE KYC3_FULL_ALLOW ALLOW_PAYMENT_OUT ALLOW_MARKET_PURCHASES ALLOW_GET_BALANCE ALLOW_GET_MOVEMENT_LIST ALLOW_GET_CREDENTIAL "
|
|
52
52
|
}, {
|
|
@@ -56,8 +56,8 @@ export class Tropipay {
|
|
|
56
56
|
// }
|
|
57
57
|
})
|
|
58
58
|
|
|
59
|
-
this.
|
|
60
|
-
this.
|
|
59
|
+
this.accessToken = data.access_token
|
|
60
|
+
this.refreshToken = data.refresh_token
|
|
61
61
|
return data
|
|
62
62
|
} catch (error) {
|
|
63
63
|
if (axios.isAxiosError(error)) {
|
|
@@ -70,26 +70,26 @@ export class Tropipay {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
|
-
* Create a paymentLink
|
|
74
|
-
* @param payload
|
|
75
|
-
* @returns Promise<PaymentLink> or
|
|
73
|
+
* Create a paymentLink with the specified options.
|
|
74
|
+
* @param payload PaymentLinkPayload Object.
|
|
75
|
+
* @returns Promise<PaymentLink> or throws an Exception.
|
|
76
76
|
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
77
77
|
*/
|
|
78
78
|
async createPayLink(payload: PaymentLinkPayload): Promise<PaymentLink> {
|
|
79
|
-
if (!this.
|
|
79
|
+
if (!this.accessToken) {
|
|
80
80
|
await this.login()
|
|
81
81
|
}
|
|
82
82
|
try {
|
|
83
83
|
const paylink = await this.request.post('/api/v2/paymentcards', payload, {
|
|
84
84
|
headers: {
|
|
85
85
|
// 'Content-Type': 'application/json',
|
|
86
|
-
Authorization: `Bearer ${this.
|
|
86
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
87
87
|
// Accept: 'application/json'
|
|
88
88
|
}
|
|
89
89
|
})
|
|
90
90
|
return paylink.data as PaymentLink
|
|
91
91
|
} catch (error) {
|
|
92
|
-
throw new Error(`
|
|
92
|
+
throw new Error(`Could not obtain the access tokemn with the given credentials.`);
|
|
93
93
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
@@ -100,7 +100,7 @@ export class Tropipay {
|
|
|
100
100
|
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6OTgyOTQ1Mg-get-deposit-accounts-list
|
|
101
101
|
*/
|
|
102
102
|
async getDepositAccounts(): Promise<AccountDeposits[] | Error>{
|
|
103
|
-
if (!this.
|
|
103
|
+
if (!this.accessToken) {
|
|
104
104
|
await this.login()
|
|
105
105
|
}
|
|
106
106
|
try {
|
|
@@ -113,45 +113,62 @@ export class Tropipay {
|
|
|
113
113
|
|
|
114
114
|
/**
|
|
115
115
|
* Get the list of all supported countries by Tropipay.
|
|
116
|
-
* @returns Array of Countries
|
|
117
|
-
* @see
|
|
116
|
+
* @returns Array of Countries Data
|
|
117
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/bfac21259e2ff-getting-users-countries-list
|
|
118
118
|
*/
|
|
119
|
-
async countries(): Promise<Country[]
|
|
120
|
-
|
|
121
|
-
await this.login()
|
|
122
|
-
}
|
|
119
|
+
async countries(): Promise<Country[] > {
|
|
120
|
+
|
|
123
121
|
try {
|
|
124
|
-
const countries = await this.request.get('/api/countries')
|
|
125
|
-
return countries.data
|
|
122
|
+
const countries = await this.request.get('/api/v2/countries')
|
|
123
|
+
return countries.data
|
|
126
124
|
} catch (error) {
|
|
127
125
|
throw new Error(`Could not retrieve the countries list`);
|
|
128
126
|
}
|
|
129
127
|
}
|
|
130
128
|
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Get the list of all detination countries supported by Tropipay.
|
|
132
|
+
* Obtaining the list of valid countries to send funds to. Useful
|
|
133
|
+
* when adding new beneficiaries to some user.
|
|
134
|
+
*
|
|
135
|
+
* @returns Array of Country Objects
|
|
136
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/3cfe5504f0524-getting-list-of-beneficiary-countries
|
|
137
|
+
*/
|
|
138
|
+
async destinations(): Promise<Country[]> {
|
|
139
|
+
try {
|
|
140
|
+
const countries = await this.request.get('/api/v2/countries/destinations')
|
|
141
|
+
return countries.data
|
|
142
|
+
} catch (error) {
|
|
143
|
+
throw new Error(`Could not retrieve the destination countries list`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
131
147
|
/**
|
|
132
|
-
* Get list of all the favorites accounts.
|
|
148
|
+
* Get list of all the favorites accounts. This endpoint is not documented
|
|
149
|
+
* in the official Tropipay documentation.
|
|
133
150
|
* @returns
|
|
134
|
-
* @see
|
|
135
151
|
*/
|
|
136
152
|
async favorites(){
|
|
137
|
-
if (!this.
|
|
153
|
+
if (!this.accessToken) {
|
|
138
154
|
await this.login()
|
|
139
155
|
}
|
|
140
156
|
try {
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
157
|
+
const favoritesList = await this.request.get('/api/v2/paymentcards/favorites')
|
|
158
|
+
console.log(favoritesList)
|
|
159
|
+
return favoritesList.data
|
|
160
|
+
} catch (error) {
|
|
161
|
+
throw new Error(`Could not retrieve favorites list ${error}`);
|
|
145
162
|
}
|
|
146
163
|
}
|
|
147
164
|
|
|
148
165
|
/**
|
|
149
|
-
* List all movements
|
|
150
|
-
*
|
|
166
|
+
* List all account movements. You can optionaly specify
|
|
167
|
+
* offset and limit params for pagination.
|
|
151
168
|
* @returns
|
|
152
169
|
*/
|
|
153
170
|
async movements(offset = 0 , limit = 10){
|
|
154
|
-
if (!this.
|
|
171
|
+
if (!this.accessToken) {
|
|
155
172
|
await this.login()
|
|
156
173
|
}
|
|
157
174
|
try {
|
|
@@ -160,7 +177,7 @@ export class Tropipay {
|
|
|
160
177
|
headers: {
|
|
161
178
|
'Content-Type': 'application/json',
|
|
162
179
|
Accept: 'application/json',
|
|
163
|
-
Authorization: `Bearer ${this.
|
|
180
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
164
181
|
|
|
165
182
|
} })
|
|
166
183
|
return movements.data
|
|
@@ -175,7 +192,7 @@ export class Tropipay {
|
|
|
175
192
|
* @returns
|
|
176
193
|
*/
|
|
177
194
|
async profile(){
|
|
178
|
-
if (!this.
|
|
195
|
+
if (!this.accessToken) {
|
|
179
196
|
await this.login()
|
|
180
197
|
}
|
|
181
198
|
try {
|
|
@@ -188,7 +205,7 @@ export class Tropipay {
|
|
|
188
205
|
|
|
189
206
|
async getRates(payload = {currencyFrom: "EUR"}) {
|
|
190
207
|
console.log(payload)
|
|
191
|
-
if (!this.
|
|
208
|
+
if (!this.accessToken) {
|
|
192
209
|
await this.login()
|
|
193
210
|
}
|
|
194
211
|
try {
|
|
@@ -196,7 +213,7 @@ export class Tropipay {
|
|
|
196
213
|
headers: {
|
|
197
214
|
'Content-Type': 'application/json',
|
|
198
215
|
Accept: 'application/json',
|
|
199
|
-
Authorization: `Bearer ${this.
|
|
216
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
200
217
|
|
|
201
218
|
} })
|
|
202
219
|
return rates.data
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yosle/tropipayjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Javascript / Typescript SDK for the Tropipay API",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -34,5 +34,9 @@
|
|
|
34
34
|
"rollup": "^2.79.1",
|
|
35
35
|
"rollup-plugin-dts": "^4.2.2",
|
|
36
36
|
"run-s": "^0.0.0"
|
|
37
|
+
},
|
|
38
|
+
"funding": {
|
|
39
|
+
"type": "individual",
|
|
40
|
+
"url": "https://tppay.me/l94qaa3h"
|
|
37
41
|
}
|
|
38
42
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tropipayjs is a wrapper for the Tropipay API. It was made in
|
|
3
|
-
* typescript but you can use Javascript.
|
|
4
|
-
* @author Yosleivy baez Acosta
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
|
-
import { Axios } from "axios";
|
|
8
|
-
import { PaymentLink, PaymentLinkPayload } from './interfaces/paymentlink';
|
|
9
|
-
declare type ServerMode = 'Development' | 'Production';
|
|
10
|
-
export declare class Tropipay {
|
|
11
|
-
readonly client_id: string;
|
|
12
|
-
readonly client_secret: string;
|
|
13
|
-
request: Axios;
|
|
14
|
-
access_token: string | undefined;
|
|
15
|
-
refresh_token: string | undefined;
|
|
16
|
-
server_mode: ServerMode;
|
|
17
|
-
constructor(client_id: string, client_secret: string, server_mode?: ServerMode);
|
|
18
|
-
login(): Promise<LoginResponse>;
|
|
19
|
-
/**
|
|
20
|
-
* Create a paymentLink width the specifued payload
|
|
21
|
-
* @param payload Object of PaymentLinkPayload type with paylink payload
|
|
22
|
-
* @returns Promise<PaymentLink> or Error
|
|
23
|
-
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
24
|
-
*/
|
|
25
|
-
createPayLink(payload: PaymentLinkPayload): Promise<PaymentLink>;
|
|
26
|
-
/**
|
|
27
|
-
* Get all deposits in this account.
|
|
28
|
-
* @returns A Promise of an Array of AccountDeposits or throws an Exception
|
|
29
|
-
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6OTgyOTQ1Mg-get-deposit-accounts-list
|
|
30
|
-
*/
|
|
31
|
-
getDepositAccounts(): Promise<AccountDeposits[] | Error>;
|
|
32
|
-
/**
|
|
33
|
-
* Get the list of all supported countries by Tropipay.
|
|
34
|
-
* @returns Array of Countries
|
|
35
|
-
* @see
|
|
36
|
-
*/
|
|
37
|
-
countries(): Promise<Country[] | Error>;
|
|
38
|
-
/**
|
|
39
|
-
* Get list of all the favorites accounts.
|
|
40
|
-
* @returns
|
|
41
|
-
* @see
|
|
42
|
-
*/
|
|
43
|
-
favorites(): Promise<any>;
|
|
44
|
-
/**
|
|
45
|
-
* List all movements in current account. You can optionaly specify
|
|
46
|
-
* offset and limit params for pagination.
|
|
47
|
-
* @returns
|
|
48
|
-
*/
|
|
49
|
-
movements(offset?: number, limit?: number): Promise<any>;
|
|
50
|
-
/**
|
|
51
|
-
* Return profile data for this account.
|
|
52
|
-
* @returns
|
|
53
|
-
*/
|
|
54
|
-
profile(): Promise<any>;
|
|
55
|
-
getRates(payload?: {
|
|
56
|
-
currencyFrom: string;
|
|
57
|
-
}): Promise<any>;
|
|
58
|
-
}
|
|
59
|
-
export {};
|
package/dist/index.js
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tropipayjs is a wrapper for the Tropipay API. It was made in
|
|
3
|
-
* typescript but you can use Javascript.
|
|
4
|
-
* @author Yosleivy baez Acosta
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
|
-
import axios from "axios";
|
|
8
|
-
export class Tropipay {
|
|
9
|
-
client_id;
|
|
10
|
-
client_secret;
|
|
11
|
-
request;
|
|
12
|
-
access_token;
|
|
13
|
-
refresh_token;
|
|
14
|
-
server_mode;
|
|
15
|
-
constructor(client_id, client_secret, server_mode = 'Development') {
|
|
16
|
-
this.client_id = client_id;
|
|
17
|
-
this.client_secret = client_secret;
|
|
18
|
-
this.server_mode = server_mode;
|
|
19
|
-
this.request = axios.create({
|
|
20
|
-
baseURL: this.server_mode === 'Production'
|
|
21
|
-
? 'https://www.tropipay.com'
|
|
22
|
-
: 'https://tropipay-dev.herokuapp.com',
|
|
23
|
-
headers: {
|
|
24
|
-
'Content-Type': 'application/json',
|
|
25
|
-
Accept: 'application/json',
|
|
26
|
-
Authorization: `Bearer ${this.access_token}`,
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
async login() {
|
|
31
|
-
try {
|
|
32
|
-
const { data } = await this.request.post('/api/v2/access/token', {
|
|
33
|
-
client_id: this.client_id,
|
|
34
|
-
client_secret: this.client_secret,
|
|
35
|
-
grant_type: "client_credentials",
|
|
36
|
-
scope: "ALLOW_GET_PROFILE_DATA ALLOW_PAYMENT_IN ALLOW_EXTERNAL_CHARGE KYC3_FULL_ALLOW ALLOW_PAYMENT_OUT ALLOW_MARKET_PURCHASES ALLOW_GET_BALANCE ALLOW_GET_MOVEMENT_LIST ALLOW_GET_CREDENTIAL "
|
|
37
|
-
}, {
|
|
38
|
-
// headers: {
|
|
39
|
-
// 'Content-Type': 'application/json',
|
|
40
|
-
// Accept: 'application/json',
|
|
41
|
-
// }
|
|
42
|
-
});
|
|
43
|
-
this.access_token = data.access_token;
|
|
44
|
-
this.refresh_token = data.refresh_token;
|
|
45
|
-
return data;
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
if (axios.isAxiosError(error)) {
|
|
49
|
-
// 👇️ error: AxiosError<any, any>
|
|
50
|
-
throw new Error("Conection error: " + error.message);
|
|
51
|
-
}
|
|
52
|
-
throw new Error("Could not obtain the access token from credentials ");
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Create a paymentLink width the specifued payload
|
|
57
|
-
* @param payload Object of PaymentLinkPayload type with paylink payload
|
|
58
|
-
* @returns Promise<PaymentLink> or Error
|
|
59
|
-
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
60
|
-
*/
|
|
61
|
-
async createPayLink(payload) {
|
|
62
|
-
if (!this.access_token) {
|
|
63
|
-
await this.login();
|
|
64
|
-
}
|
|
65
|
-
try {
|
|
66
|
-
const paylink = await this.request.post('/api/v2/paymentcards', payload, {
|
|
67
|
-
headers: {
|
|
68
|
-
// 'Content-Type': 'application/json',
|
|
69
|
-
Authorization: `Bearer ${this.access_token}`,
|
|
70
|
-
// Accept: 'application/json'
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
return paylink.data;
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
throw new Error(`Error tryng to get the access token`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Get all deposits in this account.
|
|
81
|
-
* @returns A Promise of an Array of AccountDeposits or throws an Exception
|
|
82
|
-
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6OTgyOTQ1Mg-get-deposit-accounts-list
|
|
83
|
-
*/
|
|
84
|
-
async getDepositAccounts() {
|
|
85
|
-
if (!this.access_token) {
|
|
86
|
-
await this.login();
|
|
87
|
-
}
|
|
88
|
-
try {
|
|
89
|
-
const deposits = await this.request.get('/api/v2/deposit_accounts', {});
|
|
90
|
-
return deposits.data;
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
throw new Error(`Could not retrieve the account deposits ${error}`);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Get the list of all supported countries by Tropipay.
|
|
98
|
-
* @returns Array of Countries
|
|
99
|
-
* @see
|
|
100
|
-
*/
|
|
101
|
-
async countries() {
|
|
102
|
-
if (!this.access_token) {
|
|
103
|
-
await this.login();
|
|
104
|
-
}
|
|
105
|
-
try {
|
|
106
|
-
const countries = await this.request.get('/api/countries');
|
|
107
|
-
return countries.data;
|
|
108
|
-
}
|
|
109
|
-
catch (error) {
|
|
110
|
-
throw new Error(`Could not retrieve the countries list`);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Get list of all the favorites accounts.
|
|
115
|
-
* @returns
|
|
116
|
-
* @see
|
|
117
|
-
*/
|
|
118
|
-
async favorites() {
|
|
119
|
-
if (!this.access_token) {
|
|
120
|
-
await this.login();
|
|
121
|
-
}
|
|
122
|
-
try {
|
|
123
|
-
const favorites = await this.request.get('/api/v2/paymentcards/favorites');
|
|
124
|
-
return favorites.data;
|
|
125
|
-
}
|
|
126
|
-
catch (error) {
|
|
127
|
-
throw new Error(`Could not retrieve favorites list`);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* List all movements in current account. You can optionaly specify
|
|
132
|
-
* offset and limit params for pagination.
|
|
133
|
-
* @returns
|
|
134
|
-
*/
|
|
135
|
-
async movements(offset = 0, limit = 10) {
|
|
136
|
-
if (!this.access_token) {
|
|
137
|
-
await this.login();
|
|
138
|
-
}
|
|
139
|
-
try {
|
|
140
|
-
const movements = await this.request.get('/api/v2/movements', { params: { limit: limit, offset: offset },
|
|
141
|
-
headers: {
|
|
142
|
-
'Content-Type': 'application/json',
|
|
143
|
-
Accept: 'application/json',
|
|
144
|
-
Authorization: `Bearer ${this.access_token}`,
|
|
145
|
-
} });
|
|
146
|
-
return movements.data;
|
|
147
|
-
}
|
|
148
|
-
catch (error) {
|
|
149
|
-
throw new Error(`Could not retrieve movements list`);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Return profile data for this account.
|
|
154
|
-
* @returns
|
|
155
|
-
*/
|
|
156
|
-
async profile() {
|
|
157
|
-
if (!this.access_token) {
|
|
158
|
-
await this.login();
|
|
159
|
-
}
|
|
160
|
-
try {
|
|
161
|
-
const profile = await this.request.get('/api/users/profile');
|
|
162
|
-
return profile.data;
|
|
163
|
-
}
|
|
164
|
-
catch (error) {
|
|
165
|
-
throw new Error(`Could not retrieve movements list ${error}`);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
async getRates(payload = { currencyFrom: "EUR" }) {
|
|
169
|
-
console.log(payload);
|
|
170
|
-
if (!this.access_token) {
|
|
171
|
-
await this.login();
|
|
172
|
-
}
|
|
173
|
-
try {
|
|
174
|
-
const rates = await this.request.post('/api/v2/movements/get_rate', { payload,
|
|
175
|
-
headers: {
|
|
176
|
-
'Content-Type': 'application/json',
|
|
177
|
-
Accept: 'application/json',
|
|
178
|
-
Authorization: `Bearer ${this.access_token}`,
|
|
179
|
-
} });
|
|
180
|
-
return rates.data;
|
|
181
|
-
}
|
|
182
|
-
catch (error) {
|
|
183
|
-
throw new Error(`Could not retrieve rates ${error}`);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
//# sourceMappingURL=index.js.map
|
|
File without changes
|
|
File without changes
|
package/dist/interfaces/index.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export interface PaymentLinkPayload {
|
|
2
|
-
reference: string;
|
|
3
|
-
concept: string;
|
|
4
|
-
favorite: boolean;
|
|
5
|
-
amount: number;
|
|
6
|
-
currency: string;
|
|
7
|
-
description: string;
|
|
8
|
-
singleUse: boolean;
|
|
9
|
-
reasonId: number;
|
|
10
|
-
expirationDays: number;
|
|
11
|
-
lang: string;
|
|
12
|
-
urlSuccess: string;
|
|
13
|
-
urlFailed: string;
|
|
14
|
-
urlNotification: string;
|
|
15
|
-
serviceDate: string;
|
|
16
|
-
client: {
|
|
17
|
-
name: string;
|
|
18
|
-
lastName: string;
|
|
19
|
-
address: string;
|
|
20
|
-
phone: string;
|
|
21
|
-
email: string;
|
|
22
|
-
countryId: number;
|
|
23
|
-
termsAndConditions: boolean;
|
|
24
|
-
};
|
|
25
|
-
directPayment: boolean;
|
|
26
|
-
paymentMethods?: string[];
|
|
27
|
-
}
|
|
28
|
-
export interface PaymentLink extends PaymentLinkPayload {
|
|
29
|
-
expirationDate: string;
|
|
30
|
-
hasClient: boolean;
|
|
31
|
-
updatedAt: string;
|
|
32
|
-
createdAt: string;
|
|
33
|
-
qrImage: string;
|
|
34
|
-
shortUrl: string;
|
|
35
|
-
paymentUrl: string;
|
|
36
|
-
}
|