@yosle/tropipayjs 0.1.7 → 0.1.9

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,223 +1,282 @@
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
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
+ static accessToken;
22
+ static refreshToken;
23
+ serverMode;
24
+ constructor(config) {
25
+ this.clientId = config.clientId;
26
+ this.clientSecret = config.clientSecret;
27
+ this.serverMode = config.serverMode || 'Development';
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 ${Tropipay.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
+ Tropipay.accessToken = data.access_token;
53
+ Tropipay.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 createPaymentCard(payload) {
70
+ if (!Tropipay.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 ${Tropipay.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 (!Tropipay.accessToken) {
94
+ await this.login();
95
+ }
96
+ try {
97
+ const deposits = await this.request.get('/api/v2/deposit_accounts', {
98
+ headers: {
99
+ 'Content-Type': 'application/json',
100
+ Authorization: `Bearer ${Tropipay.accessToken}`,
101
+ Accept: 'application/json'
102
+ }
103
+ });
104
+ return deposits.data;
105
+ }
106
+ catch (error) {
107
+ throw new Error(`Could not retrieve the account deposits ${error}`);
108
+ }
109
+ }
110
+ /**
111
+ * Get the list of all supported countries by Tropipay.
112
+ * @returns Array of Countries Data
113
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/bfac21259e2ff-getting-users-countries-list
114
+ */
115
+ async countries() {
116
+ try {
117
+ const countries = await this.request.get('/api/v2/countries');
118
+ return countries.data;
119
+ }
120
+ catch (error) {
121
+ throw new Error(`TropipayJS Error - Could not retrieve the countries list`);
122
+ }
123
+ }
124
+ /**
125
+ * Get user balance
126
+ * @returns balance object
127
+ */
128
+ async getBalance() {
129
+ if (!Tropipay.accessToken) {
130
+ await this.login();
131
+ }
132
+ try {
133
+ const balance = await this.request.get('/api/v2/users/balance', {
134
+ headers: {
135
+ 'Content-Type': 'application/json',
136
+ Authorization: `Bearer ${Tropipay.accessToken}`,
137
+ Accept: 'application/json'
138
+ }
139
+ });
140
+ return balance.data;
141
+ }
142
+ catch (error) {
143
+ console.log("el error es ", error);
144
+ throw new Error(`TropipayJS Error - Could not retrieve the user's balance`);
145
+ }
146
+ }
147
+ /**
148
+ * Get the list of all detination countries supported by Tropipay.
149
+ * Obtaining the list of valid countries to send funds to. Useful
150
+ * when adding new beneficiaries to some user.
151
+ *
152
+ * @returns Array of Country Objects
153
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/3cfe5504f0524-getting-list-of-beneficiary-countries
154
+ */
155
+ async destinations() {
156
+ try {
157
+ const countries = await this.request.get('/api/v2/countries/destinations');
158
+ return countries.data;
159
+ }
160
+ catch (error) {
161
+ throw new Error(`Could not retrieve the destination countries list`);
162
+ }
163
+ }
164
+ /**
165
+ * Get list of all the favorites payment links.
166
+ * @returns Array of account Object or throws an error
167
+ */
168
+ async favorites() {
169
+ if (!Tropipay.accessToken) {
170
+ await this.login();
171
+ }
172
+ try {
173
+ const favoritesList = await this.request.get('/api/v2/paymentcards/favorites', {
174
+ headers: {
175
+ 'Content-Type': 'application/json',
176
+ Authorization: `Bearer ${Tropipay.accessToken}`,
177
+ Accept: 'application/json'
178
+ }
179
+ });
180
+ return favoritesList?.data?.rows;
181
+ }
182
+ catch (error) {
183
+ throw new Error(`Could not retrieve favorites list ${error}`);
184
+ }
185
+ }
186
+ /**
187
+ * List all account movements. You can optionaly specify
188
+ * offset and limit params for pagination.
189
+ * @returns
190
+ */
191
+ async movements(offset = 0, limit = 10) {
192
+ if (!Tropipay.accessToken)
193
+ await this.login();
194
+ try {
195
+ const movements = await this.request.get('/api/v2/movements', {
196
+ params: { limit: limit, offset: offset },
197
+ headers: {
198
+ 'Content-Type': 'application/json',
199
+ Accept: 'application/json',
200
+ Authorization: `Bearer ${Tropipay.accessToken}`
201
+ }
202
+ });
203
+ return movements.data;
204
+ }
205
+ catch (error) {
206
+ throw new Error(`Could not retrieve movements list ${error}`);
207
+ }
208
+ }
209
+ /**
210
+ * Return profile data for this account.
211
+ * @returns
212
+ */
213
+ async profile() {
214
+ if (!Tropipay.accessToken)
215
+ await this.login();
216
+ try {
217
+ const profile = await this.request.get('/api/users/profile');
218
+ return profile.data;
219
+ }
220
+ catch (error) {
221
+ throw new Error(`Could not retrieve movements list ${error}`);
222
+ }
223
+ }
224
+ /**
225
+ * Obtain current Tropipay conversion rate. For example USD to EUR
226
+ * targetCurrency must be 'EUR'
227
+ * @param originCurrency Target currency code supported by Tropipay.
228
+ * @param targetCurrency Must be 'EUR'? (not documented by Tropipay)
229
+ * @returns Conversion rate (number)
230
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/85163f6f28b23-get-rate
231
+ */
232
+ async rates(originCurrency, targetCurrency = 'EUR') {
233
+ if (!Tropipay.accessToken) {
234
+ await this.login();
235
+ }
236
+ try {
237
+ const rates = await this.request.post('/api/v2/movements/get_rate', {
238
+ currencyFrom: originCurrency,
239
+ currencyTo: targetCurrency
240
+ }, {
241
+ headers: {
242
+ 'Content-Type': 'application/json',
243
+ Accept: 'application/json',
244
+ Authorization: `Bearer ${Tropipay.accessToken}`,
245
+ }
246
+ });
247
+ return rates.data.rate;
248
+ }
249
+ catch (error) {
250
+ throw new Error(`Could not retrieve rates ${error}`);
251
+ }
252
+ }
253
+ /**
254
+ * (ONLY in Bussiness Accounts)
255
+ * An escrow payment link. This allows a payment to be made to persons
256
+ * belonging or not to the TropiPay platform with the particularity
257
+ * that the payment will be held in custody or retained until it is
258
+ * released with the approval of the payer.
259
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/12a128ff971e4-creating-a-mediation-payment-card
260
+ * @param config Payload with the payment details
261
+ */
262
+ async createMediationPaymentCard(config) {
263
+ if (!Tropipay.accessToken)
264
+ await this.login();
265
+ try {
266
+ const mediation = await this.request.post('/api/v2/paymentcards/mediation', config, {
267
+ headers: {
268
+ 'Content-Type': 'application/json',
269
+ Authorization: `Bearer ${Tropipay.accessToken}`,
270
+ Accept: 'application/json'
271
+ }
272
+ });
273
+ return mediation.data;
274
+ }
275
+ catch (error) {
276
+ throw new Error(`Could not generate mediation paymentCard ${error}`);
277
+ }
278
+ }
279
+ }
280
+
281
+ exports.Tropipay = Tropipay;
282
+ //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- export declare type TropipayCountry = {};
1
+ export type TropipayCountry = {};
@@ -1,2 +1,2 @@
1
- import * as countries from './countries';
2
- export { countries };
1
+ import * as countries from './countries';
2
+ export { countries };
@@ -0,0 +1,22 @@
1
+ /**
2
+ *
3
+ */
4
+ export interface mediationPaymentCardConfig {
5
+ amount: number;
6
+ currency: "EUR" | "USD";
7
+ concept: string;
8
+ description: string;
9
+ reference: string;
10
+ singleUse: boolean;
11
+ lang: string;
12
+ productUrl?: string;
13
+ buyer: null | any;
14
+ seller: {
15
+ sellerId?: number;
16
+ type?: number;
17
+ email?: string;
18
+ };
19
+ feePercent?: number;
20
+ feeFixed?: number;
21
+ sendMail: boolean;
22
+ }
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "@yosle/tropipayjs",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Javascript / Typescript SDK for the Tropipay API",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -8,7 +8,7 @@
8
8
  "_clear": "rimraf src/dist/*",
9
9
  "_tsc": "tsc",
10
10
  "_make-bundle": "rollup --config",
11
- "build": "run-s _clear _tsc _make-bundle"
11
+ "build": "yarn _clear && yarn _tsc && yarn _make-bundle"
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
@@ -33,7 +33,8 @@
33
33
  "rimraf": "^3.0.2",
34
34
  "rollup": "^2.79.1",
35
35
  "rollup-plugin-dts": "^4.2.2",
36
- "run-s": "^0.0.0"
36
+ "run-s": "^0.0.0",
37
+ "typescript": "^5.0.4"
37
38
  },
38
39
  "funding": {
39
40
  "type": "individual",