@yosle/tropipayjs 0.2.3 → 0.3.0

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 (47) hide show
  1. package/README.md +69 -9
  2. package/index.d.ts +358 -76
  3. package/index.js +421 -342
  4. package/index.js.map +1 -0
  5. package/package.json +10 -2
  6. package/.nvmrc +0 -1
  7. package/.vscode/launch.json +0 -18
  8. package/SECURITY.md +0 -43
  9. package/api/TropipayAPI.d.ts +0 -133
  10. package/config/TropipayConfig.d.ts +0 -2
  11. package/constants/TropipayConstants.d.ts +0 -2
  12. package/depositAccount/depositAccounts.d.ts +0 -36
  13. package/docs/readme.md +0 -3
  14. package/globals.d.ts +0 -75
  15. package/hooks/TropipayHooks.d.ts +0 -38
  16. package/interfaces/countries/index.d.ts +0 -1
  17. package/interfaces/depositaccounts/index.d.ts +0 -68
  18. package/interfaces/index.d.ts +0 -176
  19. package/interfaces/mediation/index.d.ts +0 -22
  20. package/interfaces/paymentlink/index.d.ts +0 -87
  21. package/jest.config.js +0 -5
  22. package/mediationPaymentCard/MediationPaymentCard.d.ts +0 -17
  23. package/paymentcard/PaymentCard.d.ts +0 -37
  24. package/paymentcard/paymentcard.spec.d.ts +0 -1
  25. package/rollup.config.js +0 -23
  26. package/src/api/TropipayAPI.ts +0 -459
  27. package/src/config/TropipayConfig.ts +0 -2
  28. package/src/constants/TropipayConstants.ts +0 -2
  29. package/src/depositAccount/depositAccounts.ts +0 -139
  30. package/src/hooks/TropipayHooks.ts +0 -154
  31. package/src/index.ts +0 -29
  32. package/src/interfaces/depositaccounts/index.ts +0 -70
  33. package/src/interfaces/index.js +0 -2
  34. package/src/interfaces/index.ts +0 -212
  35. package/src/interfaces/mediation/index.ts +0 -23
  36. package/src/interfaces/paymentlink/index.d.ts +0 -36
  37. package/src/interfaces/paymentlink/index.js +0 -3
  38. package/src/interfaces/paymentlink/index.ts +0 -91
  39. package/src/mediationPaymentCard/MediationPaymentCard.ts +0 -42
  40. package/src/mocks/tropipay.ts +0 -0
  41. package/src/paymentcard/PaymentCard.ts +0 -123
  42. package/src/paymentcard/paymentcard.spec.ts +0 -79
  43. package/src/utils/TropipayUtils.ts +0 -126
  44. package/src/utils/errors.ts +0 -92
  45. package/tsconfig.json +0 -96
  46. package/utils/TropipayUtils.d.ts +0 -45
  47. package/utils/errors.d.ts +0 -16
