@yosle/tropipayjs 0.1.10 → 0.1.11
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/api/TropipayAPI.d.ts +2 -2
- package/hooks/TropipayHooks.d.ts +29 -8
- package/index.d.ts +32 -11
- package/index.js +105 -17
- package/interfaces/index.d.ts +1 -1
- package/interfaces/paymentlink/index.d.ts +56 -5
- package/package.json +1 -1
- package/src/api/TropipayAPI.ts +4 -6
- package/src/hooks/TropipayHooks.ts +121 -20
- package/src/index.ts +8 -2
- package/src/interfaces/index.ts +22 -1
- package/src/interfaces/paymentlink/index.ts +86 -35
package/api/TropipayAPI.d.ts
CHANGED
|
@@ -63,8 +63,8 @@ export declare class Tropipay {
|
|
|
63
63
|
*/
|
|
64
64
|
movements(offset?: number, limit?: number): Promise<any>;
|
|
65
65
|
/**
|
|
66
|
-
* Return profile data for
|
|
67
|
-
* @returns
|
|
66
|
+
* Return profile data for current Tropipay account.
|
|
67
|
+
* @returns account object
|
|
68
68
|
*/
|
|
69
69
|
profile(): Promise<any>;
|
|
70
70
|
/**
|
package/hooks/TropipayHooks.d.ts
CHANGED
|
@@ -3,15 +3,36 @@ import { Tropipay } from "../api/TropipayAPI";
|
|
|
3
3
|
export declare class TropipayHooks {
|
|
4
4
|
private tropipay;
|
|
5
5
|
constructor(tropipayInstance: Tropipay);
|
|
6
|
-
static subscribeHook(eventType: HookEventType, target: string, value: string): Promise<void>;
|
|
7
6
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
7
|
+
* Subscribe a new hook
|
|
8
|
+
* @param event String that represents the name of the event,
|
|
9
|
+
* you must select from the list of available events, otherwise
|
|
10
|
+
* it will not produce an error but it will not be executed.
|
|
11
|
+
* For get full list of available events see endpoint
|
|
12
|
+
* GET /api/v2/hook/events.
|
|
13
|
+
* @param target String representing the type of event supported.
|
|
14
|
+
* It is currently available: 'web' (allows to receive information in a url),
|
|
15
|
+
* 'email' (allows to receive information in an email address).
|
|
16
|
+
* @param value if the selected 'target' is email the value would be an
|
|
17
|
+
* email address, likewise if the selected 'target' is 'web' the expected
|
|
18
|
+
* value corresponds to a url that receives information through the
|
|
19
|
+
* HTTP POST method.
|
|
12
20
|
* @returns
|
|
13
21
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
22
|
+
subscribe({ eventType, target, value, }: {
|
|
23
|
+
eventType: HookEventType;
|
|
24
|
+
target: "email" | "web";
|
|
25
|
+
value: string;
|
|
26
|
+
}): Promise<any>;
|
|
27
|
+
/**
|
|
28
|
+
* Get the sucbcribed hook info by his event type.
|
|
29
|
+
* If no event type is passed, it will return
|
|
30
|
+
* all subscribed hooks or empty Array if none exist.
|
|
31
|
+
* @param eventType or no params for retrieving all hooks
|
|
32
|
+
* @returns All subscribed hooks or empty Array if none exist.
|
|
33
|
+
*/
|
|
34
|
+
list(eventType?: HookEventType): Promise<UserHookSubscribed[]>;
|
|
35
|
+
update(eventType: string, target: "web" | "email", value: string): Promise<any>;
|
|
36
|
+
delete(eventType: HookEventType, target: string): Promise<any>;
|
|
37
|
+
events(): Promise<any>;
|
|
17
38
|
}
|
package/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ type TropipayCredentials = {
|
|
|
16
16
|
clientId: string;
|
|
17
17
|
clientSecret: string;
|
|
18
18
|
};
|
|
19
|
-
type HookEventType = "transaction_completed" | "transaction_charged" | "transaction_guarded";
|
|
19
|
+
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";
|
|
20
20
|
type HookTargetType = "web" | "email";
|
|
21
21
|
interface UserHook {
|
|
22
22
|
event: HookEventType;
|
|
@@ -164,17 +164,38 @@ type AccountDeposits = {
|
|
|
164
164
|
declare class TropipayHooks {
|
|
165
165
|
private tropipay;
|
|
166
166
|
constructor(tropipayInstance: Tropipay);
|
|
167
|
-
static subscribeHook(eventType: HookEventType, target: string, value: string): Promise<void>;
|
|
168
167
|
/**
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
168
|
+
* Subscribe a new hook
|
|
169
|
+
* @param event String that represents the name of the event,
|
|
170
|
+
* you must select from the list of available events, otherwise
|
|
171
|
+
* it will not produce an error but it will not be executed.
|
|
172
|
+
* For get full list of available events see endpoint
|
|
173
|
+
* GET /api/v2/hook/events.
|
|
174
|
+
* @param target String representing the type of event supported.
|
|
175
|
+
* It is currently available: 'web' (allows to receive information in a url),
|
|
176
|
+
* 'email' (allows to receive information in an email address).
|
|
177
|
+
* @param value if the selected 'target' is email the value would be an
|
|
178
|
+
* email address, likewise if the selected 'target' is 'web' the expected
|
|
179
|
+
* value corresponds to a url that receives information through the
|
|
180
|
+
* HTTP POST method.
|
|
173
181
|
* @returns
|
|
174
182
|
*/
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
183
|
+
subscribe({ eventType, target, value, }: {
|
|
184
|
+
eventType: HookEventType;
|
|
185
|
+
target: "email" | "web";
|
|
186
|
+
value: string;
|
|
187
|
+
}): Promise<any>;
|
|
188
|
+
/**
|
|
189
|
+
* Get the sucbcribed hook info by his event type.
|
|
190
|
+
* If no event type is passed, it will return
|
|
191
|
+
* all subscribed hooks or empty Array if none exist.
|
|
192
|
+
* @param eventType or no params for retrieving all hooks
|
|
193
|
+
* @returns All subscribed hooks or empty Array if none exist.
|
|
194
|
+
*/
|
|
195
|
+
list(eventType?: HookEventType): Promise<UserHookSubscribed[]>;
|
|
196
|
+
update(eventType: string, target: "web" | "email", value: string): Promise<any>;
|
|
197
|
+
delete(eventType: HookEventType, target: string): Promise<any>;
|
|
198
|
+
events(): Promise<any>;
|
|
178
199
|
}
|
|
179
200
|
|
|
180
201
|
/**
|
|
@@ -241,8 +262,8 @@ declare class Tropipay {
|
|
|
241
262
|
*/
|
|
242
263
|
movements(offset?: number, limit?: number): Promise<any>;
|
|
243
264
|
/**
|
|
244
|
-
* Return profile data for
|
|
245
|
-
* @returns
|
|
265
|
+
* Return profile data for current Tropipay account.
|
|
266
|
+
* @returns account object
|
|
246
267
|
*/
|
|
247
268
|
profile(): Promise<any>;
|
|
248
269
|
/**
|
package/index.js
CHANGED
|
@@ -34,15 +34,52 @@ class TropipayHooks {
|
|
|
34
34
|
constructor(tropipayInstance) {
|
|
35
35
|
this.tropipay = tropipayInstance;
|
|
36
36
|
}
|
|
37
|
-
static async subscribeHook(eventType, target, value) { }
|
|
38
37
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
38
|
+
* Subscribe a new hook
|
|
39
|
+
* @param event String that represents the name of the event,
|
|
40
|
+
* you must select from the list of available events, otherwise
|
|
41
|
+
* it will not produce an error but it will not be executed.
|
|
42
|
+
* For get full list of available events see endpoint
|
|
43
|
+
* GET /api/v2/hook/events.
|
|
44
|
+
* @param target String representing the type of event supported.
|
|
45
|
+
* It is currently available: 'web' (allows to receive information in a url),
|
|
46
|
+
* 'email' (allows to receive information in an email address).
|
|
47
|
+
* @param value if the selected 'target' is email the value would be an
|
|
48
|
+
* email address, likewise if the selected 'target' is 'web' the expected
|
|
49
|
+
* value corresponds to a url that receives information through the
|
|
50
|
+
* HTTP POST method.
|
|
43
51
|
* @returns
|
|
44
52
|
*/
|
|
45
|
-
async
|
|
53
|
+
async subscribe({ eventType, target, value, }) {
|
|
54
|
+
if (!Tropipay.accessToken) {
|
|
55
|
+
await this.tropipay.login();
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const hooks = await this.tropipay.request.post(`/api/v2/hooks`, {
|
|
59
|
+
event: eventType,
|
|
60
|
+
target: target,
|
|
61
|
+
value: value,
|
|
62
|
+
}, {
|
|
63
|
+
headers: {
|
|
64
|
+
"Content-Type": "application/json",
|
|
65
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
66
|
+
Accept: "application/json",
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
return hooks.data;
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
throw new Error(`Could not get subscribe new hook`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get the sucbcribed hook info by his event type.
|
|
77
|
+
* If no event type is passed, it will return
|
|
78
|
+
* all subscribed hooks or empty Array if none exist.
|
|
79
|
+
* @param eventType or no params for retrieving all hooks
|
|
80
|
+
* @returns All subscribed hooks or empty Array if none exist.
|
|
81
|
+
*/
|
|
82
|
+
async list(eventType) {
|
|
46
83
|
if (!Tropipay.accessToken) {
|
|
47
84
|
await this.tropipay.login();
|
|
48
85
|
}
|
|
@@ -57,16 +94,67 @@ class TropipayHooks {
|
|
|
57
94
|
return hooks.data;
|
|
58
95
|
}
|
|
59
96
|
catch (error) {
|
|
60
|
-
throw new Error(`Could not get subscribed hooks
|
|
97
|
+
throw new Error(`Could not get subscribed hooks`);
|
|
61
98
|
}
|
|
62
99
|
}
|
|
63
|
-
async
|
|
64
|
-
|
|
65
|
-
|
|
100
|
+
async update(eventType, target, value) {
|
|
101
|
+
if (!Tropipay.accessToken) {
|
|
102
|
+
await this.tropipay.login();
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
const hooks = await this.tropipay.request.put(`/api/v2/hooks`, {
|
|
106
|
+
event: eventType,
|
|
107
|
+
target: target,
|
|
108
|
+
value: value,
|
|
109
|
+
}, {
|
|
110
|
+
headers: {
|
|
111
|
+
"Content-Type": "application/json",
|
|
112
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
113
|
+
Accept: "application/json",
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
return hooks.data;
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
throw new Error(`Could not update subscribed hooks`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async delete(eventType, target) {
|
|
123
|
+
if (!Tropipay.accessToken) {
|
|
124
|
+
await this.tropipay.login();
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
const hooks = await this.tropipay.request.delete(`/api/v2/hooks/${eventType}/${target}`, {
|
|
128
|
+
headers: {
|
|
129
|
+
"Content-Type": "application/json",
|
|
130
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
131
|
+
Accept: "application/json",
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
return hooks.data;
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
console.trace(error);
|
|
138
|
+
throw new Error(`Could not delete subscribed hooks`);
|
|
139
|
+
}
|
|
66
140
|
}
|
|
67
|
-
async
|
|
68
|
-
|
|
69
|
-
|
|
141
|
+
async events() {
|
|
142
|
+
if (!Tropipay.accessToken) {
|
|
143
|
+
await this.tropipay.login();
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
const hooks = await this.tropipay.request.get(`/api/v2/hooks/events`, {
|
|
147
|
+
headers: {
|
|
148
|
+
"Content-Type": "application/json",
|
|
149
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
150
|
+
Accept: "application/json",
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
return hooks.data;
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
throw new Error(`Could not get events list for hooks ${error}`);
|
|
157
|
+
}
|
|
70
158
|
}
|
|
71
159
|
}
|
|
72
160
|
|
|
@@ -145,7 +233,7 @@ class Tropipay {
|
|
|
145
233
|
return paylink.data;
|
|
146
234
|
}
|
|
147
235
|
catch (error) {
|
|
148
|
-
throw new Error(`
|
|
236
|
+
throw new Error(`TropipayJS - Error creating the Payment Card.`);
|
|
149
237
|
}
|
|
150
238
|
}
|
|
151
239
|
/**
|
|
@@ -270,8 +358,8 @@ class Tropipay {
|
|
|
270
358
|
}
|
|
271
359
|
}
|
|
272
360
|
/**
|
|
273
|
-
* Return profile data for
|
|
274
|
-
* @returns
|
|
361
|
+
* Return profile data for current Tropipay account.
|
|
362
|
+
* @returns account object
|
|
275
363
|
*/
|
|
276
364
|
async profile() {
|
|
277
365
|
if (!Tropipay.accessToken)
|
|
@@ -336,7 +424,7 @@ class Tropipay {
|
|
|
336
424
|
return mediation.data;
|
|
337
425
|
}
|
|
338
426
|
catch (error) {
|
|
339
|
-
throw new Error(`Could not
|
|
427
|
+
throw new Error(`Could not create mediation payment card`);
|
|
340
428
|
}
|
|
341
429
|
}
|
|
342
430
|
}
|
package/interfaces/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export type TropipayCredentials = {
|
|
|
13
13
|
clientId: string;
|
|
14
14
|
clientSecret: string;
|
|
15
15
|
};
|
|
16
|
-
export type HookEventType = "transaction_completed" | "transaction_charged" | "transaction_guarded";
|
|
16
|
+
export 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";
|
|
17
17
|
export type HookTargetType = "web" | "email";
|
|
18
18
|
export interface UserHook {
|
|
19
19
|
event: HookEventType;
|
|
@@ -1,3 +1,50 @@
|
|
|
1
|
+
type PaymentMethodElement = "EXT" | "TPP";
|
|
2
|
+
export type PaymentMethods = Element | [PaymentMethodElement, PaymentMethodElement];
|
|
3
|
+
declare enum Reasons {
|
|
4
|
+
HOUSING_ARRANGEMENT = 1,
|
|
5
|
+
FINANCIAL_AID = 2,
|
|
6
|
+
FAMILY_SUPPORT = 3,
|
|
7
|
+
TRAVEL_FUND = 4,
|
|
8
|
+
REAL_ESTATE_PURCHASE = 5,
|
|
9
|
+
FURNITURE_PURCHASE = 6,
|
|
10
|
+
EDUCATION = 7,
|
|
11
|
+
MEDICAL_EXPENSES = 8,
|
|
12
|
+
OTHER = 9,
|
|
13
|
+
DEBT_PAYMENT = 10,
|
|
14
|
+
TOURISM = 11,
|
|
15
|
+
SELF_SHIPPING = 12,
|
|
16
|
+
ACCOUNT_ACTIVATION = 13,
|
|
17
|
+
SPORTS_ACTIVITIES = 14,
|
|
18
|
+
DONATION = 15,
|
|
19
|
+
AFFILIATE_COMMISSION = 16,
|
|
20
|
+
SALARY = 17,
|
|
21
|
+
SAVINGS = 18,
|
|
22
|
+
RENT_AND_LEASING = 19,
|
|
23
|
+
SHARED_EXPENSES = 20,
|
|
24
|
+
SERVICE_PAYMENT = 21,
|
|
25
|
+
GIFT = 22,
|
|
26
|
+
CRYPTOCURRENCY_PURCHASE = 23,
|
|
27
|
+
OPERATING_EXPENSES = 24,
|
|
28
|
+
CURRENCY_EXCHANGE = 25,
|
|
29
|
+
ACCOMMODATION = 26,
|
|
30
|
+
EQUIPMENT_PURCHASE = 27,
|
|
31
|
+
CONSULTING = 28,
|
|
32
|
+
SOFTWARE_DEVELOPMENT = 29,
|
|
33
|
+
REFUND = 30,
|
|
34
|
+
PACKAGE_DELIVERY = 31,
|
|
35
|
+
PERSONAL_EXPENSES = 32,
|
|
36
|
+
INVESTMENT = 33,
|
|
37
|
+
BILL_PAYMENT = 34,
|
|
38
|
+
HOST_PAYMENT = 35,
|
|
39
|
+
TRANSPORTATION = 36,
|
|
40
|
+
LOAN = 37,
|
|
41
|
+
BONUS = 38,
|
|
42
|
+
HALLOWEEN_REMITTANCE = 39,
|
|
43
|
+
PLINK_REMITTANCE = 41,
|
|
44
|
+
R1_2023 = 78,
|
|
45
|
+
HAPPYWEEK = 79,
|
|
46
|
+
SENDING_YOU_A_KISS = 80
|
|
47
|
+
}
|
|
1
48
|
export interface PaymentLinkPayload {
|
|
2
49
|
reference: string;
|
|
3
50
|
concept: string;
|
|
@@ -6,14 +53,17 @@ export interface PaymentLinkPayload {
|
|
|
6
53
|
currency: string;
|
|
7
54
|
description: string;
|
|
8
55
|
singleUse: boolean;
|
|
9
|
-
reasonId:
|
|
56
|
+
reasonId: Reasons;
|
|
10
57
|
expirationDays: number;
|
|
11
58
|
lang: string;
|
|
12
59
|
urlSuccess: string;
|
|
13
60
|
urlFailed: string;
|
|
14
61
|
urlNotification: string;
|
|
15
62
|
serviceDate: string;
|
|
16
|
-
|
|
63
|
+
/**
|
|
64
|
+
* fgfsgdfgdfgd
|
|
65
|
+
*/
|
|
66
|
+
client?: {
|
|
17
67
|
name: string;
|
|
18
68
|
lastName: string;
|
|
19
69
|
address: string;
|
|
@@ -21,9 +71,9 @@ export interface PaymentLinkPayload {
|
|
|
21
71
|
email: string;
|
|
22
72
|
countryId: number;
|
|
23
73
|
termsAndConditions: boolean;
|
|
24
|
-
};
|
|
25
|
-
directPayment
|
|
26
|
-
paymentMethods?:
|
|
74
|
+
} | null;
|
|
75
|
+
directPayment?: boolean;
|
|
76
|
+
paymentMethods?: PaymentMethods;
|
|
27
77
|
}
|
|
28
78
|
export interface PaymentLink extends PaymentLinkPayload {
|
|
29
79
|
expirationDate: string;
|
|
@@ -34,3 +84,4 @@ export interface PaymentLink extends PaymentLinkPayload {
|
|
|
34
84
|
shortUrl: string;
|
|
35
85
|
paymentUrl: string;
|
|
36
86
|
}
|
|
87
|
+
export {};
|
package/package.json
CHANGED
package/src/api/TropipayAPI.ts
CHANGED
|
@@ -99,9 +99,7 @@ export class Tropipay {
|
|
|
99
99
|
});
|
|
100
100
|
return paylink.data as PaymentLink;
|
|
101
101
|
} catch (error) {
|
|
102
|
-
throw new Error(
|
|
103
|
-
`Could not obtain the access token with the given credentials.`
|
|
104
|
-
);
|
|
102
|
+
throw new Error(`TropipayJS - Error creating the Payment Card.`);
|
|
105
103
|
}
|
|
106
104
|
}
|
|
107
105
|
|
|
@@ -233,8 +231,8 @@ export class Tropipay {
|
|
|
233
231
|
}
|
|
234
232
|
|
|
235
233
|
/**
|
|
236
|
-
* Return profile data for
|
|
237
|
-
* @returns
|
|
234
|
+
* Return profile data for current Tropipay account.
|
|
235
|
+
* @returns account object
|
|
238
236
|
*/
|
|
239
237
|
async profile() {
|
|
240
238
|
if (!Tropipay.accessToken) await this.login();
|
|
@@ -309,7 +307,7 @@ export class Tropipay {
|
|
|
309
307
|
);
|
|
310
308
|
return mediation.data as PaymentLink;
|
|
311
309
|
} catch (error) {
|
|
312
|
-
throw new Error(`Could not
|
|
310
|
+
throw new Error(`Could not create mediation payment card`);
|
|
313
311
|
}
|
|
314
312
|
}
|
|
315
313
|
}
|
|
@@ -6,22 +6,63 @@ export class TropipayHooks {
|
|
|
6
6
|
constructor(tropipayInstance: Tropipay) {
|
|
7
7
|
this.tropipay = tropipayInstance;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
public static async subscribeHook(
|
|
11
|
-
eventType: HookEventType,
|
|
12
|
-
target: string,
|
|
13
|
-
value: string
|
|
14
|
-
) {}
|
|
15
9
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
10
|
+
* Subscribe a new hook
|
|
11
|
+
* @param event String that represents the name of the event,
|
|
12
|
+
* you must select from the list of available events, otherwise
|
|
13
|
+
* it will not produce an error but it will not be executed.
|
|
14
|
+
* For get full list of available events see endpoint
|
|
15
|
+
* GET /api/v2/hook/events.
|
|
16
|
+
* @param target String representing the type of event supported.
|
|
17
|
+
* It is currently available: 'web' (allows to receive information in a url),
|
|
18
|
+
* 'email' (allows to receive information in an email address).
|
|
19
|
+
* @param value if the selected 'target' is email the value would be an
|
|
20
|
+
* email address, likewise if the selected 'target' is 'web' the expected
|
|
21
|
+
* value corresponds to a url that receives information through the
|
|
22
|
+
* HTTP POST method.
|
|
20
23
|
* @returns
|
|
21
24
|
*/
|
|
22
|
-
public async
|
|
23
|
-
eventType
|
|
24
|
-
|
|
25
|
+
public async subscribe({
|
|
26
|
+
eventType,
|
|
27
|
+
target,
|
|
28
|
+
value,
|
|
29
|
+
}: {
|
|
30
|
+
eventType: HookEventType;
|
|
31
|
+
target: "email" | "web";
|
|
32
|
+
value: string;
|
|
33
|
+
}) {
|
|
34
|
+
if (!Tropipay.accessToken) {
|
|
35
|
+
await this.tropipay.login();
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const hooks = await this.tropipay.request.post(
|
|
39
|
+
`/api/v2/hooks`,
|
|
40
|
+
{
|
|
41
|
+
event: eventType,
|
|
42
|
+
target: target,
|
|
43
|
+
value: value,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
headers: {
|
|
47
|
+
"Content-Type": "application/json",
|
|
48
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
49
|
+
Accept: "application/json",
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
return hooks.data;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
throw new Error(`Could not get subscribe new hook`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get the sucbcribed hook info by his event type.
|
|
60
|
+
* If no event type is passed, it will return
|
|
61
|
+
* all subscribed hooks or empty Array if none exist.
|
|
62
|
+
* @param eventType or no params for retrieving all hooks
|
|
63
|
+
* @returns All subscribed hooks or empty Array if none exist.
|
|
64
|
+
*/
|
|
65
|
+
public async list(eventType?: HookEventType): Promise<UserHookSubscribed[]> {
|
|
25
66
|
if (!Tropipay.accessToken) {
|
|
26
67
|
await this.tropipay.login();
|
|
27
68
|
}
|
|
@@ -38,15 +79,75 @@ export class TropipayHooks {
|
|
|
38
79
|
);
|
|
39
80
|
return hooks.data;
|
|
40
81
|
} catch (error) {
|
|
41
|
-
throw new Error(`Could not get subscribed hooks
|
|
82
|
+
throw new Error(`Could not get subscribed hooks`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
public async update(
|
|
86
|
+
eventType: string,
|
|
87
|
+
target: "web" | "email",
|
|
88
|
+
value: string
|
|
89
|
+
) {
|
|
90
|
+
if (!Tropipay.accessToken) {
|
|
91
|
+
await this.tropipay.login();
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const hooks = await this.tropipay.request.put(
|
|
95
|
+
`/api/v2/hooks`,
|
|
96
|
+
{
|
|
97
|
+
event: eventType,
|
|
98
|
+
target: target,
|
|
99
|
+
value: value,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
headers: {
|
|
103
|
+
"Content-Type": "application/json",
|
|
104
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
105
|
+
Accept: "application/json",
|
|
106
|
+
},
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
return hooks.data;
|
|
110
|
+
} catch (error) {
|
|
111
|
+
throw new Error(`Could not update subscribed hooks`);
|
|
42
112
|
}
|
|
43
113
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
114
|
+
async delete(eventType: HookEventType, target: string) {
|
|
115
|
+
if (!Tropipay.accessToken) {
|
|
116
|
+
await this.tropipay.login();
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
const hooks = await this.tropipay.request.delete(
|
|
120
|
+
`/api/v2/hooks/${eventType}/${target}`,
|
|
121
|
+
{
|
|
122
|
+
headers: {
|
|
123
|
+
"Content-Type": "application/json",
|
|
124
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
125
|
+
Accept: "application/json",
|
|
126
|
+
},
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
return hooks.data;
|
|
130
|
+
} catch (error) {
|
|
131
|
+
console.trace(error);
|
|
132
|
+
throw new Error(`Could not delete subscribed hooks`);
|
|
133
|
+
}
|
|
47
134
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
135
|
+
|
|
136
|
+
async events() {
|
|
137
|
+
if (!Tropipay.accessToken) {
|
|
138
|
+
await this.tropipay.login();
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
const hooks = await this.tropipay.request.get(`/api/v2/hooks/events`, {
|
|
142
|
+
headers: {
|
|
143
|
+
"Content-Type": "application/json",
|
|
144
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
145
|
+
Accept: "application/json",
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
return hooks.data;
|
|
149
|
+
} catch (error) {
|
|
150
|
+
throw new Error(`Could not get events list for hooks ${error}`);
|
|
151
|
+
}
|
|
51
152
|
}
|
|
52
153
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* TropipayJS is a powerful TypeScript/JavaScript library designed to provide seamless interaction
|
|
3
|
+
* with the Tropipay API. It simplifies the process of integrating Tropipay's functionality into
|
|
4
|
+
* your applications.
|
|
3
5
|
*
|
|
4
|
-
*
|
|
6
|
+
* Developed by Yosleivy Baez Acosta
|
|
7
|
+
* GitHub: https://github.com/yosle/tropipayjs
|
|
5
8
|
*
|
|
9
|
+
* @version 0.1.11
|
|
10
|
+
* @license MIT
|
|
6
11
|
*/
|
|
12
|
+
|
|
7
13
|
export { Tropipay } from "./api/TropipayAPI";
|
|
8
14
|
export { ClientSideUtils } from "./api/TropipayAPI";
|
|
9
15
|
export { ServerSideUtils } from "./utils/TropipayUtils";
|
package/src/interfaces/index.ts
CHANGED
|
@@ -16,7 +16,28 @@ export type TropipayCredentials = { clientId: string; clientSecret: string };
|
|
|
16
16
|
export type HookEventType =
|
|
17
17
|
| "transaction_completed"
|
|
18
18
|
| "transaction_charged"
|
|
19
|
-
| "transaction_guarded"
|
|
19
|
+
| "transaction_guarded"
|
|
20
|
+
| "user_signup"
|
|
21
|
+
| "user_kyc"
|
|
22
|
+
| "payment_in_state_change"
|
|
23
|
+
| "payment_out_state_change"
|
|
24
|
+
| "beneficiary_added"
|
|
25
|
+
| "beneficiary_updated"
|
|
26
|
+
| "beneficiary_deleted"
|
|
27
|
+
| "transaction_new"
|
|
28
|
+
| "transaction_preauthorized"
|
|
29
|
+
| "transaction_pendingin"
|
|
30
|
+
| "transaction_processing"
|
|
31
|
+
| "transaction_error"
|
|
32
|
+
| "transaction_bloqued"
|
|
33
|
+
| "transaction_guarded_send"
|
|
34
|
+
| "transaction_guarded_mediation"
|
|
35
|
+
| "user_after_update"
|
|
36
|
+
| "user_after_create"
|
|
37
|
+
| "userDetail_after_create"
|
|
38
|
+
| "userDetail_after_update"
|
|
39
|
+
| "tpv_callback_ok"
|
|
40
|
+
| "fraud_state_on_change";
|
|
20
41
|
|
|
21
42
|
export type HookTargetType = "web" | "email";
|
|
22
43
|
export interface UserHook {
|
|
@@ -1,40 +1,91 @@
|
|
|
1
|
+
type PaymentMethodElement = "EXT" | "TPP";
|
|
2
|
+
export type PaymentMethods =
|
|
3
|
+
| Element
|
|
4
|
+
| [PaymentMethodElement, PaymentMethodElement];
|
|
1
5
|
|
|
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
|
-
|
|
6
|
+
enum Reasons {
|
|
7
|
+
HOUSING_ARRANGEMENT = 1,
|
|
8
|
+
FINANCIAL_AID = 2,
|
|
9
|
+
FAMILY_SUPPORT = 3,
|
|
10
|
+
TRAVEL_FUND = 4,
|
|
11
|
+
REAL_ESTATE_PURCHASE = 5,
|
|
12
|
+
FURNITURE_PURCHASE = 6,
|
|
13
|
+
EDUCATION = 7,
|
|
14
|
+
MEDICAL_EXPENSES = 8,
|
|
15
|
+
OTHER = 9,
|
|
16
|
+
DEBT_PAYMENT = 10,
|
|
17
|
+
TOURISM = 11,
|
|
18
|
+
SELF_SHIPPING = 12,
|
|
19
|
+
ACCOUNT_ACTIVATION = 13,
|
|
20
|
+
SPORTS_ACTIVITIES = 14,
|
|
21
|
+
DONATION = 15,
|
|
22
|
+
AFFILIATE_COMMISSION = 16,
|
|
23
|
+
SALARY = 17,
|
|
24
|
+
SAVINGS = 18,
|
|
25
|
+
RENT_AND_LEASING = 19,
|
|
26
|
+
SHARED_EXPENSES = 20,
|
|
27
|
+
SERVICE_PAYMENT = 21,
|
|
28
|
+
GIFT = 22,
|
|
29
|
+
CRYPTOCURRENCY_PURCHASE = 23,
|
|
30
|
+
OPERATING_EXPENSES = 24,
|
|
31
|
+
CURRENCY_EXCHANGE = 25,
|
|
32
|
+
ACCOMMODATION = 26,
|
|
33
|
+
EQUIPMENT_PURCHASE = 27,
|
|
34
|
+
CONSULTING = 28,
|
|
35
|
+
SOFTWARE_DEVELOPMENT = 29,
|
|
36
|
+
REFUND = 30,
|
|
37
|
+
PACKAGE_DELIVERY = 31,
|
|
38
|
+
PERSONAL_EXPENSES = 32,
|
|
39
|
+
INVESTMENT = 33,
|
|
40
|
+
BILL_PAYMENT = 34,
|
|
41
|
+
HOST_PAYMENT = 35,
|
|
42
|
+
TRANSPORTATION = 36,
|
|
43
|
+
LOAN = 37,
|
|
44
|
+
BONUS = 38,
|
|
45
|
+
HALLOWEEN_REMITTANCE = 39,
|
|
46
|
+
PLINK_REMITTANCE = 41,
|
|
47
|
+
R1_2023 = 78,
|
|
48
|
+
HAPPYWEEK = 79,
|
|
49
|
+
SENDING_YOU_A_KISS = 80,
|
|
50
|
+
}
|
|
28
51
|
|
|
52
|
+
export interface PaymentLinkPayload {
|
|
53
|
+
reference: string;
|
|
54
|
+
concept: string;
|
|
55
|
+
favorite: boolean;
|
|
56
|
+
amount: number;
|
|
57
|
+
currency: string;
|
|
58
|
+
description: string;
|
|
59
|
+
singleUse: boolean;
|
|
60
|
+
reasonId: Reasons;
|
|
61
|
+
expirationDays: number;
|
|
62
|
+
lang: string;
|
|
63
|
+
urlSuccess: string;
|
|
64
|
+
urlFailed: string;
|
|
65
|
+
urlNotification: string;
|
|
66
|
+
serviceDate: string;
|
|
67
|
+
/**
|
|
68
|
+
* fgfsgdfgdfgd
|
|
69
|
+
*/
|
|
70
|
+
client?: {
|
|
71
|
+
name: string;
|
|
72
|
+
lastName: string;
|
|
73
|
+
address: string;
|
|
74
|
+
phone: string;
|
|
75
|
+
email: string;
|
|
76
|
+
countryId: number;
|
|
77
|
+
termsAndConditions: boolean;
|
|
78
|
+
} | null;
|
|
79
|
+
directPayment?: boolean;
|
|
80
|
+
paymentMethods?: PaymentMethods;
|
|
29
81
|
}
|
|
30
82
|
|
|
31
83
|
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
|
-
}
|
|
84
|
+
expirationDate: string;
|
|
85
|
+
hasClient: boolean;
|
|
86
|
+
updatedAt: string;
|
|
87
|
+
createdAt: string;
|
|
88
|
+
qrImage: string;
|
|
89
|
+
shortUrl: string;
|
|
90
|
+
paymentUrl: string;
|
|
91
|
+
}
|