@yosle/tropipayjs 0.1.9 → 0.1.10

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/src/index.ts CHANGED
@@ -1,299 +1,13 @@
1
- /**
2
- * Tropipayjs is a Typescript/Javascript library for the Tropipay API.
3
- *
4
- * @author Yosleivy Baez Acosta
5
- *
6
- */
7
-
8
- import axios, { Axios } from "axios";
9
- import { PaymentLink, PaymentLinkPayload } from './interfaces/paymentlink'
10
- import { mediationPaymentCardConfig } from "./interfaces/mediation";
11
-
12
- type ServerMode = 'Development' | 'Production'
13
-
14
- interface TropipayConfig {
15
- clientId: string;
16
- clientSecret: string;
17
- serverMode?: ServerMode;
18
- }
19
-
20
- type AccountBalance = {
21
- balance: number,
22
- pendingIn: number,
23
- pendingOut: number
24
- }
25
-
26
- export class Tropipay {
27
- protected clientId: string;
28
- protected clientSecret: string;
29
- protected request: Axios;
30
- protected static accessToken: string | undefined;
31
- protected static refreshToken: string | undefined;
32
- protected serverMode: ServerMode;
33
-
34
- constructor(config: TropipayConfig) {
35
- this.clientId = config.clientId;
36
- this.clientSecret = config.clientSecret;
37
- this.serverMode = config.serverMode || 'Development';
38
- this.request = axios.create({
39
- baseURL: this.serverMode === 'Production'
40
- ? 'https://www.tropipay.com'
41
- : 'https://tropipay-dev.herokuapp.com',
42
- headers: {
43
- 'Content-Type': 'application/json',
44
- Accept: 'application/json',
45
- Authorization: `Bearer ${Tropipay.accessToken}`,
46
- }
47
- });
48
- }
49
-
50
-
51
- async login() {
52
- try {
53
- const { data } = await this.request.post<LoginResponse>('/api/v2/access/token', {
54
- client_id: this.clientId,
55
- client_secret: this.clientSecret,
56
- grant_type: "client_credentials",
57
- 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"
58
- }, {
59
- headers: {
60
- 'Content-Type': 'application/json',
61
- Accept: 'application/json',
62
- }
63
- });
64
-
65
- Tropipay.accessToken = data.access_token
66
- Tropipay.refreshToken = data.refresh_token
67
- return data
68
- } catch (error) {
69
- if (axios.isAxiosError(error)) {
70
- throw new Error(`Could not obtain the access token from credentials ${error}`);
71
- }
72
- throw new Error(`Could not obtain the access token from credentials ${error}`);
73
-
74
- }
75
- }
76
-
77
- /**
78
- * Create a paymentLink with the specified options.
79
- * @param payload PaymentLinkPayload Object.
80
- * @returns Promise<PaymentLink> or throws an Exception.
81
- * @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
82
- */
83
- async createPaymentCard(payload: PaymentLinkPayload): Promise<PaymentLink> {
84
- if (!Tropipay.accessToken) {
85
- await this.login()
86
- }
87
- try {
88
- const paylink = await this.request.post('/api/v2/paymentcards', payload, {
89
- headers: {
90
- 'Content-Type': 'application/json',
91
- Authorization: `Bearer ${Tropipay.accessToken}`,
92
- Accept: 'application/json'
93
- }
94
- })
95
- return paylink.data as PaymentLink
96
- } catch (error) {
97
- throw new Error(`Could not obtain the access token with the given credentials.`);
98
- }
99
- }
100
-
101
- /**
102
- * Get all deposits in this account.
103
- * @returns A Promise of an Array of AccountDeposits or throws an Exception
104
- * @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6OTgyOTQ1Mg-get-deposit-accounts-list
105
- */
106
- async getDepositAccounts(): Promise<AccountDeposits[] | Error> {
107
- if (!Tropipay.accessToken) {
108
- await this.login()
109
- }
110
- try {
111
- const deposits = await this.request.get('/api/v2/deposit_accounts', {
112
- headers: {
113
- 'Content-Type': 'application/json',
114
- Authorization: `Bearer ${Tropipay.accessToken}`,
115
- Accept: 'application/json'
116
- }
117
- })
118
- return deposits.data
119
- } catch (error) {
120
- throw new Error(`Could not retrieve the account deposits ${error}`);
121
- }
122
- }
123
-
124
- /**
125
- * Get the list of all supported countries by Tropipay.
126
- * @returns Array of Countries Data
127
- * @see https://tpp.stoplight.io/docs/tropipay-api-doc/bfac21259e2ff-getting-users-countries-list
128
- */
129
- async countries(): Promise<Country[]> {
130
- try {
131
- const countries = await this.request.get('/api/v2/countries')
132
- return countries.data
133
- } catch (error) {
134
- throw new Error(`TropipayJS Error - Could not retrieve the countries list`);
135
- }
136
- }
137
- /**
138
- * Get user balance
139
- * @returns balance Object { balance: number, pendingIn: number, pendingOut: number }
140
- */
141
- async getBalance(): Promise<AccountBalance> {
142
- if (!Tropipay.accessToken) {
143
- await this.login()
144
- }
145
- try {
146
- const balance = await this.request.get('/api/v2/users/balance', {
147
- headers: {
148
- 'Content-Type': 'application/json',
149
- Authorization: `Bearer ${Tropipay.accessToken}`,
150
- Accept: 'application/json'
151
- }
152
- });
153
- return balance.data
154
- } catch (error) {
155
- throw new Error(`TropipayJS Error - Could not retrieve the user's balance`);
156
- }
157
- }
158
-
159
- /**
160
- * Get the list of all detination countries supported by Tropipay.
161
- * Obtaining the list of valid countries to send funds to. Useful
162
- * when adding new beneficiaries to some user.
163
- *
164
- * @returns Array of Country Objects
165
- * @see https://tpp.stoplight.io/docs/tropipay-api-doc/3cfe5504f0524-getting-list-of-beneficiary-countries
166
- */
167
- async destinations(): Promise<Country[]> {
168
- try {
169
- const countries = await this.request.get('/api/v2/countries/destinations')
170
- return countries.data
171
- } catch (error) {
172
- throw new Error(`Could not retrieve the destination countries list`);
173
- }
174
- }
175
-
176
- /**
177
- * Get list of all the favorites payment links.
178
- * @returns Array of account Object or throws an error
179
- */
180
- async favorites() {
181
- if (!Tropipay.accessToken) {
182
- await this.login()
183
- }
184
- try {
185
- const favoritesList = await this.request.get('/api/v2/paymentcards/favorites', {
186
- headers: {
187
- 'Content-Type': 'application/json',
188
- Authorization: `Bearer ${Tropipay.accessToken}`,
189
- Accept: 'application/json'
190
- }
191
- });
192
- return favoritesList?.data?.rows
193
- } catch (error) {
194
- throw new Error(`Could not retrieve favorites list ${error}`);
195
- }
196
- }
197
-
198
- /**
199
- * List all account movements. You can optionaly specify
200
- * offset and limit params for pagination.
201
- * @returns
202
- */
203
- async movements(offset = 0, limit = 10) {
204
- if (!Tropipay.accessToken) await this.login()
205
-
206
- try {
207
- const movements = await this.request.get('/api/v2/movements',
208
- {
209
- params: { limit: limit, offset: offset },
210
- headers: {
211
- 'Content-Type': 'application/json',
212
- Accept: 'application/json',
213
- Authorization: `Bearer ${Tropipay.accessToken}`
214
- }
215
- })
216
- return movements.data
217
- } catch (error) {
218
- throw new Error(`Could not retrieve movements list ${error}`);
219
- }
220
- }
221
-
222
- /**
223
- * Return profile data for this account.
224
- * @returns
225
- */
226
- async profile() {
227
- if (!Tropipay.accessToken) await this.login();
228
- try {
229
- const profile = await this.request.get('/api/users/profile')
230
- return profile.data
231
- } catch (error) {
232
- throw new Error(`Could not retrieve movements list ${error}`);
233
- }
234
- }
235
-
236
- /**
237
- * Obtain current Tropipay conversion rate. For example USD to EUR
238
- * targetCurrency must be 'EUR'
239
- * @param originCurrency Target currency code supported by Tropipay.
240
- * @param targetCurrency Must be 'EUR'? (not documented by Tropipay)
241
- * @returns Conversion rate (number)
242
- * @see https://tpp.stoplight.io/docs/tropipay-api-doc/85163f6f28b23-get-rate
243
- */
244
- async rates(originCurrency: string, targetCurrency: string = 'EUR'): Promise<number | Error> {
245
- if (!Tropipay.accessToken) {
246
- await this.login()
247
- }
248
- try {
249
- const rates = await this.request.post('/api/v2/movements/get_rate',
250
- {
251
- currencyFrom: originCurrency,
252
- currencyTo: targetCurrency
253
- }, {
254
- headers: {
255
- 'Content-Type': 'application/json',
256
- Accept: 'application/json',
257
- Authorization: `Bearer ${Tropipay.accessToken}`,
258
-
259
- }
260
- })
261
- return rates.data.rate
262
- } catch (error) {
263
- throw new Error(`Could not retrieve rates ${error}`);
264
- }
265
-
266
- }
267
-
268
- /**
269
- * (ONLY in Bussiness Accounts)
270
- * An escrow payment link. This allows a payment to be made to persons
271
- * belonging or not to the TropiPay platform with the particularity
272
- * that the payment will be held in custody or retained until it is
273
- * released with the approval of the payer.
274
- * @see https://tpp.stoplight.io/docs/tropipay-api-doc/12a128ff971e4-creating-a-mediation-payment-card
275
- * @param config Payload with the payment details
276
- */
277
- async createMediationPaymentCard(config: mediationPaymentCardConfig): Promise<PaymentLink> {
278
- if (!Tropipay.accessToken) await this.login();
279
- try {
280
- const mediation = await this.request.post('/api/v2/paymentcards/mediation', config, {
281
- headers: {
282
- 'Content-Type': 'application/json',
283
- Authorization: `Bearer ${Tropipay.accessToken}`,
284
- Accept: 'application/json'
285
- }
286
- })
287
- return mediation.data as PaymentLink;
288
- } catch (error) {
289
- throw new Error(`Could not generate mediation paymentCard ${error}`);
290
- }
291
-
292
-
293
- }
294
-
295
- }
296
-
297
-
298
-
299
-
1
+ /**
2
+ * Tropipayjs is a Typescript/Javascript library for the Tropipay API.
3
+ *
4
+ * @author Yosleivy Baez Acosta
5
+ *
6
+ */
7
+ export { Tropipay } from "./api/TropipayAPI";
8
+ export { ClientSideUtils } from "./api/TropipayAPI";
9
+ export { ServerSideUtils } from "./utils/TropipayUtils";
10
+ export { TropipayHooks } from "./hooks/TropipayHooks";
11
+ export * from "./interfaces/index";
12
+ export { SERVER_MODE } from "./config/TropipayConfig";
13
+ export * from "./constants/TropipayConstants";
@@ -1,2 +1,2 @@
1
- "use strict";
1
+ "use strict";
2
2
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,172 @@
1
- import * as countries from './countries'
2
-
3
-
4
- export {countries}
1
+ import { ServerMode } from "../constants/TropipayConstants";
2
+
3
+ export type AccountBalance = {
4
+ balance: number;
5
+ pendingIn: number;
6
+ pendingOut: number;
7
+ };
8
+
9
+ export interface TropipayConfig {
10
+ clientId: string;
11
+ clientSecret: string;
12
+ serverMode?: ServerMode;
13
+ }
14
+
15
+ export type TropipayCredentials = { clientId: string; clientSecret: string };
16
+ export type HookEventType =
17
+ | "transaction_completed"
18
+ | "transaction_charged"
19
+ | "transaction_guarded";
20
+
21
+ export type HookTargetType = "web" | "email";
22
+ export interface UserHook {
23
+ event: HookEventType;
24
+ target: string;
25
+ value: string;
26
+ }
27
+ export interface UserHookSubscribed extends UserHook {
28
+ createdAt: string;
29
+ updatedAt: string;
30
+ }
31
+
32
+ export interface UserHook {
33
+ event: HookEventType;
34
+ target: string;
35
+ value: string;
36
+ }
37
+ export interface UserHookSubscribed extends UserHook {
38
+ createdAt: string;
39
+ updatedAt: string;
40
+ }
41
+
42
+ export interface PaymentLinkPayload {
43
+ reference: string;
44
+ concept: string;
45
+ favorite: boolean;
46
+ amount: number;
47
+ currency: string;
48
+ description: string;
49
+ singleUse: boolean;
50
+ reasonId: number;
51
+ expirationDays: number;
52
+ lang: string;
53
+ urlSuccess: string;
54
+ urlFailed: string;
55
+ urlNotification: string;
56
+ serviceDate: string;
57
+ client: {
58
+ name: string;
59
+ lastName: string;
60
+ address: string;
61
+ phone: string;
62
+ email: string;
63
+ countryId: number;
64
+ termsAndConditions: boolean;
65
+ };
66
+ directPayment: boolean;
67
+ paymentMethods?: string[];
68
+ }
69
+
70
+ export interface PaymentLink extends PaymentLinkPayload {
71
+ expirationDate: string;
72
+ hasClient: boolean;
73
+ updatedAt: string;
74
+ createdAt: string;
75
+ qrImage: string;
76
+ shortUrl: string;
77
+ paymentUrl: string;
78
+ }
79
+
80
+ export interface mediationPaymentCardConfig {
81
+ amount: number;
82
+ currency: "EUR" | "USD";
83
+ concept: string;
84
+ description: string;
85
+ reference: string;
86
+ singleUse: boolean;
87
+ lang: string;
88
+ productUrl?: string;
89
+ buyer: null | any;
90
+ seller: {
91
+ sellerId?: number;
92
+ type?: number;
93
+ email?: string;
94
+ };
95
+ feePercent?: number;
96
+ feeFixed?: number;
97
+ sendMail: boolean;
98
+ }
99
+
100
+ export type LoginResponse = {
101
+ access_token: string;
102
+ refresh_token: string;
103
+ token_type: "Bearer";
104
+ expires_in: number;
105
+ scope: string;
106
+ };
107
+
108
+ export type LoginError = {
109
+ error: string;
110
+ };
111
+
112
+ export type Country = {
113
+ id: number;
114
+ name: string;
115
+ sepaZone: boolean;
116
+ state: number;
117
+ slug: string;
118
+ slugn: number;
119
+ callingCode: number;
120
+ isDestination: boolean;
121
+ isRisky: boolean;
122
+ currentCurrency: string | null;
123
+ createdAt: string;
124
+ updatedAt: string;
125
+ isFavorite: boolean;
126
+ position: any;
127
+ };
128
+
129
+ export type Deposit = {
130
+ id: number;
131
+ accountNumber: string;
132
+ alias: string;
133
+ swift: string;
134
+ type: number;
135
+ country: number | null;
136
+ firstName: string;
137
+ default: null;
138
+ state: number;
139
+ userId: string;
140
+ countryDestinationId: number;
141
+ lastName: string;
142
+ documentNumber: number;
143
+ userRelationTypeId: number;
144
+ city: string;
145
+ postalCode: string;
146
+ address: string;
147
+ phone: string;
148
+ checked: boolean;
149
+ province: string;
150
+ beneficiaryType: number;
151
+ relatedUserId: null | string;
152
+ currency: string;
153
+ correspondent?: any;
154
+ location: any;
155
+ office: any;
156
+ officeValue: any;
157
+ paymentType: number;
158
+ paymentEntityBeneficiaryId: number;
159
+ paymentEntityAccountId: number;
160
+ verified: any;
161
+ paymentEntityInfo: any;
162
+ documentTypeId: any;
163
+ documentExpirationDate: Date;
164
+ createdAt: Date;
165
+ updatedAt: Date;
166
+ countryDestination: Country;
167
+ };
168
+
169
+ export type AccountDeposits = {
170
+ count: number;
171
+ rows: Deposit[];
172
+ };
@@ -1,23 +1,23 @@
1
-
2
- /**
3
- *
4
- */
5
- export interface mediationPaymentCardConfig {
6
- amount: number //5000,
7
- currency: "EUR" | "USD",
8
- concept: string //Celular,
9
- description: string,
10
- reference: string, //458424548,
11
- singleUse: boolean,
12
- lang: string// es,
13
- productUrl?: string,
14
- buyer: null | any //null,
15
- seller: {
16
- sellerId?: number,
17
- type?: number,
18
- email?: string
19
- },
20
- feePercent?: number,//in cents
21
- feeFixed?: number,
22
- sendMail: boolean
1
+
2
+ /**
3
+ *
4
+ */
5
+ export interface mediationPaymentCardConfig {
6
+ amount: number //5000,
7
+ currency: "EUR" | "USD",
8
+ concept: string //Celular,
9
+ description: string,
10
+ reference: string, //458424548,
11
+ singleUse: boolean,
12
+ lang: string// es,
13
+ productUrl?: string,
14
+ buyer: null | any //null,
15
+ seller: {
16
+ sellerId?: number,
17
+ type?: number,
18
+ email?: string
19
+ },
20
+ feePercent?: number,//in cents
21
+ feeFixed?: number,
22
+ sendMail: boolean
23
23
  }
@@ -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
+ }
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=index.js.map
@@ -1,40 +1,40 @@
1
-
2
- export interface PaymentLinkPayload {
3
- reference: string,
4
- concept: string,
5
- favorite: boolean,
6
- amount: number,
7
- currency: string,
8
- description : string,
9
- singleUse: boolean,
10
- reasonId: number,
11
- expirationDays: number,
12
- lang:string,
13
- urlSuccess: string,
14
- urlFailed: string,
15
- urlNotification: string,
16
- serviceDate: string,
17
- client: {
18
- name: string,
19
- lastName: string,
20
- address: string,
21
- phone: string,
22
- email:string,
23
- countryId: number,
24
- termsAndConditions: boolean
25
- },
26
- directPayment: boolean
27
- paymentMethods?:string[]
28
-
29
- }
30
-
31
- export interface PaymentLink extends PaymentLinkPayload {
32
- expirationDate: string,
33
- hasClient:boolean,
34
- updatedAt:string,
35
- createdAt: string,
36
- qrImage: string,
37
- shortUrl: string,
38
- paymentUrl: string
39
-
1
+
2
+ export interface PaymentLinkPayload {
3
+ reference: string,
4
+ concept: string,
5
+ favorite: boolean,
6
+ amount: number,
7
+ currency: string,
8
+ description : string,
9
+ singleUse: boolean,
10
+ reasonId: number,
11
+ expirationDays: number,
12
+ lang:string,
13
+ urlSuccess: string,
14
+ urlFailed: string,
15
+ urlNotification: string,
16
+ serviceDate: string,
17
+ client: {
18
+ name: string,
19
+ lastName: string,
20
+ address: string,
21
+ phone: string,
22
+ email:string,
23
+ countryId: number,
24
+ termsAndConditions: boolean
25
+ },
26
+ directPayment: boolean
27
+ paymentMethods?:string[]
28
+
29
+ }
30
+
31
+ export interface PaymentLink extends PaymentLinkPayload {
32
+ expirationDate: string,
33
+ hasClient:boolean,
34
+ updatedAt:string,
35
+ createdAt: string,
36
+ qrImage: string,
37
+ shortUrl: string,
38
+ paymentUrl: string
39
+
40
40
  }