@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/index.js CHANGED
@@ -1,212 +1,223 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var axios = require('axios');
6
-
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
-
9
- var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
10
-
11
- /**
12
- * Tropipayjs is a Typescript/Javascript library for the Tropipay API.
13
- *
14
- * @author Yosleivy Baez Acosta
15
- *
16
- */
17
- class Tropipay {
18
- clientId;
19
- clientSecret;
20
- request;
21
- accessToken;
22
- refreshToken;
23
- serverMode;
24
- constructor(client_id, client_secret, server_mode = 'Development') {
25
- this.clientId = client_id;
26
- this.clientSecret = client_secret;
27
- this.serverMode = server_mode;
28
- this.request = axios__default["default"].create({
29
- baseURL: this.serverMode === 'Production'
30
- ? 'https://www.tropipay.com'
31
- : 'https://tropipay-dev.herokuapp.com',
32
- headers: {
33
- 'Content-Type': 'application/json',
34
- Accept: 'application/json',
35
- Authorization: `Bearer ${this.accessToken}`,
36
- }
37
- });
38
- }
39
- async login() {
40
- try {
41
- const { data } = await this.request.post('/api/v2/access/token', {
42
- client_id: this.clientId,
43
- client_secret: this.clientSecret,
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"
46
- }, {
47
- // headers: {
48
- // 'Content-Type': 'application/json',
49
- // Accept: 'application/json',
50
- // }
51
- });
52
- this.accessToken = data.access_token;
53
- this.refreshToken = data.refresh_token;
54
- return data;
55
- }
56
- catch (error) {
57
- if (axios__default["default"].isAxiosError(error)) {
58
- throw new Error("Conection error: " + error.message);
59
- }
60
- throw new Error("Could not obtain the access token from credentials ");
61
- }
62
- }
63
- /**
64
- * Create a paymentLink with the specified options.
65
- * @param payload PaymentLinkPayload Object.
66
- * @returns Promise<PaymentLink> or throws an Exception.
67
- * @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
68
- */
69
- async createPayLink(payload) {
70
- if (!this.accessToken) {
71
- await this.login();
72
- }
73
- try {
74
- const paylink = await this.request.post('/api/v2/paymentcards', payload, {
75
- headers: {
76
- // 'Content-Type': 'application/json',
77
- Authorization: `Bearer ${this.accessToken}`,
78
- // Accept: 'application/json'
79
- }
80
- });
81
- return paylink.data;
82
- }
83
- catch (error) {
84
- throw new Error(`Could not obtain the access token with the given credentials.`);
85
- }
86
- }
87
- /**
88
- * Get all deposits in this account.
89
- * @returns A Promise of an Array of AccountDeposits or throws an Exception
90
- * @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6OTgyOTQ1Mg-get-deposit-accounts-list
91
- */
92
- async getDepositAccounts() {
93
- if (!this.accessToken) {
94
- await this.login();
95
- }
96
- try {
97
- const deposits = await this.request.get('/api/v2/deposit_accounts', {});
98
- return deposits.data;
99
- }
100
- catch (error) {
101
- throw new Error(`Could not retrieve the account deposits ${error}`);
102
- }
103
- }
104
- /**
105
- * Get the list of all supported countries by Tropipay.
106
- * @returns Array of Countries Data
107
- * @see https://tpp.stoplight.io/docs/tropipay-api-doc/bfac21259e2ff-getting-users-countries-list
108
- */
109
- async countries() {
110
- try {
111
- const countries = await this.request.get('/api/v2/countries');
112
- return countries.data;
113
- }
114
- catch (error) {
115
- throw new Error(`Could not retrieve the countries list`);
116
- }
117
- }
118
- /**
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.
138
- * @returns
139
- */
140
- async favorites() {
141
- if (!this.accessToken) {
142
- await this.login();
143
- }
144
- try {
145
- const favoritesList = await this.request.get('/api/v2/paymentcards/favorites');
146
- console.log(favoritesList);
147
- return favoritesList.data;
148
- }
149
- catch (error) {
150
- throw new Error(`Could not retrieve favorites list ${error}`);
151
- }
152
- }
153
- /**
154
- * List all account movements. You can optionaly specify
155
- * offset and limit params for pagination.
156
- * @returns
157
- */
158
- async movements(offset = 0, limit = 10) {
159
- if (!this.accessToken) {
160
- await this.login();
161
- }
162
- try {
163
- const movements = await this.request.get('/api/v2/movements', { params: { limit: limit, offset: offset },
164
- headers: {
165
- 'Content-Type': 'application/json',
166
- Accept: 'application/json',
167
- Authorization: `Bearer ${this.accessToken}`,
168
- } });
169
- return movements.data;
170
- }
171
- catch (error) {
172
- throw new Error(`Could not retrieve movements list`);
173
- }
174
- }
175
- /**
176
- * Return profile data for this account.
177
- * @returns
178
- */
179
- async profile() {
180
- if (!this.accessToken) {
181
- await this.login();
182
- }
183
- try {
184
- const profile = await this.request.get('/api/users/profile');
185
- return profile.data;
186
- }
187
- catch (error) {
188
- throw new Error(`Could not retrieve movements list ${error}`);
189
- }
190
- }
191
- async rates(payload = { currencyFrom: "EUR" }) {
192
- console.log(payload);
193
- if (!this.accessToken) {
194
- await this.login();
195
- }
196
- try {
197
- const rates = await this.request.post('/api/v2/movements/get_rate', { payload,
198
- headers: {
199
- 'Content-Type': 'application/json',
200
- Accept: 'application/json',
201
- Authorization: `Bearer ${this.accessToken}`,
202
- } });
203
- return rates.data;
204
- }
205
- catch (error) {
206
- throw new Error(`Could not retrieve rates ${error}`);
207
- }
208
- }
209
- }
210
-
211
- exports.Tropipay = Tropipay;
212
- //# sourceMappingURL=index.js.map
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var axios = require('axios');
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
9
+ var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
10
+
11
+ /**
12
+ * Tropipayjs is a Typescript/Javascript library for the Tropipay API.
13
+ *
14
+ * @author Yosleivy Baez Acosta
15
+ *
16
+ */
17
+ class Tropipay {
18
+ clientId;
19
+ clientSecret;
20
+ request;
21
+ accessToken;
22
+ refreshToken;
23
+ serverMode;
24
+ constructor(client_id, client_secret, server_mode = 'Development') {
25
+ this.clientId = client_id;
26
+ this.clientSecret = client_secret;
27
+ this.serverMode = server_mode;
28
+ this.request = axios__default["default"].create({
29
+ baseURL: this.serverMode === 'Production'
30
+ ? 'https://www.tropipay.com'
31
+ : 'https://tropipay-dev.herokuapp.com',
32
+ headers: {
33
+ 'Content-Type': 'application/json',
34
+ Accept: 'application/json',
35
+ Authorization: `Bearer ${this.accessToken}`,
36
+ }
37
+ });
38
+ }
39
+ async login() {
40
+ try {
41
+ const { data } = await this.request.post('/api/v2/access/token', {
42
+ client_id: this.clientId,
43
+ client_secret: this.clientSecret,
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"
46
+ }, {
47
+ // headers: {
48
+ // 'Content-Type': 'application/json',
49
+ // Accept: 'application/json',
50
+ // }
51
+ });
52
+ this.accessToken = data.access_token;
53
+ this.refreshToken = data.refresh_token;
54
+ return data;
55
+ }
56
+ catch (error) {
57
+ if (axios__default["default"].isAxiosError(error)) {
58
+ throw new Error(`Could not obtain the access token from credentials ${error}`);
59
+ }
60
+ throw new Error(`Could not obtain the access token from credentials ${error}`);
61
+ }
62
+ }
63
+ /**
64
+ * Create a paymentLink with the specified options.
65
+ * @param payload PaymentLinkPayload Object.
66
+ * @returns Promise<PaymentLink> or throws an Exception.
67
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
68
+ */
69
+ async createPayLink(payload) {
70
+ if (!this.accessToken) {
71
+ await this.login();
72
+ }
73
+ try {
74
+ const paylink = await this.request.post('/api/v2/paymentcards', payload, {
75
+ headers: {
76
+ // 'Content-Type': 'application/json',
77
+ Authorization: `Bearer ${this.accessToken}`,
78
+ // Accept: 'application/json'
79
+ }
80
+ });
81
+ return paylink.data;
82
+ }
83
+ catch (error) {
84
+ throw new Error(`Could not obtain the access token with the given credentials.`);
85
+ }
86
+ }
87
+ /**
88
+ * Get all deposits in this account.
89
+ * @returns A Promise of an Array of AccountDeposits or throws an Exception
90
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6OTgyOTQ1Mg-get-deposit-accounts-list
91
+ */
92
+ async getDepositAccounts() {
93
+ if (!this.accessToken) {
94
+ await this.login();
95
+ }
96
+ try {
97
+ const deposits = await this.request.get('/api/v2/deposit_accounts', {});
98
+ return deposits.data;
99
+ }
100
+ catch (error) {
101
+ throw new Error(`Could not retrieve the account deposits ${error}`);
102
+ }
103
+ }
104
+ /**
105
+ * Get the list of all supported countries by Tropipay.
106
+ * @returns Array of Countries Data
107
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/bfac21259e2ff-getting-users-countries-list
108
+ */
109
+ async countries() {
110
+ try {
111
+ const countries = await this.request.get('/api/v2/countries');
112
+ return countries.data;
113
+ }
114
+ catch (error) {
115
+ throw new Error(`Could not retrieve the countries list`);
116
+ }
117
+ }
118
+ /**
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.
138
+ * @returns
139
+ */
140
+ async favorites() {
141
+ if (!this.accessToken) {
142
+ await this.login();
143
+ }
144
+ try {
145
+ const favoritesList = await this.request.get('/api/v2/paymentcards/favorites');
146
+ console.log(favoritesList);
147
+ return favoritesList.data;
148
+ }
149
+ catch (error) {
150
+ throw new Error(`Could not retrieve favorites list ${error}`);
151
+ }
152
+ }
153
+ /**
154
+ * List all account movements. You can optionaly specify
155
+ * offset and limit params for pagination.
156
+ * @returns
157
+ */
158
+ async movements(offset = 0, limit = 10) {
159
+ if (!this.accessToken) {
160
+ await this.login();
161
+ }
162
+ try {
163
+ const movements = await this.request.get('/api/v2/movements', { params: { limit: limit, offset: offset },
164
+ headers: {
165
+ 'Content-Type': 'application/json',
166
+ Accept: 'application/json',
167
+ Authorization: `Bearer ${this.accessToken}`,
168
+ } });
169
+ return movements.data;
170
+ }
171
+ catch (error) {
172
+ throw new Error(`Could not retrieve movements list`);
173
+ }
174
+ }
175
+ /**
176
+ * Return profile data for this account.
177
+ * @returns
178
+ */
179
+ async profile() {
180
+ if (!this.accessToken) {
181
+ await this.login();
182
+ }
183
+ try {
184
+ const profile = await this.request.get('/api/users/profile');
185
+ return profile.data;
186
+ }
187
+ catch (error) {
188
+ throw new Error(`Could not retrieve movements list ${error}`);
189
+ }
190
+ }
191
+ /**
192
+ * Obtain current Tropipay conversion rate. For example USD to EUR
193
+ * targetCurrency must be 'EUR'
194
+ * @param originCurrency Target currency code supported by Tropipay.
195
+ * @param targetCurrency Must be 'EUR'? (not documented by Tropipay)
196
+ * @returns Conversion rate (number)
197
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/85163f6f28b23-get-rate
198
+ */
199
+ async rates(originCurrency, targetCurrency = 'EUR') {
200
+ if (!this.accessToken) {
201
+ await this.login();
202
+ }
203
+ try {
204
+ const rates = await this.request.post('/api/v2/movements/get_rate', {
205
+ currencyFrom: originCurrency,
206
+ currencyTo: targetCurrency
207
+ }, {
208
+ headers: {
209
+ 'Content-Type': 'application/json',
210
+ Accept: 'application/json',
211
+ Authorization: `Bearer ${this.accessToken}`,
212
+ }
213
+ });
214
+ return rates.data.rate;
215
+ }
216
+ catch (error) {
217
+ throw new Error(`Could not retrieve rates ${error}`);
218
+ }
219
+ }
220
+ }
221
+
222
+ exports.Tropipay = Tropipay;
223
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ export declare type TropipayCountry = {};
@@ -0,0 +1,2 @@
1
+ import * as countries from './countries';
2
+ export { countries };
@@ -1,36 +1,36 @@
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
- }
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
+ }
package/package.json CHANGED
@@ -1,42 +1,42 @@
1
- {
2
- "name": "@yosle/tropipayjs",
3
- "version": "0.1.6",
4
- "description": "Javascript / Typescript SDK for the Tropipay API",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1",
8
- "_clear": "rimraf src/dist/*",
9
- "_tsc": "tsc",
10
- "_make-bundle": "rollup --config",
11
- "build": "run-s _clear _tsc _make-bundle"
12
- },
13
- "repository": {
14
- "type": "git",
15
- "url": "https://github.com/yosle/tropipayjs"
16
- },
17
- "keywords": [
18
- "Javascript",
19
- "Typescript",
20
- "Tropipay",
21
- "payments",
22
- "gateway",
23
- "API"
24
- ],
25
- "author": "Yosleivy Baez Acosta <yosle007@gmail.com>",
26
- "license": "MIT",
27
- "dependencies": {
28
- "axios": "^0.27.2",
29
- "tslib": "^2.4.0"
30
- },
31
- "devDependencies": {
32
- "@rollup/plugin-typescript": "^8.5.0",
33
- "rimraf": "^3.0.2",
34
- "rollup": "^2.79.1",
35
- "rollup-plugin-dts": "^4.2.2",
36
- "run-s": "^0.0.0"
37
- },
38
- "funding": {
39
- "type": "individual",
40
- "url": "https://tppay.me/l94qaa3h"
41
- }
1
+ {
2
+ "name": "@yosle/tropipayjs",
3
+ "version": "0.1.7",
4
+ "description": "Javascript / Typescript SDK for the Tropipay API",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "_clear": "rimraf src/dist/*",
9
+ "_tsc": "tsc",
10
+ "_make-bundle": "rollup --config",
11
+ "build": "run-s _clear _tsc _make-bundle"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/yosle/tropipayjs"
16
+ },
17
+ "keywords": [
18
+ "Javascript",
19
+ "Typescript",
20
+ "Tropipay",
21
+ "payments",
22
+ "gateway",
23
+ "API"
24
+ ],
25
+ "author": "Yosleivy Baez Acosta <yosle007@gmail.com>",
26
+ "license": "MIT",
27
+ "dependencies": {
28
+ "axios": "^0.27.2",
29
+ "tslib": "^2.4.0"
30
+ },
31
+ "devDependencies": {
32
+ "@rollup/plugin-typescript": "^8.5.0",
33
+ "rimraf": "^3.0.2",
34
+ "rollup": "^2.79.1",
35
+ "rollup-plugin-dts": "^4.2.2",
36
+ "run-s": "^0.0.0"
37
+ },
38
+ "funding": {
39
+ "type": "individual",
40
+ "url": "https://tppay.me/l94qaa3h"
41
+ }
42
42
  }
