@yosle/tropipayjs 0.1.6 → 0.1.8

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
@@ -18,13 +18,13 @@ class Tropipay {
18
18
  clientId;
19
19
  clientSecret;
20
20
  request;
21
- accessToken;
22
- refreshToken;
21
+ static accessToken;
22
+ static refreshToken;
23
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;
24
+ constructor(config) {
25
+ this.clientId = config.clientId;
26
+ this.clientSecret = config.clientSecret;
27
+ this.serverMode = config.serverMode || 'Development';
28
28
  this.request = axios__default["default"].create({
29
29
  baseURL: this.serverMode === 'Production'
30
30
  ? 'https://www.tropipay.com'
@@ -32,7 +32,7 @@ class Tropipay {
32
32
  headers: {
33
33
  'Content-Type': 'application/json',
34
34
  Accept: 'application/json',
35
- Authorization: `Bearer ${this.accessToken}`,
35
+ Authorization: `Bearer ${Tropipay.accessToken}`,
36
36
  }
37
37
  });
38
38
  }
@@ -44,20 +44,20 @@ class Tropipay {
44
44
  grant_type: "client_credentials",
45
45
  scope: "ALLOW_GET_PROFILE_DATA ALLOW_PAYMENT_IN ALLOW_EXTERNAL_CHARGE KYC3_FULL_ALLOW ALLOW_PAYMENT_OUT ALLOW_MARKET_PURCHASES ALLOW_GET_BALANCE ALLOW_GET_MOVEMENT_LIST ALLOW_GET_CREDENTIAL"
46
46
  }, {
47
- // headers: {
48
- // 'Content-Type': 'application/json',
49
- // Accept: 'application/json',
50
- // }
47
+ headers: {
48
+ 'Content-Type': 'application/json',
49
+ Accept: 'application/json',
50
+ }
51
51
  });
52
- this.accessToken = data.access_token;
53
- this.refreshToken = data.refresh_token;
52
+ Tropipay.accessToken = data.access_token;
53
+ Tropipay.refreshToken = data.refresh_token;
54
54
  return data;
55
55
  }
56
56
  catch (error) {
57
57
  if (axios__default["default"].isAxiosError(error)) {
58
- throw new Error("Conection error: " + error.message);
58
+ throw new Error(`Could not obtain the access token from credentials ${error}`);
59
59
  }
60
- throw new Error("Could not obtain the access token from credentials ");
60
+ throw new Error(`Could not obtain the access token from credentials ${error}`);
61
61
  }
62
62
  }
63
63
  /**
@@ -66,16 +66,16 @@ class Tropipay {
66
66
  * @returns Promise<PaymentLink> or throws an Exception.
67
67
  * @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
68
68
  */
