@yosle/tropipayjs 0.1.10 → 0.1.12
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 +3 -10
- package/docs/.nojekyll +0 -0
- package/docs/404.html +17 -0
- package/docs/assets/css/styles.5c8c3f00.css +1 -0
- package/docs/assets/images/docsVersionDropdown-35e13cbe46c9923327f30a76a90bff3b.png +0 -0
- package/docs/assets/images/docusaurus-plushie-banner-a60f7593abca1e3eef26a9afa244e4fb.jpeg +0 -0
- package/docs/assets/images/localeDropdown-f0d995e751e7656a1b0dbbc1134e49c2.png +0 -0
- package/docs/assets/js/01a85c17.91559aa8.js +1 -0
- package/docs/assets/js/04f53609.3e080413.js +1 -0
- package/docs/assets/js/06f8edbc.d068ca2d.js +1 -0
- package/docs/assets/js/0e384e19.bfafbae8.js +1 -0
- package/docs/assets/js/14eb3368.dc3929be.js +1 -0
- package/docs/assets/js/1506.be55cc02.js +1 -0
- package/docs/assets/js/17896441.6978c74d.js +1 -0
- package/docs/assets/js/18c41134.51213963.js +1 -0
- package/docs/assets/js/1be78505.7eff18a4.js +1 -0
- package/docs/assets/js/1e4232ab.9d5e7d68.js +1 -0
- package/docs/assets/js/1f391b9e.ded0d3af.js +1 -0
- package/docs/assets/js/2529.215308a3.js +1 -0
- package/docs/assets/js/2a62e1de.f5d1c5c9.js +1 -0
- package/docs/assets/js/35eb6bfb.705be990.js +1 -0
- package/docs/assets/js/374b0cdb.7b632eb1.js +1 -0
- package/docs/assets/js/393be207.22fd7b62.js +1 -0
- package/docs/assets/js/4972.074ebb40.js +1 -0
- package/docs/assets/js/5160ec69.26603a56.js +1 -0
- package/docs/assets/js/5334ce5a.424fc12a.js +1 -0
- package/docs/assets/js/533a09ca.636e61f7.js +1 -0
- package/docs/assets/js/59362658.a2ba0846.js +1 -0
- package/docs/assets/js/5c868d36.f7746599.js +1 -0
- package/docs/assets/js/5f55c74a.654d3d70.js +1 -0
- package/docs/assets/js/6875c492.4887a372.js +1 -0
- package/docs/assets/js/6d28c3a2.500d2f8a.js +1 -0
- package/docs/assets/js/7177ef6c.93edadcb.js +1 -0
- package/docs/assets/js/73664a40.9a87d45e.js +1 -0
- package/docs/assets/js/7661071f.e1c9bc29.js +1 -0
- package/docs/assets/js/7ebdc023.47964b2f.js +1 -0
- package/docs/assets/js/814f3328.5d2849da.js +1 -0
- package/docs/assets/js/822bd8ab.d333174b.js +1 -0
- package/docs/assets/js/84d8e3c6.1948afb0.js +1 -0
- package/docs/assets/js/8717b14a.7cc8f157.js +1 -0
- package/docs/assets/js/925b3f96.cec27ac2.js +1 -0
- package/docs/assets/js/935f2afb.f8c4c915.js +1 -0
- package/docs/assets/js/943f97fe.fe5cbcd1.js +1 -0
- package/docs/assets/js/9d38d20f.d2a4a29c.js +1 -0
- package/docs/assets/js/9e4087bc.930b1943.js +1 -0
- package/docs/assets/js/a6aa9e1f.7745bc3a.js +1 -0
- package/docs/assets/js/c4f5d8e4.f1e52410.js +1 -0
- package/docs/assets/js/ccc49370.fbb75b83.js +1 -0
- package/docs/assets/js/d23d5178.fb9fee6f.js +1 -0
- package/docs/assets/js/d47dff13.ca5c7941.js +1 -0
- package/docs/assets/js/d9f32620.abb1b84e.js +1 -0
- package/docs/assets/js/dff1c289.178f928a.js +1 -0
- package/docs/assets/js/e273c56f.ad3daaac.js +1 -0
- package/docs/assets/js/e44a2883.faee0d73.js +1 -0
- package/docs/assets/js/f4f34a3a.6ba2e989.js +1 -0
- package/docs/assets/js/f55d3e7a.9370b31f.js +1 -0
- package/docs/assets/js/feeaa39e.dfbe8222.js +1 -0
- package/docs/assets/js/main.b18edd8d.js +2 -0
- package/docs/assets/js/main.b18edd8d.js.LICENSE.txt +63 -0
- package/docs/assets/js/runtime~main.48a22eee.js +1 -0
- package/docs/blog/archive/index.html +17 -0
- package/docs/blog/atom.xml +70 -0
- package/docs/blog/first-blog-post/index.html +17 -0
- package/docs/blog/index.html +17 -0
- package/docs/blog/long-blog-post/index.html +17 -0
- package/docs/blog/mdx-blog-post/index.html +17 -0
- package/docs/blog/rss.xml +52 -0
- package/docs/blog/tags/docusaurus/index.html +17 -0
- package/docs/blog/tags/facebook/index.html +17 -0
- package/docs/blog/tags/hello/index.html +17 -0
- package/docs/blog/tags/hola/index.html +17 -0
- package/docs/blog/tags/index.html +17 -0
- package/docs/blog/welcome/index.html +17 -0
- package/docs/docs/category/tutorial---basics/index.html +17 -0
- package/docs/docs/category/tutorial---extras/index.html +17 -0
- package/docs/docs/intro/index.html +17 -0
- package/docs/docs/tutorial-basics/congratulations/index.html +17 -0
- package/docs/docs/tutorial-basics/create-a-blog-post/index.html +17 -0
- package/docs/docs/tutorial-basics/create-a-document/index.html +17 -0
- package/docs/docs/tutorial-basics/create-a-page/index.html +17 -0
- package/docs/docs/tutorial-basics/deploy-your-site/index.html +17 -0
- package/docs/docs/tutorial-basics/markdown-features/index.html +17 -0
- package/docs/docs/tutorial-extras/manage-docs-versions/index.html +17 -0
- package/docs/docs/tutorial-extras/translate-your-site/index.html +17 -0
- package/docs/helloReact/index.html +17 -0
- package/docs/img/docusaurus-social-card.jpg +0 -0
- package/docs/img/docusaurus.png +0 -0
- package/docs/img/favicon.ico +0 -0
- package/docs/img/logo.svg +1 -0
- package/docs/img/undraw_docusaurus_mountain.svg +171 -0
- package/docs/img/undraw_docusaurus_react.svg +170 -0
- package/docs/img/undraw_docusaurus_tree.svg +40 -0
- package/docs/index.html +17 -0
- package/docs/markdown-page/index.html +17 -0
- package/docs/sitemap.xml +1 -0
- package/hooks/TropipayHooks.d.ts +29 -8
- package/index.d.ts +32 -18
- package/index.js +119 -40
- package/interfaces/index.d.ts +1 -1
- package/interfaces/paymentlink/index.d.ts +56 -5
- package/package.json +1 -1
- package/paymentcard/PaymentCard.d.ts +21 -0
- package/src/api/TropipayAPI.ts +3 -29
- package/src/hooks/TropipayHooks.ts +121 -20
- package/src/index.ts +14 -2
- package/src/interfaces/index.ts +22 -1
- package/src/interfaces/paymentlink/index.ts +86 -35
- package/src/paymentcard/PaymentCard.ts +84 -0
- package/docs/images/app-credentials-menu.png +0 -0
- package/docs/images/confirmation-code-screen.png +0 -0
- package/docs/images/intellisense-vs-code.png +0 -0
- package/docs/index.MD +0 -19
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
|
+
}
|
|
66
121
|
}
|
|
67
|
-
async
|
|
68
|
-
|
|
69
|
-
|
|
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
|
+
}
|
|
140
|
+
}
|
|
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
|
|
|
@@ -124,30 +212,6 @@ class Tropipay {
|
|
|
124
212
|
throw new Error(`Could not obtain the access token from credentials ${error}`);
|
|
125
213
|
}
|
|
126
214
|
}
|
|
127
|
-
/**
|
|
128
|
-
* Create a paymentLink with the specified options.
|
|
129
|
-
* @param payload PaymentLinkPayload Object.
|
|
130
|
-
* @returns Promise<PaymentLink> or throws an Exception.
|
|
131
|
-
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
132
|
-
*/
|
|
133
|
-
async createPaymentCard(payload) {
|
|
134
|
-
if (!Tropipay.accessToken) {
|
|
135
|
-
await this.login();
|
|
136
|
-
}
|
|
137
|
-
try {
|
|
138
|
-
const paylink = await this.request.post("/api/v2/paymentcards", payload, {
|
|
139
|
-
headers: {
|
|
140
|
-
"Content-Type": "application/json",
|
|
141
|
-
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
142
|
-
Accept: "application/json",
|
|
143
|
-
},
|
|
144
|
-
});
|
|
145
|
-
return paylink.data;
|
|
146
|
-
}
|
|
147
|
-
catch (error) {
|
|
148
|
-
throw new Error(`Could not obtain the access token with the given credentials.`);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
215
|
/**
|
|
152
216
|
* Get all deposits in this account.
|
|
153
217
|
* @returns A Promise of an Array of AccountDeposits or throws an Exception
|
|
@@ -270,8 +334,8 @@ class Tropipay {
|
|
|
270
334
|
}
|
|
271
335
|
}
|
|
272
336
|
/**
|
|
273
|
-
* Return profile data for
|
|
274
|
-
* @returns
|
|
337
|
+
* Return profile data for current Tropipay account.
|
|
338
|
+
* @returns account object
|
|
275
339
|
*/
|
|
276
340
|
async profile() {
|
|
277
341
|
if (!Tropipay.accessToken)
|
|
@@ -336,7 +400,7 @@ class Tropipay {
|
|
|
336
400
|
return mediation.data;
|
|
337
401
|
}
|
|
338
402
|
catch (error) {
|
|
339
|
-
throw new Error(`Could not
|
|
403
|
+
throw new Error(`Could not create mediation payment card`);
|
|
340
404
|
}
|
|
341
405
|
}
|
|
342
406
|
}
|
|
@@ -374,6 +438,21 @@ class ServerSideUtils {
|
|
|
374
438
|
|
|
375
439
|
const SERVER_MODE = "Development"; // Move the constant here
|
|
376
440
|
|
|
441
|
+
/**
|
|
442
|
+
* TropipayJS is a powerful TypeScript/JavaScript library designed to provide seamless interaction
|
|
443
|
+
* with the Tropipay API. It simplifies the process of integrating Tropipay's functionality into
|
|
444
|
+
* your applications.
|
|
445
|
+
*
|
|
446
|
+
* Developed by Yosleivy Baez Acosta
|
|
447
|
+
* GitHub: https://github.com/yosle/tropipayjs
|
|
448
|
+
*
|
|
449
|
+
* @version 0.1.11
|
|
450
|
+
* @license MIT
|
|
451
|
+
*/
|
|
452
|
+
if (typeof window !== "undefined") {
|
|
453
|
+
console.warn("DANGER This library should not be used client side, your credentials could be exposed");
|
|
454
|
+
}
|
|
455
|
+
|
|
377
456
|
exports.ClientSideUtils = ClientSideUtils;
|
|
378
457
|
exports.SERVER_MODE = SERVER_MODE;
|
|
379
458
|
exports.ServerSideUtils = ServerSideUtils;
|
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
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Tropipay } from "../api/TropipayAPI";
|
|
2
|
+
import { PaymentLink } from "../interfaces";
|
|
3
|
+
import { PaymentLinkPayload } from "../interfaces";
|
|
4
|
+
export declare class PaymentCard {
|
|
5
|
+
private tropipay;
|
|
6
|
+
constructor(tropipayInstance: Tropipay);
|
|
7
|
+
/**
|
|
8
|
+
* Create a paymentLink with the specified options.
|
|
9
|
+
* @param payload PaymentLinkPayload Object.
|
|
10
|
+
* @returns Promise<PaymentLink> or throws an Exception.
|
|
11
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
12
|
+
*/
|
|
13
|
+
create(payload: PaymentLinkPayload): Promise<PaymentLink>;
|
|
14
|
+
/**
|
|
15
|
+
* Shows a list of stored paymentcards created by user.
|
|
16
|
+
* This list includes active and closed paylinks
|
|
17
|
+
* @returns Array of paymentlinks
|
|
18
|
+
*/
|
|
19
|
+
list(): Promise<any>;
|
|
20
|
+
get(id: string): Promise<any>;
|
|
21
|
+
}
|
package/src/api/TropipayAPI.ts
CHANGED
|
@@ -79,32 +79,6 @@ export class Tropipay {
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
/**
|
|
83
|
-
* Create a paymentLink with the specified options.
|
|
84
|
-
* @param payload PaymentLinkPayload Object.
|
|
85
|
-
* @returns Promise<PaymentLink> or throws an Exception.
|
|
86
|
-
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
87
|
-
*/
|
|
88
|
-
async createPaymentCard(payload: PaymentLinkPayload): Promise<PaymentLink> {
|
|
89
|
-
if (!Tropipay.accessToken) {
|
|
90
|
-
await this.login();
|
|
91
|
-
}
|
|
92
|
-
try {
|
|
93
|
-
const paylink = await this.request.post("/api/v2/paymentcards", payload, {
|
|
94
|
-
headers: {
|
|
95
|
-
"Content-Type": "application/json",
|
|
96
|
-
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
97
|
-
Accept: "application/json",
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
return paylink.data as PaymentLink;
|
|
101
|
-
} catch (error) {
|
|
102
|
-
throw new Error(
|
|
103
|
-
`Could not obtain the access token with the given credentials.`
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
82
|
/**
|
|
109
83
|
* Get all deposits in this account.
|
|
110
84
|
* @returns A Promise of an Array of AccountDeposits or throws an Exception
|
|
@@ -233,8 +207,8 @@ export class Tropipay {
|
|
|
233
207
|
}
|
|
234
208
|
|
|
235
209
|
/**
|
|
236
|
-
* Return profile data for
|
|
237
|
-
* @returns
|
|
210
|
+
* Return profile data for current Tropipay account.
|
|
211
|
+
* @returns account object
|
|
238
212
|
*/
|
|
239
213
|
async profile() {
|
|
240
214
|
if (!Tropipay.accessToken) await this.login();
|
|
@@ -309,7 +283,7 @@ export class Tropipay {
|
|
|
309
283
|
);
|
|
310
284
|
return mediation.data as PaymentLink;
|
|
311
285
|
} catch (error) {
|
|
312
|
-
throw new Error(`Could not
|
|
286
|
+
throw new Error(`Could not create mediation payment card`);
|
|
313
287
|
}
|
|
314
288
|
}
|
|
315
289
|
}
|
|
@@ -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,21 @@
|
|
|
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
|
+
|
|
13
|
+
if (typeof window !== "undefined") {
|
|
14
|
+
console.warn(
|
|
15
|
+
"DANGER This library should not be used client side, your credentials could be exposed"
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
7
19
|
export { Tropipay } from "./api/TropipayAPI";
|
|
8
20
|
export { ClientSideUtils } from "./api/TropipayAPI";
|
|
9
21
|
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 {
|