@yosle/tropipayjs 0.1.6 → 0.1.7
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/LICENSE +9 -9
- package/README.md +126 -115
- package/docs/README.MD +3 -3
- package/docs/images/intellisense-vs-code.png +0 -0
- package/globals.d.ts +73 -73
- package/index.d.ts +113 -107
- package/index.js +223 -212
- package/interfaces/countries/index.d.ts +1 -0
- package/interfaces/index.d.ts +2 -0
- package/interfaces/paymentlink/index.d.ts +36 -36
- package/package.json +41 -41
- package/rollup.config.js +22 -22
- package/src/globals.d.ts +73 -73
- package/src/index.ts +239 -229
- package/src/interfaces/countries/index.js +1 -1
- package/src/interfaces/countries/index.ts +3 -0
- package/src/interfaces/index.js +1 -1
- package/src/interfaces/index.ts +4 -0
- package/src/interfaces/paymentlink/index.d.ts +36 -36
- package/src/interfaces/paymentlink/index.js +2 -2
- package/src/interfaces/paymentlink/index.ts +39 -39
- package/src/interfaces/paymentlink.js +1 -1
- package/tsconfig.json +94 -94
package/src/globals.d.ts
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
type LoginResponse = {
|
|
2
|
-
access_token: string,
|
|
3
|
-
refresh_token: string
|
|
4
|
-
token_type: "Bearer",
|
|
5
|
-
expires_in: number,
|
|
6
|
-
scope: string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
type LoginError = {
|
|
10
|
-
error: string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
type Country = {
|
|
14
|
-
id: number,
|
|
15
|
-
name: string,
|
|
16
|
-
sepaZone: boolean,
|
|
17
|
-
state: number,
|
|
18
|
-
slug: string,
|
|
19
|
-
slugn: number,
|
|
20
|
-
callingCode: number,
|
|
21
|
-
isDestination: boolean,
|
|
22
|
-
isRisky: boolean,
|
|
23
|
-
currentCurrency: string | null,
|
|
24
|
-
createdAt: string,
|
|
25
|
-
updatedAt: string,
|
|
26
|
-
isFavorite: boolean,
|
|
27
|
-
position: any
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
type Deposit = {
|
|
32
|
-
id: number,
|
|
33
|
-
accountNumber: string,
|
|
34
|
-
alias: string,
|
|
35
|
-
swift: string,
|
|
36
|
-
type: number,
|
|
37
|
-
country: number | null,
|
|
38
|
-
firstName: string,
|
|
39
|
-
default: null,
|
|
40
|
-
state: number,
|
|
41
|
-
userId: string,
|
|
42
|
-
countryDestinationId: number,
|
|
43
|
-
lastName: string,
|
|
44
|
-
documentNumber: number,
|
|
45
|
-
userRelationTypeId: number,
|
|
46
|
-
city: string,
|
|
47
|
-
postalCode: string,
|
|
48
|
-
address: string,
|
|
49
|
-
phone: string,
|
|
50
|
-
checked: boolean,
|
|
51
|
-
province: string,
|
|
52
|
-
beneficiaryType: number,
|
|
53
|
-
relatedUserId: null | string,
|
|
54
|
-
currency: string,
|
|
55
|
-
correspondent?: any,
|
|
56
|
-
location: any,
|
|
57
|
-
office: any,
|
|
58
|
-
officeValue: any,
|
|
59
|
-
paymentType: number,
|
|
60
|
-
paymentEntityBeneficiaryId: number,
|
|
61
|
-
paymentEntityAccountId: number,
|
|
62
|
-
verified: any,
|
|
63
|
-
paymentEntityInfo: any,
|
|
64
|
-
documentTypeId: any,
|
|
65
|
-
documentExpirationDate: Date,
|
|
66
|
-
createdAt: Date<string>,
|
|
67
|
-
updatedAt: Date<string>,
|
|
68
|
-
countryDestination: Country
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
type AccountDeposits = {
|
|
72
|
-
count: number,
|
|
73
|
-
rows: Deposit[]
|
|
1
|
+
type LoginResponse = {
|
|
2
|
+
access_token: string,
|
|
3
|
+
refresh_token: string
|
|
4
|
+
token_type: "Bearer",
|
|
5
|
+
expires_in: number,
|
|
6
|
+
scope: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type LoginError = {
|
|
10
|
+
error: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type Country = {
|
|
14
|
+
id: number,
|
|
15
|
+
name: string,
|
|
16
|
+
sepaZone: boolean,
|
|
17
|
+
state: number,
|
|
18
|
+
slug: string,
|
|
19
|
+
slugn: number,
|
|
20
|
+
callingCode: number,
|
|
21
|
+
isDestination: boolean,
|
|
22
|
+
isRisky: boolean,
|
|
23
|
+
currentCurrency: string | null,
|
|
24
|
+
createdAt: string,
|
|
25
|
+
updatedAt: string,
|
|
26
|
+
isFavorite: boolean,
|
|
27
|
+
position: any
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type Deposit = {
|
|
32
|
+
id: number,
|
|
33
|
+
accountNumber: string,
|
|
34
|
+
alias: string,
|
|
35
|
+
swift: string,
|
|
36
|
+
type: number,
|
|
37
|
+
country: number | null,
|
|
38
|
+
firstName: string,
|
|
39
|
+
default: null,
|
|
40
|
+
state: number,
|
|
41
|
+
userId: string,
|
|
42
|
+
countryDestinationId: number,
|
|
43
|
+
lastName: string,
|
|
44
|
+
documentNumber: number,
|
|
45
|
+
userRelationTypeId: number,
|
|
46
|
+
city: string,
|
|
47
|
+
postalCode: string,
|
|
48
|
+
address: string,
|
|
49
|
+
phone: string,
|
|
50
|
+
checked: boolean,
|
|
51
|
+
province: string,
|
|
52
|
+
beneficiaryType: number,
|
|
53
|
+
relatedUserId: null | string,
|
|
54
|
+
currency: string,
|
|
55
|
+
correspondent?: any,
|
|
56
|
+
location: any,
|
|
57
|
+
office: any,
|
|
58
|
+
officeValue: any,
|
|
59
|
+
paymentType: number,
|
|
60
|
+
paymentEntityBeneficiaryId: number,
|
|
61
|
+
paymentEntityAccountId: number,
|
|
62
|
+
verified: any,
|
|
63
|
+
paymentEntityInfo: any,
|
|
64
|
+
documentTypeId: any,
|
|
65
|
+
documentExpirationDate: Date,
|
|
66
|
+
createdAt: Date<string>,
|
|
67
|
+
updatedAt: Date<string>,
|
|
68
|
+
countryDestination: Country
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
type AccountDeposits = {
|
|
72
|
+
count: number,
|
|
73
|
+
rows: Deposit[]
|
|
74
74
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,229 +1,239 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tropipayjs is a Typescript/Javascript library for the Tropipay API.
|
|
3
|
-
*
|
|
4
|
-
* @author Yosleivy Baez Acosta
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import axios, { Axios } from "axios";
|
|
9
|
-
import { PaymentLink, PaymentLinkPayload } from './interfaces/paymentlink'
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
type ServerMode = 'Development' | 'Production'
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export class Tropipay {
|
|
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
|
-
|
|
23
|
-
constructor(
|
|
24
|
-
client_id: string,
|
|
25
|
-
client_secret: string,
|
|
26
|
-
server_mode: ServerMode = 'Development') {
|
|
27
|
-
this.clientId = client_id;
|
|
28
|
-
this.clientSecret = client_secret
|
|
29
|
-
this.serverMode = server_mode
|
|
30
|
-
|
|
31
|
-
this.request = axios.create({
|
|
32
|
-
baseURL: this.serverMode === 'Production'
|
|
33
|
-
? 'https://www.tropipay.com'
|
|
34
|
-
: 'https://tropipay-dev.herokuapp.com',
|
|
35
|
-
headers: {
|
|
36
|
-
'Content-Type': 'application/json',
|
|
37
|
-
Accept: 'application/json',
|
|
38
|
-
Authorization: `Bearer ${this.accessToken}`,
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
async login() {
|
|
46
|
-
try {
|
|
47
|
-
const { data } = await this.request.post<LoginResponse>('/api/v2/access/token', {
|
|
48
|
-
client_id: this.clientId,
|
|
49
|
-
client_secret: this.clientSecret,
|
|
50
|
-
grant_type: "client_credentials",
|
|
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
|
-
}, {
|
|
53
|
-
// headers: {
|
|
54
|
-
// 'Content-Type': 'application/json',
|
|
55
|
-
// Accept: 'application/json',
|
|
56
|
-
// }
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
this.accessToken = data.access_token
|
|
60
|
-
this.refreshToken = data.refresh_token
|
|
61
|
-
return data
|
|
62
|
-
} catch (error) {
|
|
63
|
-
if (axios.isAxiosError(error)) {
|
|
64
|
-
throw new Error(
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Create a paymentLink with the specified options.
|
|
73
|
-
* @param payload PaymentLinkPayload Object.
|
|
74
|
-
* @returns Promise<PaymentLink> or throws an Exception.
|
|
75
|
-
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
76
|
-
*/
|
|
77
|
-
async createPayLink(payload: PaymentLinkPayload): Promise<PaymentLink> {
|
|
78
|
-
if (!this.accessToken) {
|
|
79
|
-
await this.login()
|
|
80
|
-
}
|
|
81
|
-
try {
|
|
82
|
-
const paylink = await this.request.post('/api/v2/paymentcards', payload, {
|
|
83
|
-
headers: {
|
|
84
|
-
// 'Content-Type': 'application/json',
|
|
85
|
-
Authorization: `Bearer ${this.accessToken}`,
|
|
86
|
-
// Accept: 'application/json'
|
|
87
|
-
}
|
|
88
|
-
})
|
|
89
|
-
return paylink.data as PaymentLink
|
|
90
|
-
} catch (error) {
|
|
91
|
-
throw new Error(`Could not obtain the access token with the given credentials.`);
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Get all deposits in this account.
|
|
98
|
-
* @returns A Promise of an Array of AccountDeposits or throws an Exception
|
|
99
|
-
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6OTgyOTQ1Mg-get-deposit-accounts-list
|
|
100
|
-
*/
|
|
101
|
-
async getDepositAccounts(): Promise<AccountDeposits[] | Error>{
|
|
102
|
-
if (!this.accessToken) {
|
|
103
|
-
await this.login()
|
|
104
|
-
}
|
|
105
|
-
try {
|
|
106
|
-
const deposits = await this.request.get('/api/v2/deposit_accounts',{ })
|
|
107
|
-
return deposits.data
|
|
108
|
-
} catch (error) {
|
|
109
|
-
throw new Error(`Could not retrieve the account deposits ${error}`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Get the list of all supported countries by Tropipay.
|
|
115
|
-
* @returns Array of Countries Data
|
|
116
|
-
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/bfac21259e2ff-getting-users-countries-list
|
|
117
|
-
*/
|
|
118
|
-
async countries(): Promise<Country[] > {
|
|
119
|
-
|
|
120
|
-
try {
|
|
121
|
-
const countries = await this.request.get('/api/v2/countries')
|
|
122
|
-
return countries.data
|
|
123
|
-
} catch (error) {
|
|
124
|
-
throw new Error(`Could not retrieve the countries list`);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Get the list of all detination countries supported by Tropipay.
|
|
131
|
-
* Obtaining the list of valid countries to send funds to. Useful
|
|
132
|
-
* when adding new beneficiaries to some user.
|
|
133
|
-
*
|
|
134
|
-
* @returns Array of Country Objects
|
|
135
|
-
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/3cfe5504f0524-getting-list-of-beneficiary-countries
|
|
136
|
-
*/
|
|
137
|
-
async destinations(): Promise<Country[]> {
|
|
138
|
-
try {
|
|
139
|
-
const countries = await this.request.get('/api/v2/countries/destinations')
|
|
140
|
-
return countries.data
|
|
141
|
-
} catch (error) {
|
|
142
|
-
throw new Error(`Could not retrieve the destination countries list`);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Get list of all the favorites accounts. This endpoint is not documented
|
|
148
|
-
* in the official Tropipay documentation.
|
|
149
|
-
* @returns
|
|
150
|
-
*/
|
|
151
|
-
async favorites(){
|
|
152
|
-
if (!this.accessToken) {
|
|
153
|
-
await this.login()
|
|
154
|
-
}
|
|
155
|
-
try {
|
|
156
|
-
const favoritesList = await this.request.get('/api/v2/paymentcards/favorites')
|
|
157
|
-
console.log(favoritesList)
|
|
158
|
-
return favoritesList.data
|
|
159
|
-
} catch (error) {
|
|
160
|
-
throw new Error(`Could not retrieve favorites list ${error}`);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* List all account movements. You can optionaly specify
|
|
166
|
-
* offset and limit params for pagination.
|
|
167
|
-
* @returns
|
|
168
|
-
*/
|
|
169
|
-
async movements(offset = 0 , limit = 10){
|
|
170
|
-
if (!this.accessToken) {
|
|
171
|
-
await this.login()
|
|
172
|
-
}
|
|
173
|
-
try {
|
|
174
|
-
const movements = await this.request.get('/api/v2/movements',
|
|
175
|
-
{params: {limit: limit, offset: offset},
|
|
176
|
-
headers: {
|
|
177
|
-
'Content-Type': 'application/json',
|
|
178
|
-
Accept: 'application/json',
|
|
179
|
-
Authorization: `Bearer ${this.accessToken}`,
|
|
180
|
-
|
|
181
|
-
} })
|
|
182
|
-
return movements.data
|
|
183
|
-
} catch (error) {
|
|
184
|
-
throw new Error(`Could not retrieve movements list`);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Return profile data for this account.
|
|
191
|
-
* @returns
|
|
192
|
-
*/
|
|
193
|
-
async profile(){
|
|
194
|
-
if (!this.accessToken) {
|
|
195
|
-
await this.login()
|
|
196
|
-
}
|
|
197
|
-
try {
|
|
198
|
-
const profile = await this.request.get('/api/users/profile')
|
|
199
|
-
return profile.data
|
|
200
|
-
} catch (error) {
|
|
201
|
-
throw new Error(`Could not retrieve movements list ${error}`);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Tropipayjs is a Typescript/Javascript library for the Tropipay API.
|
|
3
|
+
*
|
|
4
|
+
* @author Yosleivy Baez Acosta
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import axios, { Axios } from "axios";
|
|
9
|
+
import { PaymentLink, PaymentLinkPayload } from './interfaces/paymentlink'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
type ServerMode = 'Development' | 'Production'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export class Tropipay {
|
|
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
|
+
|
|
23
|
+
constructor(
|
|
24
|
+
client_id: string,
|
|
25
|
+
client_secret: string,
|
|
26
|
+
server_mode: ServerMode = 'Development') {
|
|
27
|
+
this.clientId = client_id;
|
|
28
|
+
this.clientSecret = client_secret
|
|
29
|
+
this.serverMode = server_mode
|
|
30
|
+
|
|
31
|
+
this.request = axios.create({
|
|
32
|
+
baseURL: this.serverMode === 'Production'
|
|
33
|
+
? 'https://www.tropipay.com'
|
|
34
|
+
: 'https://tropipay-dev.herokuapp.com',
|
|
35
|
+
headers: {
|
|
36
|
+
'Content-Type': 'application/json',
|
|
37
|
+
Accept: 'application/json',
|
|
38
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
async login() {
|
|
46
|
+
try {
|
|
47
|
+
const { data } = await this.request.post<LoginResponse>('/api/v2/access/token', {
|
|
48
|
+
client_id: this.clientId,
|
|
49
|
+
client_secret: this.clientSecret,
|
|
50
|
+
grant_type: "client_credentials",
|
|
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
|
+
}, {
|
|
53
|
+
// headers: {
|
|
54
|
+
// 'Content-Type': 'application/json',
|
|
55
|
+
// Accept: 'application/json',
|
|
56
|
+
// }
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
this.accessToken = data.access_token
|
|
60
|
+
this.refreshToken = data.refresh_token
|
|
61
|
+
return data
|
|
62
|
+
} catch (error) {
|
|
63
|
+
if (axios.isAxiosError(error)) {
|
|
64
|
+
throw new Error(`Could not obtain the access token from credentials ${error}`);
|
|
65
|
+
}
|
|
66
|
+
throw new Error(`Could not obtain the access token from credentials ${error}`);
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Create a paymentLink with the specified options.
|
|
73
|
+
* @param payload PaymentLinkPayload Object.
|
|
74
|
+
* @returns Promise<PaymentLink> or throws an Exception.
|
|
75
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
76
|
+
*/
|
|
77
|
+
async createPayLink(payload: PaymentLinkPayload): Promise<PaymentLink> {
|
|
78
|
+
if (!this.accessToken) {
|
|
79
|
+
await this.login()
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
const paylink = await this.request.post('/api/v2/paymentcards', payload, {
|
|
83
|
+
headers: {
|
|
84
|
+
// 'Content-Type': 'application/json',
|
|
85
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
86
|
+
// Accept: 'application/json'
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
return paylink.data as PaymentLink
|
|
90
|
+
} catch (error) {
|
|
91
|
+
throw new Error(`Could not obtain the access token with the given credentials.`);
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Get all deposits in this account.
|
|
98
|
+
* @returns A Promise of an Array of AccountDeposits or throws an Exception
|
|
99
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6OTgyOTQ1Mg-get-deposit-accounts-list
|
|
100
|
+
*/
|
|
101
|
+
async getDepositAccounts(): Promise<AccountDeposits[] | Error>{
|
|
102
|
+
if (!this.accessToken) {
|
|
103
|
+
await this.login()
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const deposits = await this.request.get('/api/v2/deposit_accounts',{ })
|
|
107
|
+
return deposits.data
|
|
108
|
+
} catch (error) {
|
|
109
|
+
throw new Error(`Could not retrieve the account deposits ${error}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Get the list of all supported countries by Tropipay.
|
|
115
|
+
* @returns Array of Countries Data
|
|
116
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/bfac21259e2ff-getting-users-countries-list
|
|
117
|
+
*/
|
|
118
|
+
async countries(): Promise<Country[] > {
|
|
119
|
+
|
|
120
|
+
try {
|
|
121
|
+
const countries = await this.request.get('/api/v2/countries')
|
|
122
|
+
return countries.data
|
|
123
|
+
} catch (error) {
|
|
124
|
+
throw new Error(`Could not retrieve the countries list`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Get the list of all detination countries supported by Tropipay.
|
|
131
|
+
* Obtaining the list of valid countries to send funds to. Useful
|
|
132
|
+
* when adding new beneficiaries to some user.
|
|
133
|
+
*
|
|
134
|
+
* @returns Array of Country Objects
|
|
135
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/3cfe5504f0524-getting-list-of-beneficiary-countries
|
|
136
|
+
*/
|
|
137
|
+
async destinations(): Promise<Country[]> {
|
|
138
|
+
try {
|
|
139
|
+
const countries = await this.request.get('/api/v2/countries/destinations')
|
|
140
|
+
return countries.data
|
|
141
|
+
} catch (error) {
|
|
142
|
+
throw new Error(`Could not retrieve the destination countries list`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Get list of all the favorites accounts. This endpoint is not documented
|
|
148
|
+
* in the official Tropipay documentation.
|
|
149
|
+
* @returns
|
|
150
|
+
*/
|
|
151
|
+
async favorites(){
|
|
152
|
+
if (!this.accessToken) {
|
|
153
|
+
await this.login()
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
const favoritesList = await this.request.get('/api/v2/paymentcards/favorites')
|
|
157
|
+
console.log(favoritesList)
|
|
158
|
+
return favoritesList.data
|
|
159
|
+
} catch (error) {
|
|
160
|
+
throw new Error(`Could not retrieve favorites list ${error}`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* List all account movements. You can optionaly specify
|
|
166
|
+
* offset and limit params for pagination.
|
|
167
|
+
* @returns
|
|
168
|
+
*/
|
|
169
|
+
async movements(offset = 0 , limit = 10){
|
|
170
|
+
if (!this.accessToken) {
|
|
171
|
+
await this.login()
|
|
172
|
+
}
|
|
173
|
+
try {
|
|
174
|
+
const movements = await this.request.get('/api/v2/movements',
|
|
175
|
+
{params: {limit: limit, offset: offset},
|
|
176
|
+
headers: {
|
|
177
|
+
'Content-Type': 'application/json',
|
|
178
|
+
Accept: 'application/json',
|
|
179
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
180
|
+
|
|
181
|
+
} })
|
|
182
|
+
return movements.data
|
|
183
|
+
} catch (error) {
|
|
184
|
+
throw new Error(`Could not retrieve movements list`);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Return profile data for this account.
|
|
191
|
+
* @returns
|
|
192
|
+
*/
|
|
193
|
+
async profile(){
|
|
194
|
+
if (!this.accessToken) {
|
|
195
|
+
await this.login()
|
|
196
|
+
}
|
|
197
|
+
try {
|
|
198
|
+
const profile = await this.request.get('/api/users/profile')
|
|
199
|
+
return profile.data
|
|
200
|
+
} catch (error) {
|
|
201
|
+
throw new Error(`Could not retrieve movements list ${error}`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Obtain current Tropipay conversion rate. For example USD to EUR
|
|
206
|
+
* targetCurrency must be 'EUR'
|
|
207
|
+
* @param originCurrency Target currency code supported by Tropipay.
|
|
208
|
+
* @param targetCurrency Must be 'EUR'? (not documented by Tropipay)
|
|
209
|
+
* @returns Conversion rate (number)
|
|
210
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/85163f6f28b23-get-rate
|
|
211
|
+
*/
|
|
212
|
+
async rates(originCurrency: string , targetCurrency: string = 'EUR'): Promise<number | Error> {
|
|
213
|
+
if (!this.accessToken) {
|
|
214
|
+
await this.login()
|
|
215
|
+
}
|
|
216
|
+
try {
|
|
217
|
+
const rates = await this.request.post('/api/v2/movements/get_rate',
|
|
218
|
+
{
|
|
219
|
+
currencyFrom: originCurrency,
|
|
220
|
+
currencyTo: targetCurrency
|
|
221
|
+
},{
|
|
222
|
+
headers: {
|
|
223
|
+
'Content-Type': 'application/json',
|
|
224
|
+
Accept: 'application/json',
|
|
225
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
226
|
+
|
|
227
|
+
} })
|
|
228
|
+
return rates.data.rate
|
|
229
|
+
} catch (error) {
|
|
230
|
+
throw new Error(`Could not retrieve rates ${error}`);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/src/interfaces/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/src/interfaces/index.ts
CHANGED