@yosle/tropipayjs 0.1.21 → 0.1.23

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.
Files changed (39) hide show
  1. package/.nvmrc +1 -1
  2. package/.vscode/launch.json +18 -0
  3. package/LICENSE +9 -9
  4. package/README.md +152 -152
  5. package/api/TropipayAPI.d.ts +18 -5
  6. package/depositAccount/depositAccounts.d.ts +1 -1
  7. package/docs/readme.md +3 -3
  8. package/globals.d.ts +75 -75
  9. package/hooks/TropipayHooks.d.ts +2 -2
  10. package/index.d.ts +50 -12
  11. package/index.js +99 -8
  12. package/interfaces/countries/index.d.ts +1 -1
  13. package/interfaces/index.d.ts +14 -9
  14. package/jest.config.js +5 -0
  15. package/mediationPaymentCard/MediationPaymentCard.d.ts +17 -0
  16. package/package.json +49 -46
  17. package/paymentcard/PaymentCard.d.ts +17 -1
  18. package/paymentcard/paymentcard.spec.d.ts +1 -1
  19. package/rollup.config.js +24 -24
  20. package/src/api/TropipayAPI.ts +370 -323
  21. package/src/config/TropipayConfig.ts +2 -2
  22. package/src/constants/TropipayConstants.ts +2 -2
  23. package/src/depositAccount/depositAccounts.ts +139 -139
  24. package/src/hooks/TropipayHooks.ts +154 -154
  25. package/src/index.ts +28 -27
  26. package/src/interfaces/depositaccounts/index.ts +70 -70
  27. package/src/interfaces/index.js +1 -1
  28. package/src/interfaces/index.ts +201 -195
  29. package/src/interfaces/mediation/index.ts +22 -22
  30. package/src/interfaces/paymentlink/index.d.ts +36 -36
  31. package/src/interfaces/paymentlink/index.js +2 -2
  32. package/src/interfaces/paymentlink/index.ts +91 -91
  33. package/src/mediationPaymentCard/MediationPaymentCard.ts +42 -0
  34. package/src/mocks/tropipay.ts +0 -0
  35. package/src/paymentcard/PaymentCard.ts +123 -84
  36. package/src/paymentcard/paymentcard.spec.ts +79 -10
  37. package/src/utils/TropipayUtils.ts +126 -126
  38. package/src/utils/errors.ts +92 -101
  39. package/tsconfig.json +96 -95