package/rollup.config.js CHANGED
@@ -1,23 +1,23 @@
1
- // Contents of the file /rollup.config.js
2
- import typescript from '@rollup/plugin-typescript';
3
- import dts from "rollup-plugin-dts";
4
- const config = [
5
- {
6
- input: 'dist/index.js',
7
- output: {
8
- file: 'index.js',
9
- format: 'cjs',
10
- sourcemap: true,
11
- },
12
- external: ['axios'],
13
- plugins: [typescript()]
14
- }, {
15
- input: 'dist/index.d.ts',
16
- output: {
17
- file: 'index.d.ts',
18
- format: 'es'
19
- },
20
- plugins: [dts()]
21
- }
22
- ];
1
+ // Contents of the file /rollup.config.js
2
+ import typescript from '@rollup/plugin-typescript';
3
+ import dts from "rollup-plugin-dts";
4
+ const config = [
5
+ {
6
+ input: 'dist/index.js',
7
+ output: {
8
+ file: 'index.js',
9
+ format: 'cjs',
10
+ sourcemap: true,
11
+ },
12
+ external: ['axios'],
13
+ plugins: [typescript()]
14
+ }, {
15
+ input: 'dist/index.d.ts',
16
+ output: {
17
+ file: 'index.d.ts',
18
+ format: 'es'
19
+ },
20
+ plugins: [dts()]
21
+ }
22
+ ];
23
23
  export default config;