@yosle/tropipayjs 0.1.4 → 0.1.6
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 +10 -0
- package/README.md +99 -12
- package/docs/README.MD +4 -0
- package/docs/images/app-credentials-menu.png +0 -0
- package/docs/images/confirmation-code-screen.png +0 -0
- package/index.d.ts +29 -20
- package/index.js +60 -46
- package/package.json +6 -2
- package/src/globals.d.ts +74 -0
- package/{index.ts → src/index.ts} +67 -51
- package/{dist → src}/interfaces/countries/index.d.ts +0 -0
- package/{dist → src}/interfaces/countries/index.js +0 -0
- package/{interfaces → src/interfaces}/countries/index.ts +0 -0
- package/{dist → src}/interfaces/index.d.ts +0 -0
- package/{dist → src}/interfaces/index.js +0 -0
- package/{interfaces → src/interfaces}/index.ts +0 -0
- package/{dist → src}/interfaces/paymentlink/index.d.ts +0 -0
- package/{interfaces → src/interfaces}/paymentlink/index.js +0 -0
- package/{interfaces → src/interfaces}/paymentlink/index.ts +0 -0
- package/{interfaces → src/interfaces}/paymentlink.js +0 -0
- package/tsconfig.json +2 -2
- package/dist/index.d.ts +0 -59
- package/dist/index.js +0 -187
- package/dist/interfaces/paymentlink/index.js +0 -2
- package/interfaces/countries/index.d.ts +0 -0
- package/interfaces/countries/index.js +0 -2
- package/interfaces/index.d.ts +0 -0
- package/interfaces/index.js +0 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Yosleivy Baez Acosta.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
|
6
|
+
furnished to do so, subject to the following conditions:
|
|
7
|
+
|
|
8
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
9
|
+
|
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,27 +1,114 @@
|
|
|
1
|
-
TropipayJS -
|
|
1
|
+
TropipayJS - Typescript/Javascript SDK for Tropipay Payments API
|
|
2
2
|
===========
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
3
8
|
|
|
4
|
-
TropiPay is an electronic wallet that allows you to execute the most common financial operations of the day to day. This is
|
|
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).
|
|
5
10
|
|
|
6
|
-
|
|
11
|
+
|
|
12
|
+
# Table of Contents
|
|
13
|
+
- [TropipayJS - Typescript/Javascript SDK for Tropipay Payments API](#tropipayjs---typescriptjavascript-sdk-for-tropipay-payments-api)
|
|
14
|
+
- [Table of Contents](#table-of-contents)
|
|
15
|
+
- [About the project](#about-the-project)
|
|
16
|
+
- [Getting started](#getting-started)
|
|
17
|
+
- [Setting up your app credentials](#setting-up-your-app-credentials)
|
|
18
|
+
- [Usage](#usage)
|
|
19
|
+
- [CommonJS](#commonjs)
|
|
20
|
+
- [ES6](#es6)
|
|
21
|
+
- [Initialize the Tropipay class](#initialize-the-tropipay-class)
|
|
22
|
+
- [Generating a Payment Link](#generating-a-payment-link)
|
|
23
|
+
- [Contributing](#contributing)
|
|
24
|
+
- [License](#license)
|
|
25
|
+
## About the project
|
|
26
|
+
This library is a community effort still under development so use caution if you're planing to use it in production. Tropipay may make some changes on the API Specification in the future. Use the [test environment](https://tropipay-dev.herokuapp.com) to make sure everything is working as expected.
|
|
27
|
+
# Getting started
|
|
7
28
|
You can use npm or yarn to install this package:
|
|
8
29
|
|
|
9
|
-
|
|
10
|
-
|
|
30
|
+
```npm install @yosle/tropipayjs```
|
|
31
|
+
|
|
32
|
+
or
|
|
33
|
+
|
|
34
|
+
```yarn add @yosle/tropipayjs```
|
|
35
|
+
|
|
36
|
+
## Setting up your app credentials
|
|
37
|
+
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
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.
|
|
11
42
|
|
|
12
|
-
|
|
43
|
+
## Usage
|
|
13
44
|
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.
|
|
14
45
|
|
|
15
|
-
|
|
16
|
-
|
|
46
|
+
### CommonJS
|
|
47
|
+
```javascript
|
|
48
|
+
const { Tropipay } = require('@yosle/tropipayjs')
|
|
49
|
+
```
|
|
50
|
+
### ES6
|
|
51
|
+
```javascript
|
|
52
|
+
import { Tropipay } from '@yosle/tropipayjs'
|
|
53
|
+
```
|
|
54
|
+
### Initialize the Tropipay class
|
|
55
|
+
```javascript
|
|
56
|
+
const tpp = new Tropipay("yourclientidhere",
|
|
57
|
+
"yourclientsecrethere")
|
|
58
|
+
```
|
|
59
|
+
### Generating a Payment Link
|
|
60
|
+
```javascript
|
|
61
|
+
/*
|
|
62
|
+
* Example Payload
|
|
63
|
+
*/
|
|
64
|
+
const payload = await tpp.createPayLink({
|
|
65
|
+
reference: "my-paylink-1",
|
|
66
|
+
concept: "Bicycle",
|
|
67
|
+
favorite: "true",
|
|
68
|
+
amount: 3000,
|
|
69
|
+
currency: "EUR",
|
|
70
|
+
description: "Two wheels",
|
|
71
|
+
singleUse: "true",
|
|
72
|
+
reasonId: 4,
|
|
73
|
+
expirationDays: 1,
|
|
74
|
+
lang: "es",
|
|
75
|
+
urlSuccess: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
|
|
76
|
+
urlFailed: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
|
|
77
|
+
urlNotification: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
|
|
78
|
+
serviceDate: "2021-08-20",
|
|
79
|
+
client: {
|
|
80
|
+
name: "John",
|
|
81
|
+
lastName: "McClane",
|
|
82
|
+
address: "Ave. Guadí 232, Barcelona, Barcelona",
|
|
83
|
+
phone: "+34645553333",
|
|
84
|
+
email: "client@email.com",
|
|
85
|
+
countryId: 1,
|
|
86
|
+
termsAndConditions: "true"
|
|
87
|
+
},
|
|
88
|
+
directPayment: "true"
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
// Use inside an async function
|
|
92
|
+
const paylink = await tpp.createPayLink(payload)
|
|
93
|
+
console.log(paylink.shortUrl)
|
|
94
|
+
```
|
|
17
95
|
|
|
18
|
-
|
|
96
|
+
For more examples, please refer to the [Documentation](https://github.com/yosle/tropipayjs/blob/master/docs/)
|
|
19
97
|
|
|
20
|
-
#
|
|
98
|
+
# Contributing
|
|
99
|
+
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
|
|
21
100
|
|
|
22
|
-
|
|
23
|
-
|
|
101
|
+
1. Fork the Project
|
|
102
|
+
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
|
|
103
|
+
3. Commit your Changes (`git commit -m 'Add some AmazingFeature`)
|
|
104
|
+
4. Push to the Branch (`git push origin feature/AmazingFeature`)
|
|
105
|
+
5. Open a Pull Request
|
|
106
|
+
|
|
107
|
+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
|
24
108
|
|
|
109
|
+
You can also make a small [donation to the author](https://tppay.me/l94qaa3h) of the library.
|
|
110
|
+
# License
|
|
111
|
+
Distributed under the MIT License. See `LICENSE.txt` for more information.
|
|
25
112
|
|
|
26
113
|
|
|
27
114
|
|
package/docs/README.MD
ADDED
|
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.
|
|
42
|
+
*
|
|
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
|
+
*/
|
|
75
|
+
countries(): Promise<Country[]>;
|
|
76
|
+
/**
|
|
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
|
|
74
83
|
*/
|
|
75
|
-
|
|
84
|
+
destinations(): Promise<Country[]>;
|
|
76
85
|
/**
|
|
77
|
-
* Get list of all the favorites accounts.
|
|
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>;
|
|
@@ -90,7 +99,7 @@ declare class Tropipay {
|
|
|
90
99
|
* @returns
|
|
91
100
|
*/
|
|
92
101
|
profile(): Promise<any>;
|
|
93
|
-
|
|
102
|
+
rates(payload?: {
|
|
94
103
|
currencyFrom: string;
|
|
95
104
|
}): Promise<any>;
|
|
96
105
|
}
|
package/index.js
CHANGED
|
@@ -9,80 +9,79 @@ 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.
|
|
13
|
+
*
|
|
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
|
-
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
|
|
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
|
}, {
|
|
47
47
|
// headers: {
|
|
48
48
|
// 'Content-Type': 'application/json',
|
|
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) {
|
|
57
57
|
if (axios__default["default"].isAxiosError(error)) {
|
|
58
|
-
// 👇️ error: AxiosError<any, any>
|
|
59
58
|
throw new Error("Conection error: " + error.message);
|
|
60
59
|
}
|
|
61
60
|
throw new Error("Could not obtain the access token from credentials ");
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
63
|
/**
|
|
65
|
-
* Create a paymentLink
|
|
66
|
-
* @param payload
|
|
67
|
-
* @returns Promise<PaymentLink> or
|
|
64
|
+
* Create a paymentLink with the specified options.
|
|
65
|
+
* @param payload PaymentLinkPayload Object.
|
|
66
|
+
* @returns Promise<PaymentLink> or throws an Exception.
|
|
68
67
|
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
69
68
|
*/
|
|
70
69
|
async createPayLink(payload) {
|
|
71
|
-
if (!this.
|
|
70
|
+
if (!this.accessToken) {
|
|
72
71
|
await this.login();
|
|
73
72
|
}
|
|
74
73
|
try {
|
|
75
74
|
const paylink = await this.request.post('/api/v2/paymentcards', payload, {
|
|
76
75
|
headers: {
|
|
77
76
|
// 'Content-Type': 'application/json',
|
|
78
|
-
Authorization: `Bearer ${this.
|
|
77
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
79
78
|
// Accept: 'application/json'
|
|
80
79
|
}
|
|
81
80
|
});
|
|
82
81
|
return paylink.data;
|
|
83
82
|
}
|
|
84
83
|
catch (error) {
|
|
85
|
-
throw new Error(`
|
|
84
|
+
throw new Error(`Could not obtain the access token with the given credentials.`);
|
|
86
85
|
}
|
|
87
86
|
}
|
|
88
87
|
/**
|
|
@@ -91,7 +90,7 @@ class Tropipay {
|
|
|
91
90
|
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6OTgyOTQ1Mg-get-deposit-accounts-list
|
|
92
91
|
*/
|
|
93
92
|
async getDepositAccounts() {
|
|
94
|
-
if (!this.
|
|
93
|
+
if (!this.accessToken) {
|
|
95
94
|
await this.login();
|
|
96
95
|
}
|
|
97
96
|
try {
|
|
@@ -104,15 +103,12 @@ class Tropipay {
|
|
|
104
103
|
}
|
|
105
104
|
/**
|
|
106
105
|
* Get the list of all supported countries by Tropipay.
|
|
107
|
-
* @returns Array of Countries
|
|
108
|
-
* @see
|
|
106
|
+
* @returns Array of Countries Data
|
|
107
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/bfac21259e2ff-getting-users-countries-list
|
|
109
108
|
*/
|
|
110
109
|
async countries() {
|
|
111
|
-
if (!this.access_token) {
|
|
112
|
-
await this.login();
|
|
113
|
-
}
|
|
114
110
|
try {
|
|
115
|
-
const countries = await this.request.get('/api/countries');
|
|
111
|
+
const countries = await this.request.get('/api/v2/countries');
|
|
116
112
|
return countries.data;
|
|
117
113
|
}
|
|
118
114
|
catch (error) {
|
|
@@ -120,29 +116,47 @@ class Tropipay {
|
|
|
120
116
|
}
|
|
121
117
|
}
|
|
122
118
|
/**
|
|
123
|
-
* Get list of all
|
|
119
|
+
* Get the list of all detination countries supported by Tropipay.
|
|
120
|
+
* Obtaining the list of valid countries to send funds to. Useful
|
|
121
|
+
* when adding new beneficiaries to some user.
|
|
122
|
+
*
|
|
123
|
+
* @returns Array of Country Objects
|
|
124
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/3cfe5504f0524-getting-list-of-beneficiary-countries
|
|
125
|
+
*/
|
|
126
|
+
async destinations() {
|
|
127
|
+
try {
|
|
128
|
+
const countries = await this.request.get('/api/v2/countries/destinations');
|
|
129
|
+
return countries.data;
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
throw new Error(`Could not retrieve the destination countries list`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get list of all the favorites accounts. This endpoint is not documented
|
|
137
|
+
* in the official Tropipay documentation.
|
|
124
138
|
* @returns
|
|
125
|
-
* @see
|
|
126
139
|
*/
|
|
127
140
|
async favorites() {
|
|
128
|
-
if (!this.
|
|
141
|
+
if (!this.accessToken) {
|
|
129
142
|
await this.login();
|
|
130
143
|
}
|
|
131
144
|
try {
|
|
132
|
-
const
|
|
133
|
-
|
|
145
|
+
const favoritesList = await this.request.get('/api/v2/paymentcards/favorites');
|
|
146
|
+
console.log(favoritesList);
|
|
147
|
+
return favoritesList.data;
|
|
134
148
|
}
|
|
135
149
|
catch (error) {
|
|
136
|
-
throw new Error(`Could not retrieve favorites list`);
|
|
150
|
+
throw new Error(`Could not retrieve favorites list ${error}`);
|
|
137
151
|
}
|
|
138
152
|
}
|
|
139
153
|
/**
|
|
140
|
-
* List all movements
|
|
141
|
-
*
|
|
154
|
+
* List all account movements. You can optionaly specify
|
|
155
|
+
* offset and limit params for pagination.
|
|
142
156
|
* @returns
|
|
143
157
|
*/
|
|
144
158
|
async movements(offset = 0, limit = 10) {
|
|
145
|
-
if (!this.
|
|
159
|
+
if (!this.accessToken) {
|
|
146
160
|
await this.login();
|
|
147
161
|
}
|
|
148
162
|
try {
|
|
@@ -150,7 +164,7 @@ class Tropipay {
|
|
|
150
164
|
headers: {
|
|
151
165
|
'Content-Type': 'application/json',
|
|
152
166
|
Accept: 'application/json',
|
|
153
|
-
Authorization: `Bearer ${this.
|
|
167
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
154
168
|
} });
|
|
155
169
|
return movements.data;
|
|
156
170
|
}
|
|
@@ -163,7 +177,7 @@ class Tropipay {
|
|
|
163
177
|
* @returns
|
|
164
178
|
*/
|
|
165
179
|
async profile() {
|
|
166
|
-
if (!this.
|
|
180
|
+
if (!this.accessToken) {
|
|
167
181
|
await this.login();
|
|
168
182
|
}
|
|
169
183
|
try {
|
|
@@ -174,9 +188,9 @@ class Tropipay {
|
|
|
174
188
|
throw new Error(`Could not retrieve movements list ${error}`);
|
|
175
189
|
}
|
|
176
190
|
}
|
|
177
|
-
async
|
|
191
|
+
async rates(payload = { currencyFrom: "EUR" }) {
|
|
178
192
|
console.log(payload);
|
|
179
|
-
if (!this.
|
|
193
|
+
if (!this.accessToken) {
|
|
180
194
|
await this.login();
|
|
181
195
|
}
|
|
182
196
|
try {
|
|
@@ -184,7 +198,7 @@ class Tropipay {
|
|
|
184
198
|
headers: {
|
|
185
199
|
'Content-Type': 'application/json',
|
|
186
200
|
Accept: 'application/json',
|
|
187
|
-
Authorization: `Bearer ${this.
|
|
201
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
188
202
|
} });
|
|
189
203
|
return rates.data;
|
|
190
204
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yosle/tropipayjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Javascript / Typescript SDK for the Tropipay API",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
-
"_clear": "rimraf
|
|
8
|
+
"_clear": "rimraf src/dist/*",
|
|
9
9
|
"_tsc": "tsc",
|
|
10
10
|
"_make-bundle": "rollup --config",
|
|
11
11
|
"build": "run-s _clear _tsc _make-bundle"
|
|
@@ -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/src/globals.d.ts
ADDED
|
@@ -0,0 +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[]
|
|
74
|
+
}
|
|
@@ -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.
|
|
3
|
+
*
|
|
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,10 +45,10 @@ 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
|
-
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
|
|
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
|
}, {
|
|
53
53
|
// headers: {
|
|
54
54
|
// 'Content-Type': 'application/json',
|
|
@@ -56,40 +56,39 @@ 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)) {
|
|
64
|
-
// 👇️ error: AxiosError<any, any>
|
|
65
64
|
throw new Error("Conection error: " + error.message);
|
|
66
|
-
|
|
65
|
+
}
|
|
67
66
|
throw new Error("Could not obtain the access token from credentials ");
|
|
68
67
|
|
|
69
68
|
}
|
|
70
69
|
}
|
|
71
70
|
|
|
72
71
|
/**
|
|
73
|
-
* Create a paymentLink
|
|
74
|
-
* @param payload
|
|
75
|
-
* @returns Promise<PaymentLink> or
|
|
72
|
+
* Create a paymentLink with the specified options.
|
|
73
|
+
* @param payload PaymentLinkPayload Object.
|
|
74
|
+
* @returns Promise<PaymentLink> or throws an Exception.
|
|
76
75
|
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
77
76
|
*/
|
|
78
77
|
async createPayLink(payload: PaymentLinkPayload): Promise<PaymentLink> {
|
|
79
|
-
if (!this.
|
|
78
|
+
if (!this.accessToken) {
|
|
80
79
|
await this.login()
|
|
81
80
|
}
|
|
82
81
|
try {
|
|
83
82
|
const paylink = await this.request.post('/api/v2/paymentcards', payload, {
|
|
84
83
|
headers: {
|
|
85
84
|
// 'Content-Type': 'application/json',
|
|
86
|
-
Authorization: `Bearer ${this.
|
|
85
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
87
86
|
// Accept: 'application/json'
|
|
88
87
|
}
|
|
89
88
|
})
|
|
90
89
|
return paylink.data as PaymentLink
|
|
91
90
|
} catch (error) {
|
|
92
|
-
throw new Error(`
|
|
91
|
+
throw new Error(`Could not obtain the access token with the given credentials.`);
|
|
93
92
|
|
|
94
93
|
}
|
|
95
94
|
}
|
|
@@ -100,7 +99,7 @@ export class Tropipay {
|
|
|
100
99
|
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6OTgyOTQ1Mg-get-deposit-accounts-list
|
|
101
100
|
*/
|
|
102
101
|
async getDepositAccounts(): Promise<AccountDeposits[] | Error>{
|
|
103
|
-
if (!this.
|
|
102
|
+
if (!this.accessToken) {
|
|
104
103
|
await this.login()
|
|
105
104
|
}
|
|
106
105
|
try {
|
|
@@ -113,45 +112,62 @@ export class Tropipay {
|
|
|
113
112
|
|
|
114
113
|
/**
|
|
115
114
|
* Get the list of all supported countries by Tropipay.
|
|
116
|
-
* @returns Array of Countries
|
|
117
|
-
* @see
|
|
115
|
+
* @returns Array of Countries Data
|
|
116
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/bfac21259e2ff-getting-users-countries-list
|
|
118
117
|
*/
|
|
119
|
-
async countries(): Promise<Country[]
|
|
120
|
-
|
|
121
|
-
await this.login()
|
|
122
|
-
}
|
|
118
|
+
async countries(): Promise<Country[] > {
|
|
119
|
+
|
|
123
120
|
try {
|
|
124
|
-
const countries = await this.request.get('/api/countries')
|
|
125
|
-
return countries.data
|
|
121
|
+
const countries = await this.request.get('/api/v2/countries')
|
|
122
|
+
return countries.data
|
|
126
123
|
} catch (error) {
|
|
127
124
|
throw new Error(`Could not retrieve the countries list`);
|
|
128
125
|
}
|
|
129
126
|
}
|
|
130
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
|
+
|
|
131
146
|
/**
|
|
132
|
-
* Get list of all the favorites accounts.
|
|
147
|
+
* Get list of all the favorites accounts. This endpoint is not documented
|
|
148
|
+
* in the official Tropipay documentation.
|
|
133
149
|
* @returns
|
|
134
|
-
* @see
|
|
135
150
|
*/
|
|
136
151
|
async favorites(){
|
|
137
|
-
if (!this.
|
|
152
|
+
if (!this.accessToken) {
|
|
138
153
|
await this.login()
|
|
139
154
|
}
|
|
140
155
|
try {
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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}`);
|
|
145
161
|
}
|
|
146
162
|
}
|
|
147
163
|
|
|
148
164
|
/**
|
|
149
|
-
* List all movements
|
|
150
|
-
*
|
|
165
|
+
* List all account movements. You can optionaly specify
|
|
166
|
+
* offset and limit params for pagination.
|
|
151
167
|
* @returns
|
|
152
168
|
*/
|
|
153
169
|
async movements(offset = 0 , limit = 10){
|
|
154
|
-
if (!this.
|
|
170
|
+
if (!this.accessToken) {
|
|
155
171
|
await this.login()
|
|
156
172
|
}
|
|
157
173
|
try {
|
|
@@ -160,7 +176,7 @@ export class Tropipay {
|
|
|
160
176
|
headers: {
|
|
161
177
|
'Content-Type': 'application/json',
|
|
162
178
|
Accept: 'application/json',
|
|
163
|
-
Authorization: `Bearer ${this.
|
|
179
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
164
180
|
|
|
165
181
|
} })
|
|
166
182
|
return movements.data
|
|
@@ -175,7 +191,7 @@ export class Tropipay {
|
|
|
175
191
|
* @returns
|
|
176
192
|
*/
|
|
177
193
|
async profile(){
|
|
178
|
-
if (!this.
|
|
194
|
+
if (!this.accessToken) {
|
|
179
195
|
await this.login()
|
|
180
196
|
}
|
|
181
197
|
try {
|
|
@@ -186,9 +202,9 @@ export class Tropipay {
|
|
|
186
202
|
}
|
|
187
203
|
}
|
|
188
204
|
|
|
189
|
-
async
|
|
205
|
+
async rates(payload = {currencyFrom: "EUR"}) {
|
|
190
206
|
console.log(payload)
|
|
191
|
-
if (!this.
|
|
207
|
+
if (!this.accessToken) {
|
|
192
208
|
await this.login()
|
|
193
209
|
}
|
|
194
210
|
try {
|
|
@@ -196,7 +212,7 @@ export class Tropipay {
|
|
|
196
212
|
headers: {
|
|
197
213
|
'Content-Type': 'application/json',
|
|
198
214
|
Accept: 'application/json',
|
|
199
|
-
Authorization: `Bearer ${this.
|
|
215
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
200
216
|
|
|
201
217
|
} })
|
|
202
218
|
return rates.data
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/tsconfig.json
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
24
24
|
/* Modules */
|
|
25
25
|
"module": "esnext", /* Specify what module code is generated. */
|
|
26
|
-
|
|
26
|
+
"rootDir": "./src", /* Specify the root folder within your source files. */
|
|
27
27
|
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
28
28
|
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
29
29
|
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
45
45
|
"sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
46
46
|
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
47
|
-
"outDir": "dist
|
|
47
|
+
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
|
48
48
|
"removeComments": false, /* Disable emitting comments. */
|
|
49
49
|
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
50
50
|
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
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
|
package/interfaces/index.d.ts
DELETED
|
File without changes
|
package/interfaces/index.js
DELETED