@@ -1,2 +1,2 @@
1
- import { ServerMode } from "../constants/TropipayConstants";
2
- export const SERVER_MODE: ServerMode = "Development"; // Move the constant here
1
+ import { ServerMode } from "../constants/TropipayConstants";
2
+ export const SERVER_MODE: ServerMode = "Development"; // Move the constant here
@@ -1,2 +1,2 @@
1
- export type ServerMode = "Development" | "Production";
2
- export const MAX_IMAGE_SIZE_MB = 1;
1
+ export type ServerMode = "Development" | "Production";
2
+ export const MAX_IMAGE_SIZE_MB = 1;
@@ -1,139 +1,139 @@
1
- import { AxiosError } from "axios";
2
- import { Tropipay } from "../api/TropipayAPI";
3
- import { DepositAccountConfig } from "../interfaces/depositaccounts";
4
- import { handleExceptions } from "../utils/errors";
5
- export class DepositAccounts {
6
- private tropipay: Tropipay;
7
- constructor(tropipayInstance: Tropipay) {
8
- this.tropipay = tropipayInstance;
9
- }
10
-
11
- /**
12
- * List od all beneficiaries of this account
13
- * @returns Array of DepositAccounts
14
- */
15
- public async list() {
16
- if (!Tropipay.accessToken) {
17
- await this.tropipay.login();
18
- }
19
- try {
20
- const deposit = await this.tropipay.request.get(
21
- `/api/v2/deposit_accounts`,
22
- {
23
- headers: {
24
- "Content-Type": "application/json",
25
- Authorization: `Bearer ${Tropipay.accessToken}`,
26
- Accept: "application/json",
27
- },
28
- }
29
- );
30
- return deposit.data;
31
- } catch (error) {
32
- return handleExceptions(error as unknown as any);
33
- }
34
- }
35
- /**
36
- * Adds a new beneficiary to the user account.
37
- * @param payload
38
- * @returns
39
- */
40
- public async create(depositAccountObj: DepositAccountConfig) {
41
- if (!Tropipay.accessToken) {
42
- await this.tropipay.login();
43
- }
44
- try {
45
- const deposit = await this.tropipay.request.post(
46
- "/api/v2/deposit_accounts",
47
- depositAccountObj,
48
- {
49
- headers: {
50
- "Content-Type": "application/json",
51
- Authorization: `Bearer ${Tropipay.accessToken}`,
52
- Accept: "application/json",
53
- },
54
- }
55
- );
56
- return deposit.data;
57
- } catch (error) {
58
- return handleExceptions(error as unknown as any);
59
- }
60
- }
61
- /**
62
- * This returns details of a specific
63
- * Deposit Account (beneficiary) specified by its ID
64
- * @param id
65
- * @returns
66
- */
67
- public async get(id: string) {
68
- if (!Tropipay.accessToken) {
69
- await this.tropipay.login();
70
- }
71
- try {
72
- const deposit = await this.tropipay.request.get(
73
- `/api/v2/deposit_accounts/${id}`,
74
- {
75
- headers: {
76
- "Content-Type": "application/json",
77
- Authorization: `Bearer ${Tropipay.accessToken}`,
78
- Accept: "application/json",
79
- },
80
- }
81
- );
82
- return deposit.data;
83
- } catch (error) {
84
- return handleExceptions(error as unknown as any);
85
- }
86
- }
87
-
88
- /**
89
- * Updates certain beneficiary data.
90
- * @param depositAccountObj
91
- * @returns
92
- */
93
- public async update(depositAccountObj: Partial<DepositAccountConfig>) {
94
- if (!Tropipay.accessToken) {
95
- await this.tropipay.login();
96
- }
97
- try {
98
- const deposit = await this.tropipay.request.put(
99
- `/api/v2/deposit_accounts/`,
100
- {
101
- headers: {
102
- "Content-Type": "application/json",
103
- Authorization: `Bearer ${Tropipay.accessToken}`,
104
- Accept: "application/json",
105
- },
106
- }
107
- );
108
- return deposit.data;
109
- } catch (error) {
110
- return handleExceptions(error as unknown as any);
111
- }
112
- }
113
-
114
- /**
115
- * (UNTESTED) Deletes the beneficiary indicated by id
116
- * @param id
117
- * @returns
118
- */
119
- public async delete(id: number) {
120
- if (!Tropipay.accessToken) {
121
- await this.tropipay.login();
122
- }
123
- try {
124
- const deposit = await this.tropipay.request.delete(
125
- `/api/v2/deposit_accounts/${id}`,
126
- {
127
- headers: {
128
- "Content-Type": "application/json",
129
- Authorization: `Bearer ${Tropipay.accessToken}`,
130
- Accept: "application/json",
131
- },
132
- }
133
- );
134
- return deposit.data;
135
- } catch (error) {
136
- return handleExceptions(error as unknown as any);
137
- }
138
- }
139
- }
1
+ import { AxiosError } from "axios";
2
+ import { Tropipay } from "../api/TropipayAPI";
3
+ import { DepositAccountConfig } from "../interfaces/depositaccounts";
4
+ import { handleExceptions } from "../utils/errors";
5
+ export default class DepositAccounts {
6
+ private tropipay: Tropipay;
7
+ constructor(tropipayInstance: Tropipay) {
8
+ this.tropipay = tropipayInstance;
9
+ }
10
+
11
+ /**
12
+ * List od all beneficiaries of this account
13
+ * @returns Array of DepositAccounts
14
+ */
15
+ public async list() {
16
+ if (!Tropipay.accessToken) {
17
+ await this.tropipay.login();
18
+ }
19
+ try {
20
+ const deposit = await this.tropipay.request.get(
21
+ `/api/v2/deposit_accounts`,
22
+ {
23
+ headers: {
24
+ "Content-Type": "application/json",
25
+ Authorization: `Bearer ${Tropipay.accessToken}`,
26
+ Accept: "application/json",
27
+ },
28
+ }
29
+ );
30
+ return deposit.data;
31
+ } catch (error) {
32
+ return handleExceptions(error as unknown as any);
33
+ }
34
+ }
35
+ /**
36
+ * Adds a new beneficiary to the user account.
37
+ * @param payload
38
+ * @returns
39
+ */
40
+ public async create(depositAccountObj: DepositAccountConfig) {
41
+ if (!Tropipay.accessToken) {
42
+ await this.tropipay.login();
43
+ }
44
+ try {
45
+ const deposit = await this.tropipay.request.post(
46
+ "/api/v2/deposit_accounts",
47
+ depositAccountObj,
48
+ {
49
+ headers: {
50
+ "Content-Type": "application/json",
51
+ Authorization: `Bearer ${Tropipay.accessToken}`,
52
+ Accept: "application/json",
53
+ },
54
+ }
55
+ );
56
+ return deposit.data;
57
+ } catch (error) {
58
+ return handleExceptions(error as unknown as any);
59
+ }
60
+ }
61
+ /**
62
+ * This returns details of a specific
63
+ * Deposit Account (beneficiary) specified by its ID
64
+ * @param id
65
+ * @returns
66
+ */
67
+ public async get(id: string) {
68
+ if (!Tropipay.accessToken) {
69
+ await this.tropipay.login();
70
+ }
71
+ try {
72
+ const deposit = await this.tropipay.request.get(
73
+ `/api/v2/deposit_accounts/${id}`,
74
+ {
75
+ headers: {
76
+ "Content-Type": "application/json",
77
+ Authorization: `Bearer ${Tropipay.accessToken}`,
78
+ Accept: "application/json",
79
+ },
80
+ }
81
+ );
82
+ return deposit.data;
83
+ } catch (error) {
84
+ return handleExceptions(error as unknown as any);
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Updates certain beneficiary data.
90
+ * @param depositAccountObj
91
+ * @returns
92
+ */
93
+ public async update(depositAccountObj: Partial<DepositAccountConfig>) {
94
+ if (!Tropipay.accessToken) {
95
+ await this.tropipay.login();
96
+ }
97
+ try {
98
+ const deposit = await this.tropipay.request.put(
99
+ `/api/v2/deposit_accounts/`,
100
+ {
101
+ headers: {
102
+ "Content-Type": "application/json",
103
+ Authorization: `Bearer ${Tropipay.accessToken}`,
104
+ Accept: "application/json",
105
+ },
106
+ }
107
+ );
108
+ return deposit.data;
109
+ } catch (error) {
110
+ return handleExceptions(error as unknown as any);
111
+ }
112
+ }
113
+
114
+ /**
115
+ * (UNTESTED) Deletes the beneficiary indicated by id
116
+ * @param id
117
+ * @returns
118
+ */
119
+ public async delete(id: number) {
120
+ if (!Tropipay.accessToken) {
121
+ await this.tropipay.login();
122
+ }
123
+ try {
124
+ const deposit = await this.tropipay.request.delete(
125
+ `/api/v2/deposit_accounts/${id}`,
126
+ {
127
+ headers: {
128
+ "Content-Type": "application/json",
129
+ Authorization: `Bearer ${Tropipay.accessToken}`,
130
+ Accept: "application/json",
131
+ },
132
+ }
133
+ );
134
+ return deposit.data;
135
+ } catch (error) {
136
+ return handleExceptions(error as unknown as any);
137
+ }
138
+ }
139
+ }
@@ -1,154 +1,154 @@
1
- import { HookEventType, UserHookSubscribed } from "../interfaces";
2
- import { Tropipay } from "../api/TropipayAPI";
3
- import { handleExceptions } from "../utils/errors";
4
- export class TropipayHooks {
5
- private tropipay: Tropipay;
6
- // ... hook-related functionality ...
7
- constructor(tropipayInstance: Tropipay) {
8
- this.tropipay = tropipayInstance;
9
- }
10
- /**
11
- * Subscribe a new hook
12
- * @param event String that represents the name of the event,
13
- * you must select from the list of available events, otherwise
14
- * it will not produce an error but it will not be executed.
15
- * For get full list of available events see endpoint
16
- * GET /api/v2/hook/events.
17
- * @param target String representing the type of event supported.
18
- * It is currently available: 'web' (allows to receive information in a url),
19
- * 'email' (allows to receive information in an email address).
20
- * @param value if the selected 'target' is email the value would be an
21
- * email address, likewise if the selected 'target' is 'web' the expected
22
- * value corresponds to a url that receives information through the
23
- * HTTP POST method.
24
- * @returns
25
- */
26
- public async subscribe({
27
- eventType,
28
- target,
29
- value,
30
- }: {
31
- eventType: HookEventType;
32
- target: "email" | "web";
33
- value: string;
34
- }) {
35
- if (!Tropipay.accessToken) {
36
- await this.tropipay.login();
37
- }
38
- try {
39
- const hooks = await this.tropipay.request.post(
40
- `/api/v2/hooks`,
41
- {
42
- event: eventType,
43
- target: target,
44
- value: value,
45
- },
46
- {
47
- headers: {
48
- "Content-Type": "application/json",
49
- Authorization: `Bearer ${Tropipay.accessToken}`,
50
- Accept: "application/json",
51
- },
52
- }
53
- );
54
- return hooks.data;
55
- } catch (error) {
56
- throw handleExceptions(error as unknown as any);
57
- }
58
- }
59
- /**
60
- * Get the subscribed hook info by his event type.
61
- * If no event type is passed, it will return
62
- * all subscribed hooks or empty Array if none exist.
63
- * @param eventType or no params for retrieving all hooks
64
- * @returns All subscribed hooks or empty Array if none exist.
65
- */
66
- public async list(eventType?: HookEventType): Promise<UserHookSubscribed[]> {
67
- if (!Tropipay.accessToken) {
68
- await this.tropipay.login();
69
- }
70
- try {
71
- const hooks = await this.tropipay.request.get(
72
- `/api/v2/hooks/${eventType || ""}`,
73
- {
74
- headers: {
75
- "Content-Type": "application/json",
76
- Authorization: `Bearer ${Tropipay.accessToken}`,
77
- Accept: "application/json",
78
- },
79
- }
80
- );
81
- return hooks.data;
82
- } catch (error) {
83
- throw handleExceptions(error as unknown as any);
84
- }
85
- }
86
- public async update(
87
- eventType: string,
88
- target: "web" | "email",
89
- value: string
90
- ) {
91
- if (!Tropipay.accessToken) {
92
- await this.tropipay.login();
93
- }
94
- try {
95
- const hooks = await this.tropipay.request.put(
96
- `/api/v2/hooks`,
97
- {
98
- event: eventType,
99
- target: target,
100
- value: value,
101
- },
102
- {
103
- headers: {
104
- "Content-Type": "application/json",
105
- Authorization: `Bearer ${Tropipay.accessToken}`,
106
- Accept: "application/json",
107
- },
108
- }
109
- );
110
- return hooks.data;
111
- } catch (error) {
112
- throw handleExceptions(error as unknown as any);
113
- }
114
- }
115
- async delete(eventType: HookEventType, target: string) {
116
- if (!Tropipay.accessToken) {
117
- await this.tropipay.login();
118
- }
119
- try {
120
- const hooks = await this.tropipay.request.delete(
121
- `/api/v2/hooks/${eventType}/${target}`,
122
- {
123
- headers: {
124
- "Content-Type": "application/json",
125
- Authorization: `Bearer ${Tropipay.accessToken}`,
126
- Accept: "application/json",
127
- },
128
- }
129
- );
130
- return hooks.data;
131
- } catch (error) {
132
- console.trace(error);
133
- throw handleExceptions(error as unknown as any);
134
- }
135
- }
136
-
137
- async events() {
138
- if (!Tropipay.accessToken) {
139
- await this.tropipay.login();
140
- }
141
- try {
142
- const hooks = await this.tropipay.request.get(`/api/v2/hooks/events`, {
143
- headers: {
144
- "Content-Type": "application/json",
145
- Authorization: `Bearer ${Tropipay.accessToken}`,
146
- Accept: "application/json",
147
- },
148
- });
149
- return hooks.data;
150
- } catch (error) {
151
- throw handleExceptions(error as unknown as any);
152
- }
153
- }
154
- }
1
+ import { HookEventType, UserHookSubscribed } from "../interfaces";
2
+ import { Tropipay } from "../api/TropipayAPI";
3
+ import { handleExceptions } from "../utils/errors";
4
+ export default class TropipayHooks {
5
+ private tropipay: Tropipay;
6
+ // ... hook-related functionality ...
7
+ constructor(tropipayInstance: Tropipay) {
8
+ this.tropipay = tropipayInstance;
9
+ }
10
+ /**
11
+ * Subscribe a new hook
12
+ * @param event String that represents the name of the event,
13
+ * you must select from the list of available events, otherwise
14
+ * it will not produce an error but it will not be executed.
15
+ * For get full list of available events see endpoint
16
+ * GET /api/v2/hook/events.
17
+ * @param target String representing the type of event supported.
18
+ * It is currently available: 'web' (allows to receive information in a url),
19
+ * 'email' (allows to receive information in an email address).
20
+ * @param value if the selected 'target' is email the value would be an
21
+ * email address, likewise if the selected 'target' is 'web' the expected
22
+ * value corresponds to a url that receives information through the
23
+ * HTTP POST method.
24
+ * @returns
25
+ */
26
+ public async subscribe({
27
+ eventType,
28
+ target,
29
+ value,
30
+ }: {
31
+ eventType: HookEventType;
32
+ target: "email" | "web";
33
+ value: string;
34
+ }) {
35
+ if (!Tropipay.accessToken) {
36
+ await this.tropipay.login();
37
+ }
38
+ try {
39
+ const hooks = await this.tropipay.request.post(
40
+ `/api/v2/hooks`,
41
+ {
42
+ event: eventType,
43
+ target: target,
44
+ value: value,
45
+ },
46
+ {
47
+ headers: {
48
+ "Content-Type": "application/json",
49
+ Authorization: `Bearer ${Tropipay.accessToken}`,
50
+ Accept: "application/json",
51
+ },
52
+ }
53
+ );
54
+ return hooks.data;
55
+ } catch (error) {
56
+ throw handleExceptions(error as unknown as any);
57
+ }
58
+ }
59
+ /**
60
+ * Get the subscribed hook info by his event type.
61
+ * If no event type is passed, it will return
62
+ * all subscribed hooks or empty Array if none exist.
63
+ * @param eventType or no params for retrieving all hooks
64
+ * @returns All subscribed hooks or empty Array if none exist.
65
+ */
66
+ public async list(eventType?: HookEventType): Promise<UserHookSubscribed[]> {
67
+ if (!Tropipay.accessToken) {
68
+ await this.tropipay.login();
69
+ }
70
+ try {
71
+ const hooks = await this.tropipay.request.get(
72
+ `/api/v2/hooks/${eventType || ""}`,
73
+ {
74
+ headers: {
75
+ "Content-Type": "application/json",
76
+ Authorization: `Bearer ${Tropipay.accessToken}`,
77
+ Accept: "application/json",
78
+ },
79
+ }
80
+ );
81
+ return hooks.data;
82
+ } catch (error) {
83
+ throw handleExceptions(error as unknown as any);
84
+ }
85
+ }
86
+ public async update(
87
+ eventType: HookEventType,
88
+ target: "web" | "email",
89
+ value: string
90
+ ) {
91
+ if (!Tropipay.accessToken) {
92
+ await this.tropipay.login();
93
+ }
94
+ try {
95
+ const hooks = await this.tropipay.request.put(
96
+ `/api/v2/hooks`,
97
+ {
98
+ event: eventType,
99
+ target: target,
100
+ value: value,
101
+ },
102
+ {
103
+ headers: {
104
+ "Content-Type": "application/json",
105
+ Authorization: `Bearer ${Tropipay.accessToken}`,
106
+ Accept: "application/json",
107
+ },
108
+ }
109
+ );
110
+ return hooks.data;
111
+ } catch (error) {
112
+ throw handleExceptions(error as unknown as any);
113
+ }
114
+ }
115
+ async delete(eventType: HookEventType, target: string) {
116
+ if (!Tropipay.accessToken) {
117
+ await this.tropipay.login();
118
+ }
119
+ try {
120
+ const hooks = await this.tropipay.request.delete(
121
+ `/api/v2/hooks/${eventType}/${target}`,
122
+ {
123
+ headers: {
124
+ "Content-Type": "application/json",
125
+ Authorization: `Bearer ${Tropipay.accessToken}`,
126
+ Accept: "application/json",
127
+ },
128
+ }
129
+ );
130
+ return hooks.data;
131
+ } catch (error) {
132
+ console.trace(error);
133
+ throw handleExceptions(error as unknown as any);
134
+ }
135
+ }
136
+
137
+ async events() {
138
+ if (!Tropipay.accessToken) {
139
+ await this.tropipay.login();
140
+ }
141
+ try {
142
+ const hooks = await this.tropipay.request.get(`/api/v2/hooks/events`, {
143
+ headers: {
144
+ "Content-Type": "application/json",
145
+ Authorization: `Bearer ${Tropipay.accessToken}`,
146
+ Accept: "application/json",
147
+ },
148
+ });
149
+ return hooks.data;
150
+ } catch (error) {
151
+ throw handleExceptions(error as unknown as any);
152
+ }
153
+ }
154
+ }
package/src/index.ts CHANGED
@@ -1,27 +1,28 @@
1
- /**
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.
5
- *
6
- * Developed by Yosleivy Baez Acosta
7
- * GitHub: https://github.com/yosle/tropipayjs
8
- *
9
- * @version 0.1.11
10
- * @license MIT
11
- */
12
-
13
- if (typeof window !== "undefined") {
14
- const err_msg = `⚠️ **Warning:** The Tropipay SDK should only be instantiated server-side for security reasons. Using it client-side may lead to unexpected behavior and security vulnerabilities. YOUR CREDENTIALS COULD BE EXPOSED. Check https://yosle.github.io/tropipayjs-docs/guides/installation/ for more details.`;
15
- console.error(err_msg);
16
- throw new Error(err_msg);
17
- }
18
-
19
- export { Tropipay } from "./api/TropipayAPI";
20
- export { ClientSideUtils } from "./api/TropipayAPI";
21
- export { ServerSideUtils } from "./utils/TropipayUtils";
22
- export { TropipayHooks } from "./hooks/TropipayHooks";
23
- export { PaymentCard } from "./paymentcard/PaymentCard";
24
- export { DepositAccounts } from "./depositAccount/depositAccounts";
25
- export * from "./interfaces/index";
26
- export { SERVER_MODE } from "./config/TropipayConfig";
27
- export * from "./constants/TropipayConstants";
1
+ /**
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.
5
+ *
6
+ * Developed by Yosleivy Baez Acosta
7
+ * GitHub: https://github.com/yosle/tropipayjs
8
+ *
9
+ * @version 0.1.11
10
+ * @license MIT
11
+ */
12
+
13
+ if (typeof window !== "undefined") {
14
+ const err_msg = `⚠️ **Warning:** The Tropipay SDK should only be instantiated server-side for security reasons. Using it client-side may lead to unexpected behavior and security vulnerabilities. YOUR CREDENTIALS COULD BE EXPOSED. Check https://yosle.github.io/tropipayjs-docs/guides/installation/ for more details.`;
15
+ console.error(err_msg);
16
+ throw new Error(err_msg);
17
+ }
18
+
19
+ export { Tropipay } from "./api/TropipayAPI";
20
+ export { ClientSideUtils } from "./api/TropipayAPI";
21
+ export { ServerSideUtils } from "./utils/TropipayUtils";
22
+ export * from "./hooks/TropipayHooks";
23
+ export * from "./paymentcard/PaymentCard";
24
+ export * from "./mediationPaymentCard/MediationPaymentCard";
25
+ export * from "./depositAccount/depositAccounts";
26
+ export * from "./interfaces/index";
27
+ export { SERVER_MODE } from "./config/TropipayConfig";
28
+ export * from "./constants/TropipayConstants";