@@ -1,154 +0,0 @@
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 DELETED
@@ -1,29 +0,0 @@
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";
29
- export type { RefundResponse } from "./interfaces/index";
@@ -1,70 +0,0 @@
1
- export interface DepositAccountConfig {
2
- searchValue?: string;
3
- alias: string;
4
- userRelationTypeId: number;
5
- beneficiaryType: BeneficiaryType;
6
- searchBy?: number;
7
- accountNumber?: string;
8
- swift?: string;
9
- type: DepositAccountType;
10
- firstName?: string;
11
- lastName?: string;
12
- secondLastName?: string;
13
- countryDestinationId?: number;
14
- city?: string;
15
- postalCode?: number;
16
- address?: string;
17
- documentNumber?: string;
18
- phone?: string;
19
- province?: string;
20
- paymentType?: string;
21
- documentTypeId?: number;
22
- documentExpirationDate: string;
23
- }
24
- type INTERNAL = 1;
25
- type EXTERNAL = 2;
26
-
27
- export type BeneficiaryType = INTERNAL | EXTERNAL;
28
-
29
- export const DepositAccountTypesList = {
30
- /**
31
- * Banco Metropolitano (Cuba) Bank Account
32
- */
33
- BANMET_BANK_ACCOUNT: 0,
34
- /**
35
- * Banco Popular de Ahorro
36
- */
37
- BPA_BANK_ACCOUNT: 1,
38
- /**
39
- * Banco de Credito y Comercio (Cuba) Bank Account
40
- */
41
- BANDEC_BANK_ACCOUNT: 2,
42
- /**
43
- * Banco Metropilitano (Cuba) card
44
- */
45
- BANMET_CARD: 3,
46
- /**
47
- * Banco Popular de Ahorro (Cuba) card
48
- */
49
- BPA_CARD: 4,
50
- /**
51
- * Not available anymore
52
- * @deprecated
53
- */
54
- AIS_CUC_CARD: 5,
55
- /**
56
- * Not available
57
- * @deprecated
58
- */
59
- AIS_USD_CARD: 6,
60
- /**
61
- * For international bank accounts
62
- */
63
- OTHER: 7,
64
- /**
65
- * Banco de Credito y comercio card
66
- */
67
- BANDEC_CARD: 8,
68
- } as const;
69
-
70
- export type DepositAccountType = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=index.js.map
@@ -1,212 +0,0 @@
1
- import { ServerMode } from "../constants/TropipayConstants";
2
-
3
- export type AccountBalance = {
4
- balance: number;
5
- pendingIn: number;
6
- pendingOut: number;
7
- };
8
-
9
- export interface TropipayConfig {
10
- clientId: string;
11
- clientSecret: string;
12
- scopes?: string[];
13
- serverMode?: ServerMode;
14
- // Custom tropipay environment for testing
15
- customTropipayUrl?: string;
16
- }
17
-
18
- export type TropipayCredentials = { clientId: string; clientSecret: string };
19
- export type HookEventType =
20
- | "transaction_completed"
21
- | "transaction_charged"
22
- | "transaction_guarded"
23
- | "user_signup"
24
- | "user_kyc"
25
- | "payment_in_state_change"
26
- | "payment_out_state_change"
27
- | "beneficiary_added"
28
- | "beneficiary_updated"
29
- | "beneficiary_deleted"
30
- | "transaction_new"
31
- | "transaction_preauthorized"
32
- | "transaction_pendingin"
33
- | "transaction_processing"
34
- | "transaction_error"
35
- | "transaction_bloqued"
36
- | "transaction_guarded_send"
37
- | "transaction_guarded_mediation"
38
- | "user_after_update"
39
- | "user_after_create"
40
- | "userDetail_after_create"
41
- | "userDetail_after_update"
42
- | "tpv_callback_ok"
43
- | "fraud_state_on_change";
44
-
45
- export type HookTargetType = "web" | "email";
46
- export interface UserHook {
47
- event: HookEventType;
48
- target: string;
49
- value: string;
50
- }
51
- export interface UserHookSubscribed extends UserHook {
52
- createdAt: string;
53
- updatedAt: string;
54
- }
55
-
56
- export interface UserHook {
57
- event: HookEventType;
58
- target: string;
59
- value: string;
60
- }
61
- export interface UserHookSubscribed extends UserHook {
62
- createdAt: string;
63
- updatedAt: string;
64
- }
65
-
66
- export interface PaymentLinkPayload {
67
- reference: string;
68
- concept: string;
69
- favorite: boolean;
70
- amount: number;
71
- currency: string;
72
- description: string;
73
- singleUse: boolean;
74
- reasonId: number;
75
- expirationDays: number;
76
- lang: string;
77
- urlSuccess: string;
78
- urlFailed: string;
79
- urlNotification: string;
80
- serviceDate: string;
81
- client?: {
82
- name?: string;
83
- lastName?: string;
84
- address?: string;
85
- phone?: string;
86
- email?: string;
87
- countryId?: number;
88
- countryIso?: string;
89
- city: string;
90
- postCode: string;
91
- termsAndConditions: boolean;
92
- } | null;
93
- directPayment: boolean;
94
- paymentMethods?: string[];
95
- imageBase?: string;
96
- saveToken?: boolean;
97
- }
98
-
99
- export interface PaymentLink extends PaymentLinkPayload {
100
- expirationDate: string;
101
- hasClient: boolean;
102
- updatedAt: string;
103
- createdAt: string;
104
- qrImage: string;
105
- shortUrl: string;
106
- paymentUrl: string;
107
- }
108
-
109
- export interface MediationPaymentCardConfig {
110
- amount: number;
111
- currency: "EUR" | "USD";
112
- concept: string;
113
- description: string;
114
- reference: string;
115
- singleUse: boolean;
116
- lang: string;
117
- productUrl?: string;
118
- buyer: null | any;
119
- seller: {
120
- sellerId?: number;
121
- type?: number;
122
- email?: string;
123
- };
124
- feePercent?: number;
125
- feeFixed?: number;
126
- sendMail: boolean;
127
- }
128
-
129
- export type LoginResponse = {
130
- access_token: string;
131
- refresh_token: string;
132
- token_type: "Bearer";
133
- expires_in: number;
134
- scope: string;
135
- };
136
-
137
- export type LoginError = {
138
- error: string;
139
- };
140
-
141
- export type Country = {
142
- id: number;
143
- name: string;
144
- sepaZone: boolean;
145
- state: number;
146
- slug: string;
147
- slugn: number;
148
- callingCode: number;
149
- isDestination: boolean;
150
- isRisky: boolean;
151
- currentCurrency: string | null;
152
- createdAt: string;
153
- updatedAt: string;
154
- isFavorite: boolean;
155
- position: any;
156
- };
157
-
158
- export type Deposit = {
159
- id: number;
160
- accountNumber: string;
161
- alias: string;
162
- swift: string;
163
- type: number;
164
- country: number | null;
165
- firstName: string;
166
- default: null;
167
- state: number;
168
- userId: string;
169
- countryDestinationId: number;
170
- lastName: string;
171
- documentNumber: number;
172
- userRelationTypeId: number;
173
- city: string;
174
- postalCode: string;
175
- address: string;
176
- phone: string;
177
- checked: boolean;
178
- province: string;
179
- beneficiaryType: number;
180
- relatedUserId: null | string;
181
- currency: string;
182
- correspondent?: any;
183
- location: any;
184
- office: any;
185
- officeValue: any;
186
- paymentType: number;
187
- paymentEntityBeneficiaryId: number;
188
- paymentEntityAccountId: number;
189
- verified: any;
190
- paymentEntityInfo: any;
191
- documentTypeId: any;
192
- documentExpirationDate: Date;
193
- createdAt: Date;
194
- updatedAt: Date;
195
- countryDestination: Country;
196
- };
197
-
198
- export type AccountDeposits = {
199
- count: number;
200
- rows: Deposit[];
201
- };
202
-
203
- export type RefundResponse = {
204
- id: number;
205
- orderCode: string;
206
- amount: number;
207
- currency: string;
208
- state: string;
209
- type: string;
210
- createdAt: string;
211
- completedAt: string;
212
- };
@@ -1,23 +0,0 @@
1
-
2
- /**
3
- *
4
- */
5
- export interface mediationPaymentCardConfig {
6
- amount: number //5000,
7
- currency: "EUR" | "USD",
8
- concept: string //Celular,
9
- description: string,
10
- reference: string, //458424548,
11
- singleUse: boolean,
12
- lang: string// es,
13
- productUrl?: string,
14
- buyer: null | any //null,
15
- seller: {
16
- sellerId?: number,
17
- type?: number,
18
- email?: string
19
- },
20
- feePercent?: number,//in cents
21
- feeFixed?: number,
22
- sendMail: boolean
23
- }
@@ -1,36 +0,0 @@
1
- export interface PaymentLinkPayload {
2
- reference: string;
3
- concept: string;
4
- favorite: boolean;
5
- amount: number;
6
- currency: string;
7
- description: string;
8
- singleUse: boolean;
9
- reasonId: number;
10
- expirationDays: number;
11
- lang: string;
12
- urlSuccess: string;
13
- urlFailed: string;
14
- urlNotification: string;
15
- serviceDate: string;
16
- client: {
17
- name: string;
18
- lastName: string;
19
- address: string;
20
- phone: string;
21
- email: string;
22
- countryId: number;
23
- termsAndConditions: boolean;
24
- };
25
- directPayment: boolean;
26
- paymentMethods?: string[];
27
- }
28
- export interface PaymentLink extends PaymentLinkPayload {
29
- expirationDate: string;
30
- hasClient: boolean;
31
- updatedAt: string;
32
- createdAt: string;
33
- qrImage: string;
34
- shortUrl: string;
35
- paymentUrl: string;
36
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=index.js.map
@@ -1,91 +0,0 @@
1
- type PaymentMethodElement = "EXT" | "TPP";
2
- export type PaymentMethods =
3
- | Element
4
- | [PaymentMethodElement, PaymentMethodElement];
5
-
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
- }
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;
81
- }
82
-
83
- export interface PaymentLink extends PaymentLinkPayload {
84
- expirationDate: string;
85
- hasClient: boolean;
86
- updatedAt: string;
87
- createdAt: string;
88
- qrImage: string;
89
- shortUrl: string;
90
- paymentUrl: string;
91
- }
@@ -1,42 +0,0 @@
1
- import { Tropipay } from "../api/TropipayAPI";
2
- import { PaymentLink } from "../interfaces";
3
- import { MediationPaymentCardConfig } from "../interfaces";
4
- import { handleExceptions } from "../utils/errors";
5
-
6
- export default class MediationPaymentCard {
7
- private tropipay: Tropipay;
8
- constructor(tropipayInstance: Tropipay) {
9
- this.tropipay = tropipayInstance;
10
- }
11
-
12
- /**
13
- * (ONLY FOR BUSINESS ACCOUNTS) Create a mediation paymentcard (an escrow payment link) with the specified options.
14
- * This allows a payment to be made to persons belonging or not to the TropiPay platform with the
15
- * particularity that the payment will be held in custody or retained until it is released with
16
- * the approval of the payer.
17
- * @param payload PaymentLinkPayload Object.
18
- * @returns Promise<PaymentLink> or throws an Exception.
19
- * @see https://tpp.stoplight.io/docs/tropipay-api-doc/12a128ff971e4-creating-a-mediation-payment-card
20
- */
21
- async create(payload: MediationPaymentCardConfig): Promise<PaymentLink> {
22
- if (!Tropipay.accessToken) {
23
- await this.tropipay.login();
24
- }
25
- try {
26
- const paylink = await this.tropipay.request.post(
27
- "/api/v2/paymentcards/mediation",
28
- payload,
29
- {
30
- headers: {
31
- "Content-Type": "application/json",
32
- Authorization: `Bearer ${Tropipay.accessToken}`,
33
- Accept: "application/json",
34
- },
35
- }
36
- );
37
- return paylink.data as PaymentLink;
38
- } catch (error) {
39
- throw handleExceptions(error as unknown as any);
40
- }
41
- }
42
- }
File without changes