@yosle/tropipayjs 0.1.28 → 0.2.1

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.
@@ -22,12 +22,13 @@ import PaymentCard from "../paymentcard/PaymentCard";
22
22
  import MediationPaymentCard from "../mediationPaymentCard/MediationPaymentCard";
23
23
  import DepositAccounts from "../depositAccount/depositAccounts";
24
24
  import { TropipayJSException, handleExceptions } from "../utils/errors";
25
+ import Accounts from "../accounts/accounts";
25
26
  export class Tropipay {
26
27
  readonly clientId: string;
27
28
  readonly clientSecret: string;
28
29
  readonly scopes: String[];
29
30
  public request: Axios;
30
- public loginRequest: Axios;
31
+ public loginRequest: Axios;
31
32
  public static accessToken: string | null;
32
33
  public static refreshToken: string | null;
33
34
  public static expiresIn: number | null;
@@ -36,6 +37,7 @@ export class Tropipay {
36
37
  public paymentCards: PaymentCard;
37
38
  public depositAccounts: DepositAccounts;
38
39
  public mediationPaymentCard: MediationPaymentCard;
40
+ public accounts: Accounts;
39
41
 
40
42
  /**
41
43
  * Initializes a new instance of the Tropipay class.
@@ -73,11 +75,12 @@ export class Tropipay {
73
75
  this.clientSecret = config.clientSecret;
74
76
  this.serverMode = config.serverMode || "Development";
75
77
 
76
- const tpp_env = this.serverMode === "Production"
77
- ? "https://www.tropipay.com"
78
- : "https://tropipay-dev.herokuapp.com";
78
+ const tpp_env =
79
+ this.serverMode === "Production"
80
+ ? "https://www.tropipay.com"
81
+ : "https://sandbox.tropipay.me";
79
82
  this.request = axios.create({
80
- baseURL: config.customTropipayUrl || tpp_env,
83
+ baseURL: config.customTropipayUrl || tpp_env,
81
84
  headers: {
82
85
  "Content-Type": "application/json",
83
86
  Accept: "application/json",
@@ -85,21 +88,20 @@ export class Tropipay {
85
88
  },
86
89
  });
87
90
 
88
- // Create a separate instance for login requests
89
- this.loginRequest = axios.create({
90
- baseURL: config.customTropipayUrl || tpp_env,
91
- headers: {
92
- "Content-Type": "application/json",
93
- Accept: "application/json"
94
- },
95
- });
91
+ // Create a separate instance for login requests
92
+ this.loginRequest = axios.create({
93
+ baseURL: config.customTropipayUrl || tpp_env,
94
+ headers: {
95
+ "Content-Type": "application/json",
96
+ Accept: "application/json",
97
+ },
98
+ });
96
99
 
97
- // Add request interceptor for Token expired
98
- this.request.interceptors.request.use(
100
+ // Add request interceptor for Token expired
101
+ this.request.interceptors.request.use(
99
102
  async (config) => {
100
- console.log("Executing interceptor!!");
101
103
  const currentTimestamp = Math.floor(Date.now() / 1000);
102
-
104
+
103
105
  if (Tropipay.expiresIn && Tropipay.expiresIn < currentTimestamp) {
104
106
  console.debug("Token expired, attempting to log in");
105
107
  try {
@@ -107,34 +109,29 @@ export class Tropipay {
107
109
  } catch (error) {
108
110
  throw handleExceptions(error as Error);
109
111
  }
110
- }
112
+ }
111
113
  // Update the Authorization header in the config
112
- config.headers.Authorization = `Bearer ${Tropipay.accessToken}`;
114
+ config.headers.Authorization = `Bearer ${Tropipay.accessToken}`;
113
115
  return config;
114
116
  },
115
117
  (error) => {
116
118
  return Promise.reject(error);
117
119
  }
118
120
  );
119
-
120
121
 
121
122
  this.hooks = new TropipayHooks(this);
122
123
  this.paymentCards = new PaymentCard(this);
123
124
  this.mediationPaymentCard = new MediationPaymentCard(this);
124
125
 
125
126
  this.depositAccounts = new DepositAccounts(this);
126
-
127
-
128
-
129
-
127
+ this.accounts = new Accounts(this)
130
128
  }
131
129
 
132
130
  public async login() {
133
131
  try {
134
-
135
132
  // normal credetials login
136
133
  const { data } = await this.loginRequest.post<LoginResponse>(
137
- "/api/v2/access/token",
134
+ "/api/v3/access/token",
138
135
  {
139
136
  client_id: this.clientId,
140
137
  client_secret: this.clientSecret,
@@ -149,13 +146,10 @@ export class Tropipay {
149
146
  }
150
147
  );
151
148
 
152
-
153
149
  Tropipay.accessToken = data.access_token;
154
150
  Tropipay.expiresIn = data.expires_in;
155
151
  return data;
156
152
  } catch (error) {
157
-
158
- console.log("RAW login error ", error)
159
153
  Tropipay.accessToken = null;
160
154
  Tropipay.refreshToken = null;
161
155
  Tropipay.expiresIn = null;
@@ -18,7 +18,7 @@ export default class DepositAccounts {
18
18
  }
19
19
  try {
20
20
  const deposit = await this.tropipay.request.get(
21
- `/api/v2/deposit_accounts`,
21
+ `/api/v3/deposit_accounts`,
22
22
  {
23
23
  headers: {
24
24
  "Content-Type": "application/json",
@@ -43,7 +43,7 @@ export default class DepositAccounts {
43
43
  }
44
44
  try {
45
45
  const deposit = await this.tropipay.request.post(
46
- "/api/v2/deposit_accounts",
46
+ "/api/v3/deposit_accounts",
47
47
  depositAccountObj,
48
48
  {
49
49
  headers: {
@@ -70,7 +70,7 @@ export default class DepositAccounts {
70
70
  }
71
71
  try {
72
72
  const deposit = await this.tropipay.request.get(
73
- `/api/v2/deposit_accounts/${id}`,
73
+ `/api/v3/deposit_accounts/${id}`,
74
74
  {
75
75
  headers: {
76
76
  "Content-Type": "application/json",
@@ -96,7 +96,7 @@ export default class DepositAccounts {
96
96
  }
97
97
  try {
98
98
  const deposit = await this.tropipay.request.put(
99
- `/api/v2/deposit_accounts/`,
99
+ `/api/v3/deposit_accounts/`,
100
100
  {
101
101
  headers: {
102
102
  "Content-Type": "application/json",
@@ -122,7 +122,7 @@ export default class DepositAccounts {
122
122
  }
123
123
  try {
124
124
  const deposit = await this.tropipay.request.delete(
125
- `/api/v2/deposit_accounts/${id}`,
125
+ `/api/v3/deposit_accounts/${id}`,
126
126
  {
127
127
  headers: {
128
128
  "Content-Type": "application/json",
@@ -1,201 +1,264 @@
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
- };
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
+ /**
67
+ * Interface for creating payment links/cards
68
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
69
+ */
70
+ export interface PaymentLinkPayload {
71
+ /** Account ID where the funds will be received if compatible */
72
+ accountId?: number;
73
+
74
+ /** Reference code for the payment, preferred to be unique */
75
+ reference: string;
76
+
77
+ /** Short description of the payment */
78
+ concept: string;
79
+
80
+ /** Whether to mark this payment link as favorite */
81
+ favorite: boolean;
82
+
83
+ /** Amount to charge in the specified currency */
84
+ amount: number;
85
+
86
+ /** Currency code (EUR, USD, etc.) */
87
+ currency: string;
88
+
89
+ /** Detailed description of the payment */
90
+ description: string;
91
+
92
+ /** If true, the payment link can only be used once */
93
+ singleUse: boolean;
94
+
95
+ /** Reason ID for the payment */
96
+ reasonId: number;
97
+
98
+ /** Number of days until the payment link expires */
99
+ expirationDays: number;
100
+
101
+ /** Language code for the payment page (en, es, etc.) */
102
+ lang: string;
103
+
104
+ /** URL to redirect after successful payment */
105
+ urlSuccess: string;
106
+
107
+ /** URL to redirect after failed payment */
108
+ urlFailed: string;
109
+
110
+ /** Webhook URL for payment notifications */
111
+ urlNotification: string;
112
+
113
+ /** Date when the service will be provided (ISO format) */
114
+ serviceDate: string;
115
+
116
+ /** Client information for the payment */
117
+ client?: {
118
+ /** Client's first name */
119
+ name?: string;
120
+
121
+ /** Client's last name */
122
+ lastName?: string;
123
+
124
+ /** Client's address */
125
+ address?: string;
126
+
127
+ /** Client's phone number */
128
+ phone?: string;
129
+
130
+ /** Client's email address */
131
+ email?: string;
132
+
133
+ /** Client's country ID */
134
+ countryId?: number;
135
+
136
+ /** Client's country ISO code */
137
+ countryIso?: string;
138
+
139
+ /** Client's city */
140
+ city: string;
141
+
142
+ /** Client's postal code */
143
+ postCode: string;
144
+
145
+ /** Whether client accepted terms and conditions */
146
+ termsAndConditions: boolean;
147
+ } | null;
148
+
149
+ /** @deprecated If true, redirects directly to payment page */
150
+ directPayment: boolean;
151
+
152
+ /** List of allowed payment methods */
153
+ paymentMethods?: string[];
154
+
155
+ /** Base64 encoded image for the payment page */
156
+ imageBase?: string;
157
+
158
+ /** Whether to save the payment token for future use */
159
+ saveToken?: boolean;
160
+ }
161
+
162
+ export interface PaymentLink extends PaymentLinkPayload {
163
+ expirationDate: string;
164
+ hasClient: boolean;
165
+ updatedAt: string;
166
+ createdAt: string;
167
+ qrImage: string;
168
+ shortUrl: string;
169
+ paymentUrl: string;
170
+ }
171
+
172
+ export interface MediationPaymentCardConfig {
173
+ amount: number;
174
+ currency: "EUR" | "USD";
175
+ concept: string;
176
+ description: string;
177
+ reference: string;
178
+ singleUse: boolean;
179
+ lang: string;
180
+ productUrl?: string;
181
+ buyer: null | any;
182
+ seller: {
183
+ sellerId?: number;
184
+ type?: number;
185
+ email?: string;
186
+ };
187
+ feePercent?: number;
188
+ feeFixed?: number;
189
+ sendMail: boolean;
190
+ }
191
+
192
+ export type LoginResponse = {
193
+ access_token: string;
194
+ refresh_token: string;
195
+ token_type: "Bearer";
196
+ expires_in: number;
197
+ scope: string;
198
+ };
199
+
200
+ export type LoginError = {
201
+ error: string;
202
+ };
203
+
204
+ export type Country = {
205
+ id: number;
206
+ name: string;
207
+ sepaZone: boolean;
208
+ state: number;
209
+ slug: string;
210
+ slugn: number;
211
+ callingCode: number;
212
+ isDestination: boolean;
213
+ isRisky: boolean;
214
+ currentCurrency: string | null;
215
+ createdAt: string;
216
+ updatedAt: string;
217
+ isFavorite: boolean;
218
+ position: any;
219
+ };
220
+
221
+ export type Deposit = {
222
+ id: number;
223
+ accountNumber: string;
224
+ alias: string;
225
+ swift: string;
226
+ type: number;
227
+ country: number | null;
228
+ firstName: string;
229
+ default: null;
230
+ state: number;
231
+ userId: string;
232
+ countryDestinationId: number;
233
+ lastName: string;
234
+ documentNumber: number;
235
+ userRelationTypeId: number;
236
+ city: string;
237
+ postalCode: string;
238
+ address: string;
239
+ phone: string;
240
+ checked: boolean;
241
+ province: string;
242
+ beneficiaryType: number;
243
+ relatedUserId: null | string;
244
+ currency: string;
245
+ correspondent?: any;
246
+ location: any;
247
+ office: any;
248
+ officeValue: any;
249
+ paymentType: number;
250
+ paymentEntityBeneficiaryId: number;
251
+ paymentEntityAccountId: number;
252
+ verified: any;
253
+ paymentEntityInfo: any;
254
+ documentTypeId: any;
255
+ documentExpirationDate: Date;
256
+ createdAt: Date;
257
+ updatedAt: Date;
258
+ countryDestination: Country;
259
+ };
260
+
261
+ export type AccountDeposits = {
262
+ count: number;
263
+ rows: Deposit[];
264
+ };