69
- async createPayLink(payload) {
70
- if (!this.accessToken) {
69
+ async createPaymentCard(payload) {
70
+ if (!Tropipay.accessToken) {
71
71
  await this.login();
72
72
  }
73
73
  try {
74
74
  const paylink = await this.request.post('/api/v2/paymentcards', payload, {
75
75
  headers: {
76
- // 'Content-Type': 'application/json',
77
- Authorization: `Bearer ${this.accessToken}`,
78
- // Accept: 'application/json'
76
+ 'Content-Type': 'application/json',
77
+ Authorization: `Bearer ${Tropipay.accessToken}`,
78
+ Accept: 'application/json'
79
79
  }
80
80
  });
81
81
  return paylink.data;
@@ -90,11 +90,17 @@ class Tropipay {
90
90
  * @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6OTgyOTQ1Mg-get-deposit-accounts-list
91
91
  */
92
92
  async getDepositAccounts() {
93
- if (!this.accessToken) {
93
+ if (!Tropipay.accessToken) {
94
94
  await this.login();
95
95
  }
96
96
  try {
97
- const deposits = await this.request.get('/api/v2/deposit_accounts', {});
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
+ });
98
104
  return deposits.data;
99
105
  }
100
106
  catch (error) {
@@ -112,7 +118,7 @@ class Tropipay {
112
118
  return countries.data;
113
119
  }
114
120
  catch (error) {
115
- throw new Error(`Could not retrieve the countries list`);
121
+ throw new Error(`TropipayJS Error - Could not retrieve the countries list`);
116
122
  }
117
123
  }
118
124
  /**
@@ -133,18 +139,22 @@ class Tropipay {
133
139
  }
134
140
  }
135
141
  /**
136
- * Get list of all the favorites accounts. This endpoint is not documented
137
- * in the official Tropipay documentation.
138
- * @returns
142
+ * Get list of all the favorites payment links.
143
+ * @returns Array of account Object or throws an error
139
144
  */
140
145
  async favorites() {
141
- if (!this.accessToken) {
146
+ if (!Tropipay.accessToken) {
142
147
  await this.login();
143
148
  }
144
149
  try {
145
- const favoritesList = await this.request.get('/api/v2/paymentcards/favorites');
146
- console.log(favoritesList);
147
- return favoritesList.data;
150
+ const favoritesList = await this.request.get('/api/v2/paymentcards/favorites', {
151
+ headers: {
152
+ 'Content-Type': 'application/json',
153
+ Authorization: `Bearer ${Tropipay.accessToken}`,
154
+ Accept: 'application/json'
155
+ }
156
+ });
157
+ return favoritesList?.data?.rows;
148
158
  }
149
159
  catch (error) {
150
160
  throw new Error(`Could not retrieve favorites list ${error}`);
@@ -156,20 +166,21 @@ class Tropipay {
156
166
  * @returns
157
167
  */
158
168
  async movements(offset = 0, limit = 10) {
159
- if (!this.accessToken) {
169
+ if (!Tropipay.accessToken)
160
170
  await this.login();
161
- }
162
171
  try {
163
- const movements = await this.request.get('/api/v2/movements', { params: { limit: limit, offset: offset },
172
+ const movements = await this.request.get('/api/v2/movements', {
173
+ params: { limit: limit, offset: offset },
164
174
  headers: {
165
175
  'Content-Type': 'application/json',
166
176
  Accept: 'application/json',
167
- Authorization: `Bearer ${this.accessToken}`,
168
- } });
177
+ Authorization: `Bearer ${Tropipay.accessToken}`
178
+ }
179
+ });
169
180
  return movements.data;
170
181
  }
171
182
  catch (error) {
172
- throw new Error(`Could not retrieve movements list`);
183
+ throw new Error(`Could not retrieve movements list ${error}`);
173
184
  }
174
185
  }
175
186
  /**
@@ -177,9 +188,8 @@ class Tropipay {
177
188
  * @returns
178
189
  */
179
190
  async profile() {
180
- if (!this.accessToken) {
191
+ if (!Tropipay.accessToken)
181
192
  await this.login();
182
- }
183
193
  try {
184
194
  const profile = await this.request.get('/api/users/profile');
185
195
  return profile.data;
@@ -188,24 +198,61 @@ class Tropipay {
188
198
  throw new Error(`Could not retrieve movements list ${error}`);
189
199
  }
190
200
  }
191
- async rates(payload = { currencyFrom: "EUR" }) {
192
- console.log(payload);
193
- if (!this.accessToken) {
201
+ /**
202
+ * Obtain current Tropipay conversion rate. For example USD to EUR
203
+ * targetCurrency must be 'EUR'
204
+ * @param originCurrency Target currency code supported by Tropipay.
205
+ * @param targetCurrency Must be 'EUR'? (not documented by Tropipay)
206
+ * @returns Conversion rate (number)
207
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/85163f6f28b23-get-rate
208
+ */
209
+ async rates(originCurrency, targetCurrency = 'EUR') {
210
+ if (!Tropipay.accessToken) {
194
211
  await this.login();
195
212
  }
196
213
  try {
197
- const rates = await this.request.post('/api/v2/movements/get_rate', { payload,
214
+ const rates = await this.request.post('/api/v2/movements/get_rate', {
215
+ currencyFrom: originCurrency,
216
+ currencyTo: targetCurrency
217
+ }, {
198
218
  headers: {
199
219
  'Content-Type': 'application/json',
200
220
  Accept: 'application/json',
201
- Authorization: `Bearer ${this.accessToken}`,
202
- } });
203
- return rates.data;
221
+ Authorization: `Bearer ${Tropipay.accessToken}`,
222
+ }
223
+ });
224
+ return rates.data.rate;
204
225
  }
205
226
  catch (error) {
206
227
  throw new Error(`Could not retrieve rates ${error}`);
207
228
  }
208
229
  }
230
+ /**
231
+ * (ONLY in Bussiness Accounts)
232
+ * An escrow payment link. This allows a payment to be made to persons
233
+ * belonging or not to the TropiPay platform with the particularity
234
+ * that the payment will be held in custody or retained until it is
235
+ * released with the approval of the payer.
236
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/12a128ff971e4-creating-a-mediation-payment-card
237
+ * @param config Payload with the payment details
238
+ */
239
+ async createMediationPaymentCard(config) {
240
+ if (!Tropipay.accessToken)
241
+ await this.login();
242
+ try {
243
+ const mediation = await this.request.post('/api/v2/paymentcards/mediation', config, {
244
+ headers: {
245
+ 'Content-Type': 'application/json',
246
+ Authorization: `Bearer ${Tropipay.accessToken}`,
247
+ Accept: 'application/json'
248
+ }
249
+ });
250
+ return mediation.data;
251
+ }
252
+ catch (error) {
253
+ throw new Error(`Could not generate mediation paymentCard ${error}`);
254
+ }
255
+ }
209
256
  }
210
257
 
211
258
  exports.Tropipay = Tropipay;
@@ -0,0 +1 @@
1
+ export type TropipayCountry = {};
@@ -0,0 +1,2 @@
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
+ }
package/package.json CHANGED
@@ -1,42 +1,43 @@
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.8",
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": "yarn _clear && yarn _tsc && yarn _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
+ "typescript": "^5.0.4"
38
+ },
39
+ "funding": {
40
+ "type": "individual",
41
+ "url": "https://tppay.me/l94qaa3h"
42
+ }
42
43
  }
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;
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
  }