-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.d.ts
458 lines (445 loc) · 15 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
import { Axios } from 'axios';
type ServerMode$1 = "Development" | "Production";
declare const MAX_IMAGE_SIZE_MB = 1;
type AccountBalance = {
balance: number;
pendingIn: number;
pendingOut: number;
};
interface TropipayConfig {
clientId: string;
clientSecret: string;
scopes?: string[];
serverMode?: ServerMode$1;
customTropipayUrl?: string;
}
type TropipayCredentials = {
clientId: string;
clientSecret: string;
};
type HookEventType = "transaction_completed" | "transaction_charged" | "transaction_guarded" | "user_signup" | "user_kyc" | "payment_in_state_change" | "payment_out_state_change" | "beneficiary_added" | "beneficiary_updated" | "beneficiary_deleted" | "transaction_new" | "transaction_preauthorized" | "transaction_pendingin" | "transaction_processing" | "transaction_error" | "transaction_bloqued" | "transaction_guarded_send" | "transaction_guarded_mediation" | "user_after_update" | "user_after_create" | "userDetail_after_create" | "userDetail_after_update" | "tpv_callback_ok" | "fraud_state_on_change";
type HookTargetType = "web" | "email";
interface UserHook {
event: HookEventType;
target: string;
value: string;
}
interface UserHook {
event: HookEventType;
target: string;
value: string;
}
interface UserHookSubscribed extends UserHook {
createdAt: string;
updatedAt: string;
}
interface UserHookSubscribed extends UserHook {
createdAt: string;
updatedAt: string;
}
interface PaymentLinkPayload {
reference: string;
concept: string;
favorite: boolean;
amount: number;
currency: string;
description: string;
singleUse: boolean;
reasonId: number;
expirationDays: number;
lang: string;
urlSuccess: string;
urlFailed: string;
urlNotification: string;
serviceDate: string;
client?: {
name?: string;
lastName?: string;
address?: string;
phone?: string;
email?: string;
countryId?: number;
countryIso?: string;
city: string;
postCode: string;
termsAndConditions: boolean;
} | null;
directPayment: boolean;
paymentMethods?: string[];
imageBase?: string;
saveToken?: boolean;
}
interface PaymentLink extends PaymentLinkPayload {
expirationDate: string;
hasClient: boolean;
updatedAt: string;
createdAt: string;
qrImage: string;
shortUrl: string;
paymentUrl: string;
}
interface MediationPaymentCardConfig {
amount: number;
currency: "EUR" | "USD";
concept: string;
description: string;
reference: string;
singleUse: boolean;
lang: string;
productUrl?: string;
buyer: null | any;
seller: {
sellerId?: number;
type?: number;
email?: string;
};
feePercent?: number;
feeFixed?: number;
sendMail: boolean;
}
type LoginResponse = {
access_token: string;
refresh_token: string;
token_type: "Bearer";
expires_in: number;
scope: string;
};
type LoginError = {
error: string;
};
type Country = {
id: number;
name: string;
sepaZone: boolean;
state: number;
slug: string;
slugn: number;
callingCode: number;
isDestination: boolean;
isRisky: boolean;
currentCurrency: string | null;
createdAt: string;
updatedAt: string;
isFavorite: boolean;
position: any;
};
type Deposit = {
id: number;
accountNumber: string;
alias: string;
swift: string;
type: number;
country: number | null;
firstName: string;
default: null;
state: number;
userId: string;
countryDestinationId: number;
lastName: string;
documentNumber: number;
userRelationTypeId: number;
city: string;
postalCode: string;
address: string;
phone: string;
checked: boolean;
province: string;
beneficiaryType: number;
relatedUserId: null | string;
currency: string;
correspondent?: any;
location: any;
office: any;
officeValue: any;
paymentType: number;
paymentEntityBeneficiaryId: number;
paymentEntityAccountId: number;
verified: any;
paymentEntityInfo: any;
documentTypeId: any;
documentExpirationDate: Date;
createdAt: Date;
updatedAt: Date;
countryDestination: Country;
};
type AccountDeposits = {
count: number;
rows: Deposit[];
};
declare class TropipayHooks {
private tropipay;
constructor(tropipayInstance: Tropipay);
/**
* Subscribe a new hook
* @param event String that represents the name of the event,
* you must select from the list of available events, otherwise
* it will not produce an error but it will not be executed.
* For get full list of available events see endpoint
* GET /api/v2/hook/events.
* @param target String representing the type of event supported.
* It is currently available: 'web' (allows to receive information in a url),
* 'email' (allows to receive information in an email address).
* @param value if the selected 'target' is email the value would be an
* email address, likewise if the selected 'target' is 'web' the expected
* value corresponds to a url that receives information through the
* HTTP POST method.
* @returns
*/
subscribe({ eventType, target, value, }: {
eventType: HookEventType;
target: "email" | "web";
value: string;
}): Promise<any>;
/**
* Get the subscribed hook info by his event type.
* If no event type is passed, it will return
* all subscribed hooks or empty Array if none exist.
* @param eventType or no params for retrieving all hooks
* @returns All subscribed hooks or empty Array if none exist.
*/
list(eventType?: HookEventType): Promise<UserHookSubscribed[]>;
update(eventType: HookEventType, target: "web" | "email", value: string): Promise<any>;
delete(eventType: HookEventType, target: string): Promise<any>;
events(): Promise<any>;
}
declare class PaymentCard {
private tropipay;
constructor(tropipayInstance: Tropipay);
/**
* Create a paymentLink with the specified options.
* @param payload PaymentLinkPayload Object.
* @returns Promise<PaymentLink> or throws an Exception.
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
*/
create(payload: PaymentLinkPayload): Promise<PaymentLink>;
/**
* Shows a list of stored paymentcards created by user.
* This list includes active and closed paylinks
* @returns Array of paymentlinks
*/
list(): Promise<any>;
/**
* Retrieves a payment card with the specified ID.
*
* @param {string} id - The ID of the payment card to retrieve.
* @return {Promise<any>} A Promise that resolves to the payment card data.
* @throws {Error} If an error occurs while retrieving the payment card.
*/
get(id: string): Promise<any>;
/**
* Deletes a payment card with the specified ID. Its a LOGIC delete
* so this will delete the paymentcard from paymentcard list and
* disable shortUrl but not paymentUrl
* @param {string} id - The ID of the payment card to delete.
* @return {Promise<any>} A Promise that resolves to the deleted payment card data.
* @throws {Error} If an error occurs while deleting the payment card.
*/
delete(id: string): Promise<any>;
}
declare class MediationPaymentCard {
private tropipay;
constructor(tropipayInstance: Tropipay);
/**
* (ONLY FOR BUSINESS ACCOUNTS) Create a mediation paymentcard (an escrow payment link) with the specified options.
* This allows a payment to be made to persons belonging or not to the TropiPay platform with the
* particularity that the payment will be held in custody or retained until it is released with
* the approval of the payer.
* @param payload PaymentLinkPayload Object.
* @returns Promise<PaymentLink> or throws an Exception.
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/12a128ff971e4-creating-a-mediation-payment-card
*/
create(payload: MediationPaymentCardConfig): Promise<PaymentLink>;
}
interface DepositAccountConfig {
searchValue?: string;
alias: string;
userRelationTypeId: number;
beneficiaryType: BeneficiaryType;
searchBy?: number;
accountNumber?: string;
swift?: string;
type: DepositAccountType;
firstName?: string;
lastName?: string;
secondLastName?: string;
countryDestinationId?: number;
city?: string;
postalCode?: number;
address?: string;
documentNumber?: string;
phone?: string;
province?: string;
paymentType?: string;
documentTypeId?: number;
documentExpirationDate: string;
}
type INTERNAL = 1;
type EXTERNAL = 2;
type BeneficiaryType = INTERNAL | EXTERNAL;
type DepositAccountType = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11;
declare class DepositAccounts {
private tropipay;
constructor(tropipayInstance: Tropipay);
/**
* List od all beneficiaries of this account
* @returns Array of DepositAccounts
*/
list(): Promise<any>;
/**
* Adds a new beneficiary to the user account.
* @param payload
* @returns
*/
create(depositAccountObj: DepositAccountConfig): Promise<any>;
/**
* This returns details of a specific
* Deposit Account (beneficiary) specified by its ID
* @param id
* @returns
*/
get(id: string): Promise<any>;
/**
* Updates certain beneficiary data.
* @param depositAccountObj
* @returns
*/
update(depositAccountObj: Partial<DepositAccountConfig>): Promise<any>;
/**
* (UNTESTED) Deletes the beneficiary indicated by id
* @param id
* @returns
*/
delete(id: number): Promise<any>;
}
/**
* Tropipayjs is a Typescript/Javascript library for the Tropipay API.
*
* @author Yosleivy Baez Acosta
*
*/
type ServerMode = "Development" | "Production";
declare class Tropipay {
readonly clientId: string;
readonly clientSecret: string;
readonly scopes: String[];
request: Axios;
static accessToken: string | null;
static refreshToken: string | null;
static expiresIn: number | null;
serverMode: ServerMode;
hooks: TropipayHooks;
paymentCards: PaymentCard;
depositAccounts: DepositAccounts;
mediationPaymentCard: MediationPaymentCard;
/**
* Initializes a new instance of the Tropipay class.
*
* @param {TropipayConfig} config - The configuration object.
*/
constructor(config: TropipayConfig);
login(): Promise<LoginResponse>;
/**
* Get the list of all supported countries by Tropipay.
* @returns Array of Countries Data
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/bfac21259e2ff-getting-users-countries-list
*/
countries(): Promise<Country[]>;
/**
* Get user balance
* @returns balance Object { balance: number, pendingIn: number, pendingOut: number }
*/
getBalance(): Promise<AccountBalance>;
/**
* Get the list of all detination countries supported by Tropipay.
* Obtaining the list of valid countries to send funds to. Useful
* when adding new beneficiaries to some user.
*
* @returns Array of Country Objects
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/3cfe5504f0524-getting-list-of-beneficiary-countries
*/
destinations(): Promise<Country[]>;
/**
* Get list of all the favorites payment links.
* @returns Array of account Object or throws an error
*/
favorites(): Promise<any>;
/**
* List all account movements. You can optionaly specify
* offset and limit params for pagination.
* @returns
*/
movements(offset?: number, limit?: number): Promise<any>;
/**
* Return profile data for current Tropipay account.
* @returns account object
*/
profile(): Promise<any>;
/**
* Obtain current Tropipay conversion rate. For example USD to EUR
* targetCurrency must be 'EUR'
* @param originCurrency Target currency code supported by Tropipay.
* @param targetCurrency Must be 'EUR'? (not documented by Tropipay)
* @returns Conversion rate (number)
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/85163f6f28b23-get-rate
*/
rates(originCurrency: string, targetCurrency?: string): Promise<number | Error>;
/**
* (ONLY in Bussiness Accounts)
* An escrow payment link. This allows a payment to be made to persons
* belonging or not to the TropiPay platform with the particularity
* that the payment will be held in custody or retained until it is
* released with the approval of the payer.
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/12a128ff971e4-creating-a-mediation-payment-card
* @param config Payload with the payment details
*/
createMediationPaymentCard(config: MediationPaymentCardConfig): Promise<PaymentLink>;
}
declare class ClientSideUtils {
constructor(tropipayInstance: Tropipay);
}
declare class ServerSideUtils {
private tropipay;
constructor(tropipayInstance: Tropipay);
/**
* Verify Topipay's signature on webhooks.
* @param credentials Credential object or Tropipay instance
* @param {String} originalCurrencyAmount
* @param bankOrderCode
* @param signature
* @returns {Boolean}
*/
static verifySignature(credentials: {
clientId: string;
clientSecret: string;
} | Tropipay, originalCurrencyAmount: string, bankOrderCode: string, signature: string): boolean;
/**
* Checks if the provided base64 string represents a square image.
*
* @param {string} base64String - The base64 string of the image
* @return {Promise<boolean>} A Promise that resolves to a boolean indicating whether the image is square
*/
static isBase64ImageSquare(base64String: string): Promise<boolean>;
/**
* Takes a local file path and returns a base64 representation of the file content.
*
* @param {string} filepath - the path of the file to be converted to base64
* @return {Promise<string>} a Promise that resolves to the base64 representation of the file content
*/
static fileToBase64(filepath: string): Promise<string>;
/**
* Get the base64 representation of a remote file from the given URL.
*
* @param {string} url - the URL of the file
* @return {Promise<string>} the base64 representation of the file
*/
static getBase64FromFileUrl(url: string): Promise<string>;
/**
* Check if the base64 string represents a valid image and has a valid size
*
* @param {string} base64Image - the base64 image to be validated
* @return {Promise<string>} the valid base64 image
*/
static isValidImage(base64Image: string): boolean;
}
declare const SERVER_MODE: ServerMode$1;
export { AccountBalance, AccountDeposits, ClientSideUtils, Country, Deposit, HookEventType, HookTargetType, LoginError, LoginResponse, MAX_IMAGE_SIZE_MB, MediationPaymentCardConfig, PaymentLink, PaymentLinkPayload, SERVER_MODE, ServerMode$1 as ServerMode, ServerSideUtils, Tropipay, TropipayConfig, TropipayCredentials, UserHook, UserHookSubscribed };