@yosle/tropipayjs 0.1.13 → 0.1.15

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/README.md CHANGED
@@ -1,15 +1,13 @@
1
- TropipayJS - Typescript/Javascript SDK for Tropipay Payments API
2
- ===========
1
+ # TropipayJS - Typescript/Javascript SDK for Tropipay Payments API
3
2
 
4
3
  ![NodeJS](https://img.shields.io/badge/node.js-6DA55F?style=for-the-badge&logo=node.js&logoColor=white)
5
- ![TypeScript](https://img.shields.io/badge/typescript-%23007ACC.svg?style=for-the-badge&logo=typescript&logoColor=white)
4
+ ![TypeScript](https://img.shields.io/badge/typescript-%23007ACC.svg?style=for-the-badge&logo=typescript&logoColor=white)
6
5
  ![JavaScript](https://img.shields.io/badge/javascript-%23323330.svg?style=for-the-badge&logo=javascript&logoColor=%23F7DF1E)
7
6
  ![Next JS](https://img.shields.io/badge/Next-black?style=for-the-badge&logo=next.js&logoColor=white)
8
7
  ![RollupJS](https://img.shields.io/badge/RollupJS-ef3335?style=for-the-badge&logo=rollup.js&logoColor=white)
9
8
 
10
9
  TropiPay is an electronic wallet that allows you to execute the most common financial operations of the day to day. This is SDK for Typescript and Javacript that helps you build integrations with the Tropipay platform in an easier way. Can save you a lot of time and effort implementing all the API features. You can use this library with CommonJS system (node + express) or ES6 module system (NextJS).
11
10
 
12
-
13
11
  # Table of Contents
14
12
 
15
13
  - [TropipayJS - Typescript/Javascript SDK for Tropipay Payments API](#tropipayjs---typescriptjavascript-sdk-for-tropipay-payments-api)
@@ -29,7 +27,7 @@ TropiPay is an electronic wallet that allows you to execute the most common fina
29
27
 
30
28
  This library is a community effort. Tropipay may make some changes on the API specification. Use the [test environment](https://tropipay-dev.herokuapp.com) to make sure everything is working as expected.
31
29
 
32
- **Note:** This library is provided as-is and serves as a client for the Tropipay API. While every effort has been made to ensure the accuracy and reliability of the library, Tropipay is solely responsible for maintaining and updating the API documentation.
30
+ **Note:** This library is provided as-is and serves as a client for the Tropipay API. While every effort has been made to ensure the accuracy and reliability of the library, Tropipay is solely responsible for maintaining and updating the API documentation.
33
31
 
34
32
  The library is intended to simplify the integration process with Tropipay's services, but it is essential to consult the official documentation to ensure that you are using the API correctly and taking into account any recent changes or updates made by Tropipay.
35
33
 
@@ -37,11 +35,11 @@ The library is intended to simplify the integration process with Tropipay's serv
37
35
 
38
36
  You can use npm or yarn to install this package:
39
37
 
40
- ```npm install @yosle/tropipayjs```
38
+ `npm install @yosle/tropipayjs`
41
39
 
42
40
  or
43
41
 
44
- ```yarn add @yosle/tropipayjs```
42
+ `yarn add @yosle/tropipayjs`
45
43
 
46
44
  ## Setting up your app credentials
47
45
 
@@ -52,18 +50,18 @@ In order to use the Tropipay API you'll need a client ID and a client secret. Si
52
50
 
53
51
  ## Usage
54
52
 
55
- The Tropipay instance, allows you to access all the method available in the API. This Object is meant to be used *only in server side*. Do not use the Tropipay object on the client side (browser). This would expose your app credentials (the client secret of your account). You can create an endpoint at your back-end using express and consume it in your front-end, or use SSR if you're using NextJS.
53
+ The Tropipay instance, allows you to access all the method available in the API. This Object is meant to be used _only in server side_. Do not use the Tropipay object on the client side (browser). This would expose your app credentials (the client secret of your account). You can create an endpoint at your back-end using express and consume it in your front-end, or use SSR if you're using NextJS.
56
54
 
57
- ### CommonJS
55
+ ### CommonJS
58
56
 
59
57
  ```javascript
60
- const { Tropipay } = require('@yosle/tropipayjs')
58
+ const { Tropipay } = require("@yosle/tropipayjs");
61
59
  ```
62
60
 
63
- ### ES6
61
+ ### ES6
64
62
 
65
63
  ```javascript
66
- import { Tropipay } from '@yosle/tropipayjs'
64
+ import { Tropipay } from "@yosle/tropipayjs";
67
65
  ```
68
66
 
69
67
  ### Initialize the Tropipay class
@@ -72,7 +70,7 @@ You can instantiate the Tropipay class passing the client Id ,client secret and
72
70
 
73
71
  ```javascript
74
72
  // test environment server tropipay-dev.herokuapp.com
75
- const config = {
73
+ const config = {
76
74
  clientId: process.env.TROPIPAY_CLIENT_ID,
77
75
  clientSecret: process.env.TROPIPAY_CLIENT_SECRET
78
76
  serverMode: 'Development' // it will be used as default if omited
@@ -84,48 +82,48 @@ To use your live credentials (real account) you must explicity set serverMode to
84
82
 
85
83
  ```javascript
86
84
  //real account credentials
87
- const config = {
88
- clientId: process.env.TROPIPAY_CLIENT_ID,
89
- clientSecret: process.env.TROPIPAY_CLIENT_SECRET,
90
- serverMode: 'Production' //live account
91
- }
92
- const tpp = new Tropipay(config)
85
+ const config = {
86
+ clientId: process.env.TROPIPAY_CLIENT_ID,
87
+ clientSecret: process.env.TROPIPAY_CLIENT_SECRET,
88
+ serverMode: "Production", //live account
89
+ };
90
+ const tpp = new Tropipay(config);
93
91
  ```
94
92
 
95
93
  ### Generating a Payment Link
96
94
 
97
95
  ```javascript
98
96
  /*
99
- * Example Payload
100
- */
97
+ * Example Payload
98
+ */
101
99
  const payload = {
102
- reference: "my-paylink-1",
103
- concept: "Bicycle",
104
- favorite: "true",
105
- amount: 3000,
106
- currency: "EUR",
107
- description: "Two wheels",
108
- singleUse: "true",
109
- reasonId: 4,
110
- expirationDays: 1,
111
- lang: "es",
112
- urlSuccess: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
113
- urlFailed: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
114
- urlNotification: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
115
- serviceDate: "2021-08-20",
116
- client: {
117
- name: "John",
118
- lastName: "McClane",
119
- address: "Ave. Guadí 232, Barcelona, Barcelona",
120
- phone: "+34645553333",
121
- email: "client@email.com",
122
- countryId: 1,
123
- termsAndConditions: "true"
124
- },
125
- directPayment: "true"
126
- }
100
+ reference: "my-paylink-1",
101
+ concept: "Bicycle",
102
+ favorite: "true",
103
+ amount: 3000,
104
+ currency: "EUR",
105
+ description: "Two wheels",
106
+ singleUse: "true",
107
+ reasonId: 4,
108
+ expirationDays: 1,
109
+ lang: "es",
110
+ urlSuccess: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
111
+ urlFailed: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
112
+ urlNotification: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
113
+ serviceDate: "2021-08-20",
114
+ client: {
115
+ name: "John",
116
+ lastName: "McClane",
117
+ address: "Ave. Guadí 232, Barcelona, Barcelona",
118
+ phone: "+34645553333",
119
+ email: "client@email.com",
120
+ countryId: 1,
121
+ termsAndConditions: "true",
122
+ },
123
+ directPayment: "true",
124
+ };
127
125
  // Use inside an async function
128
- const paylink = await tpp.createPaymentCard(payload);
126
+ const paylink = await tpp.paymentCards.create(payload);
129
127
  console.log(paylink.shortUrl);
130
128
  ```
131
129
 
@@ -140,15 +138,11 @@ If you have a suggestion that would make this better, please fork the repo and c
140
138
  3. Commit your Changes (`git commit -m 'Add some AmazingFeature`)
141
139
  4. Push to the Branch (`git push origin feature/AmazingFeature`)
142
140
  5. Open a Pull Request
143
-
144
- Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
141
+
142
+ Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
145
143
 
146
144
  You can also make a small [donation to the author](https://tppay.me/l94qaa3h) of the library.
147
145
 
148
146
  # License
149
147
 
150
148
  Distributed under the MIT License. See `LICENSE.txt` for more information.
151
-
152
-
153
-
154
-
@@ -8,6 +8,8 @@ import { Axios } from "axios";
8
8
  import { TropipayConfig, AccountBalance, Country, PaymentLink, mediationPaymentCardConfig, LoginResponse, AccountDeposits } from "../interfaces";
9
9
  type ServerMode = "Development" | "Production";
10
10
  import { TropipayHooks } from "../hooks/TropipayHooks";
11
+ import { PaymentCard } from "../paymentcard/PaymentCard";
12
+ import { DepositAccounts } from "../depositAccount/depositAccounts";
11
13
  export declare class Tropipay {
12
14
  readonly clientId: string;
13
15
  readonly clientSecret: string;
@@ -16,6 +18,8 @@ export declare class Tropipay {
16
18
  static refreshToken: string | undefined;
17
19
  serverMode: ServerMode;
18
20
  hooks: TropipayHooks;
21
+ paymentCards: PaymentCard;
22
+ depositAccounts: DepositAccounts;
19
23
  constructor(config: TropipayConfig);
20
24
  login(): Promise<LoginResponse>;
21
25
  /**
@@ -0,0 +1,36 @@
1
+ import { Tropipay } from "../api/TropipayAPI";
2
+ import { DepositAccountConfig } from "../interfaces/depositaccounts";
3
+ export declare class DepositAccounts {
4
+ private tropipay;
5
+ constructor(tropipayInstance: Tropipay);
6
+ /**
7
+ * List od all beneficiaries of this account
8
+ * @returns Array of DepositAccounts
9
+ */
10
+ list(): Promise<any>;
11
+ /**
12
+ * Adds a new beneficiary to the user account.
13
+ * @param payload
14
+ * @returns
15
+ */
16
+ create(depositAccountObj: DepositAccountConfig): Promise<any>;
17
+ /**
18
+ * This returns details of a specific
19
+ * Deposit Account (beneficiary) specified by its ID
20
+ * @param id
21
+ * @returns
22
+ */
23
+ get(id: string): Promise<any>;
24
+ /**
25
+ * Updates certain beneficiary data.
26
+ * @param depositAccountObj
27
+ * @returns
28
+ */
29
+ update(depositAccountObj: Partial<DepositAccountConfig>): Promise<any>;
30
+ /**
31
+ * (UNTESTED) Deletes the beneficiary indicated by id
32
+ * @param id
33
+ * @returns
34
+ */
35
+ delete(id: number): Promise<any>;
36
+ }
package/index.d.ts CHANGED
@@ -198,6 +198,87 @@ declare class TropipayHooks {
198
198
  events(): Promise<any>;
199
199
  }
200
200
 
201
+ declare class PaymentCard {
202
+ private tropipay;
203
+ constructor(tropipayInstance: Tropipay);
204
+ /**
205
+ * Create a paymentLink with the specified options.
206
+ * @param payload PaymentLinkPayload Object.
207
+ * @returns Promise<PaymentLink> or throws an Exception.
208
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
209
+ */
210
+ create(payload: PaymentLinkPayload): Promise<PaymentLink>;
211
+ /**
212
+ * Shows a list of stored paymentcards created by user.
213
+ * This list includes active and closed paylinks
214
+ * @returns Array of paymentlinks
215
+ */
216
+ list(): Promise<any>;
217
+ get(id: string): Promise<any>;
218
+ }
219
+
220
+ interface DepositAccountConfig {
221
+ searchValue?: string;
222
+ alias: string;
223
+ userRelationTypeId: number;
224
+ beneficiaryType: BeneficiaryType;
225
+ searchBy?: number;
226
+ accountNumber?: string;
227
+ swift?: string;
228
+ type?: number;
229
+ firstName?: string;
230
+ lastName?: string;
231
+ secondLastName?: string;
232
+ countryDestinationId?: number;
233
+ city?: string;
234
+ postalCode?: number;
235
+ address?: string;
236
+ documentNumber?: string;
237
+ phone?: string;
238
+ province?: string;
239
+ paymentType?: string;
240
+ documentTypeId?: number;
241
+ documentExpirationDate: string;
242
+ }
243
+ type INTERNAL = 1;
244
+ type EXTERNAL = 2;
245
+ type BeneficiaryType = INTERNAL | EXTERNAL;
246
+
247
+ declare class DepositAccounts {
248
+ private tropipay;
249
+ constructor(tropipayInstance: Tropipay);
250
+ /**
251
+ * List od all beneficiaries of this account
252
+ * @returns Array of DepositAccounts
253
+ */
254
+ list(): Promise<any>;
255
+ /**
256
+ * Adds a new beneficiary to the user account.
257
+ * @param payload
258
+ * @returns
259
+ */
260
+ create(depositAccountObj: DepositAccountConfig): Promise<any>;
261
+ /**
262
+ * This returns details of a specific
263
+ * Deposit Account (beneficiary) specified by its ID
264
+ * @param id
265
+ * @returns
266
+ */
267
+ get(id: string): Promise<any>;
268
+ /**
269
+ * Updates certain beneficiary data.
270
+ * @param depositAccountObj
271
+ * @returns
272
+ */
273
+ update(depositAccountObj: Partial<DepositAccountConfig>): Promise<any>;
274
+ /**
275
+ * (UNTESTED) Deletes the beneficiary indicated by id
276
+ * @param id
277
+ * @returns
278
+ */
279
+ delete(id: number): Promise<any>;
280
+ }
281
+
201
282
  /**
202
283
  * Tropipayjs is a Typescript/Javascript library for the Tropipay API.
203
284
  *
@@ -215,6 +296,8 @@ declare class Tropipay {
215
296
  static refreshToken: string | undefined;
216
297
  serverMode: ServerMode;
217
298
  hooks: TropipayHooks;
299
+ paymentCards: PaymentCard;
300
+ depositAccounts: DepositAccounts;
218
301
  constructor(config: TropipayConfig);
219
302
  login(): Promise<LoginResponse>;
220
303
  /**
@@ -300,25 +383,6 @@ declare class ServerSideUtils {
300
383
  } | Tropipay, originalCurrencyAmount: string, bankOrderCode: string, signature: string): boolean;
301
384
  }
302
385
 
303
- declare class PaymentCard {
304
- private tropipay;
305
- constructor(tropipayInstance: Tropipay);
306
- /**
307
- * Create a paymentLink with the specified options.
308
- * @param payload PaymentLinkPayload Object.
309
- * @returns Promise<PaymentLink> or throws an Exception.
310
- * @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
311
- */
312
- create(payload: PaymentLinkPayload): Promise<PaymentLink>;
313
- /**
314
- * Shows a list of stored paymentcards created by user.
315
- * This list includes active and closed paylinks
316
- * @returns Array of paymentlinks
317
- */
318
- list(): Promise<any>;
319
- get(id: string): Promise<any>;
320
- }
321
-
322
386
  declare const SERVER_MODE: ServerMode$1;
323
387
 
324
- export { AccountBalance, AccountDeposits, ClientSideUtils, Country, Deposit, HookEventType, HookTargetType, LoginError, LoginResponse, PaymentCard, PaymentLink, PaymentLinkPayload, SERVER_MODE, ServerMode$1 as ServerMode, ServerSideUtils, Tropipay, TropipayConfig, TropipayCredentials, TropipayHooks, UserHook, UserHookSubscribed, mediationPaymentCardConfig };
388
+ export { AccountBalance, AccountDeposits, ClientSideUtils, Country, Deposit, DepositAccounts, HookEventType, HookTargetType, LoginError, LoginResponse, PaymentCard, PaymentLink, PaymentLinkPayload, SERVER_MODE, ServerMode$1 as ServerMode, ServerSideUtils, Tropipay, TropipayConfig, TropipayCredentials, TropipayHooks, UserHook, UserHookSubscribed, mediationPaymentCardConfig };
package/index.js CHANGED
@@ -158,6 +158,200 @@ class TropipayHooks {
158
158
  }
159
159
  }
160
160
 
161
+ class PaymentCard {
162
+ tropipay;
163
+ constructor(tropipayInstance) {
164
+ this.tropipay = tropipayInstance;
165
+ }
166
+ /**
167
+ * Create a paymentLink with the specified options.
168
+ * @param payload PaymentLinkPayload Object.
169
+ * @returns Promise<PaymentLink> or throws an Exception.
170
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
171
+ */
172
+ async create(payload) {
173
+ if (!Tropipay.accessToken) {
174
+ await this.tropipay.login();
175
+ }
176
+ try {
177
+ const paylink = await this.tropipay.request.post("/api/v2/paymentcards", payload, {
178
+ headers: {
179
+ "Content-Type": "application/json",
180
+ Authorization: `Bearer ${Tropipay.accessToken}`,
181
+ Accept: "application/json",
182
+ },
183
+ });
184
+ return paylink.data;
185
+ }
186
+ catch (error) {
187
+ throw new Error(`TropipayJS - Error creating the Payment Card.`);
188
+ }
189
+ }
190
+ /**
191
+ * Shows a list of stored paymentcards created by user.
192
+ * This list includes active and closed paylinks
193
+ * @returns Array of paymentlinks
194
+ */
195
+ async list() {
196
+ if (!Tropipay.accessToken) {
197
+ await this.tropipay.login();
198
+ }
199
+ try {
200
+ const paymentcards = await this.tropipay.request.get(`/api/v2/paymentcards`, {
201
+ headers: {
202
+ "Content-Type": "application/json",
203
+ Authorization: `Bearer ${Tropipay.accessToken}`,
204
+ Accept: "application/json",
205
+ },
206
+ });
207
+ return paymentcards.data;
208
+ }
209
+ catch (error) {
210
+ throw new Error(`Could not retrieve PaymenCards list`);
211
+ }
212
+ }
213
+ async get(id) {
214
+ if (!Tropipay.accessToken) {
215
+ await this.tropipay.login();
216
+ }
217
+ try {
218
+ const paymentcard = await this.tropipay.request.get(`/api/v2/paymentcards/${id}`, {
219
+ headers: {
220
+ "Content-Type": "application/json",
221
+ Authorization: `Bearer ${Tropipay.accessToken}`,
222
+ Accept: "application/json",
223
+ },
224
+ });
225
+ return paymentcard.data;
226
+ }
227
+ catch (error) {
228
+ throw new Error(`Could not retrieve PaymenCards`);
229
+ }
230
+ }
231
+ }
232
+
233
+ class DepositAccounts {
234
+ tropipay;
235
+ constructor(tropipayInstance) {
236
+ this.tropipay = tropipayInstance;
237
+ }
238
+ /**
239
+ * List od all beneficiaries of this account
240
+ * @returns Array of DepositAccounts
241
+ */
242
+ async list() {
243
+ if (!Tropipay.accessToken) {
244
+ await this.tropipay.login();
245
+ }
246
+ try {
247
+ const deposit = await this.tropipay.request.get(`/api/v2/deposit_accounts`, {
248
+ headers: {
249
+ "Content-Type": "application/json",
250
+ Authorization: `Bearer ${Tropipay.accessToken}`,
251
+ Accept: "application/json",
252
+ },
253
+ });
254
+ return deposit.data;
255
+ }
256
+ catch (error) {
257
+ throw new Error(`Could not retrieve PaymenCards list`);
258
+ }
259
+ }
260
+ /**
261
+ * Adds a new beneficiary to the user account.
262
+ * @param payload
263
+ * @returns
264
+ */
265
+ async create(depositAccountObj) {
266
+ if (!Tropipay.accessToken) {
267
+ await this.tropipay.login();
268
+ }
269
+ try {
270
+ const deposit = await this.tropipay.request.post("/api/v2/deposit_accounts", depositAccountObj, {
271
+ headers: {
272
+ "Content-Type": "application/json",
273
+ Authorization: `Bearer ${Tropipay.accessToken}`,
274
+ Accept: "application/json",
275
+ },
276
+ });
277
+ return deposit.data;
278
+ }
279
+ catch (error) {
280
+ throw new Error(`TropipayJS - Error creating the Deposit Accounts.`);
281
+ }
282
+ }
283
+ /**
284
+ * This returns details of a specific
285
+ * Deposit Account (beneficiary) specified by its ID
286
+ * @param id
287
+ * @returns
288
+ */
289
+ async get(id) {
290
+ if (!Tropipay.accessToken) {
291
+ await this.tropipay.login();
292
+ }
293
+ try {
294
+ const deposit = await this.tropipay.request.get(`/api/v2/deposit_accounts/${id}`, {
295
+ headers: {
296
+ "Content-Type": "application/json",
297
+ Authorization: `Bearer ${Tropipay.accessToken}`,
298
+ Accept: "application/json",
299
+ },
300
+ });
301
+ return deposit.data;
302
+ }
303
+ catch (error) {
304
+ throw new Error(`Could not retrieve deposit account`);
305
+ }
306
+ }
307
+ /**
308
+ * Updates certain beneficiary data.
309
+ * @param depositAccountObj
310
+ * @returns
311
+ */
312
+ async update(depositAccountObj) {
313
+ if (!Tropipay.accessToken) {
314
+ await this.tropipay.login();
315
+ }
316
+ try {
317
+ const deposit = await this.tropipay.request.put(`/api/v2/deposit_accounts/`, {
318
+ headers: {
319
+ "Content-Type": "application/json",
320
+ Authorization: `Bearer ${Tropipay.accessToken}`,
321
+ Accept: "application/json",
322
+ },
323
+ });
324
+ return deposit.data;
325
+ }
326
+ catch (error) {
327
+ throw new Error(`Could not retrieve deposit account`);
328
+ }
329
+ }
330
+ /**
331
+ * (UNTESTED) Deletes the beneficiary indicated by id
332
+ * @param id
333
+ * @returns
334
+ */
335
+ async delete(id) {
336
+ if (!Tropipay.accessToken) {
337
+ await this.tropipay.login();
338
+ }
339
+ try {
340
+ const deposit = await this.tropipay.request.delete(`/api/v2/deposit_accounts/${id}`, {
341
+ headers: {
342
+ "Content-Type": "application/json",
343
+ Authorization: `Bearer ${Tropipay.accessToken}`,
344
+ Accept: "application/json",
345
+ },
346
+ });
347
+ return deposit.data;
348
+ }
349
+ catch (error) {
350
+ throw new Error(`Could not retrieve deposit account`);
351
+ }
352
+ }
353
+ }
354
+
161
355
  /**
162
356
  * Tropipayjs is a Typescript/Javascript library for the Tropipay API.
163
357
  *
@@ -172,6 +366,8 @@ class Tropipay {
172
366
  static refreshToken;
173
367
  serverMode;
174
368
  hooks;
369
+ paymentCards;
370
+ depositAccounts;
175
371
  constructor(config) {
176
372
  this.clientId = config.clientId;
177
373
  this.clientSecret = config.clientSecret;
@@ -187,6 +383,8 @@ class Tropipay {
187
383
  },
188
384
  });
189
385
  this.hooks = new TropipayHooks(this);
386
+ this.paymentCards = new PaymentCard(this);
387
+ this.depositAccounts = new DepositAccounts(this);
190
388
  }
191
389
  async login() {
192
390
  try {
@@ -436,78 +634,6 @@ class ServerSideUtils {
436
634
  }
437
635
  }
438
636
 
439
- class PaymentCard {
440
- tropipay;
441
- constructor(tropipayInstance) {
442
- this.tropipay = tropipayInstance;
443
- }
444
- /**
445
- * Create a paymentLink with the specified options.
446
- * @param payload PaymentLinkPayload Object.
447
- * @returns Promise<PaymentLink> or throws an Exception.
448
- * @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
449
- */
450
- async create(payload) {
451
- if (!Tropipay.accessToken) {
452
- await this.tropipay.login();
453
- }
454
- try {
455
- const paylink = await this.tropipay.request.post("/api/v2/paymentcards", payload, {
456
- headers: {
457
- "Content-Type": "application/json",
458
- Authorization: `Bearer ${Tropipay.accessToken}`,
459
- Accept: "application/json",
460
- },
461
- });
462
- return paylink.data;
463
- }
464
- catch (error) {
465
- throw new Error(`TropipayJS - Error creating the Payment Card.`);
466
- }
467
- }
468
- /**
469
- * Shows a list of stored paymentcards created by user.
470
- * This list includes active and closed paylinks
471
- * @returns Array of paymentlinks
472
- */
473
- async list() {
474
- if (!Tropipay.accessToken) {
475
- await this.tropipay.login();
476
- }
477
- try {
478
- const paymentcards = await this.tropipay.request.get(`/api/v2/paymentcards`, {
479
- headers: {
480
- "Content-Type": "application/json",
481
- Authorization: `Bearer ${Tropipay.accessToken}`,
482
- Accept: "application/json",
483
- },
484
- });
485
- return paymentcards.data;
486
- }
487
- catch (error) {
488
- throw new Error(`Could not retrieve PaymenCards list`);
489
- }
490
- }
491
- async get(id) {
492
- if (!Tropipay.accessToken) {
493
- await this.tropipay.login();
494
- }
495
- try {
496
- const paymentcard = await this.tropipay.request.get(`/api/v2/paymentcards/${id}`, {
497
- headers: {
498
- "Content-Type": "application/json",
499
- Authorization: `Bearer ${Tropipay.accessToken}`,
500
- Accept: "application/json",
501
- },
502
- });
503
- return paymentcard.data;
504
- }
505
- catch (error) {
506
- throw new Error(`Could not retrieve PaymenCards`);
507
- }
508
- }
509
- }
510
-
511
637
  const SERVER_MODE = "Development"; // Move the constant here
512
638
 
513
639
  /**
@@ -526,6 +652,7 @@ if (typeof window !== "undefined") {
526
652
  }
527
653
 
528
654
  exports.ClientSideUtils = ClientSideUtils;
655
+ exports.DepositAccounts = DepositAccounts;
529
656
  exports.PaymentCard = PaymentCard;
530
657
  exports.SERVER_MODE = SERVER_MODE;
531
658
  exports.ServerSideUtils = ServerSideUtils;
@@ -0,0 +1,27 @@
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?: number;
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
+ export type BeneficiaryType = INTERNAL | EXTERNAL;
27
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yosle/tropipayjs",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "Javascript / Typescript SDK for the Tropipay API",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -18,6 +18,8 @@ import {
18
18
  } from "../interfaces";
19
19
  type ServerMode = "Development" | "Production";
20
20
  import { TropipayHooks } from "../hooks/TropipayHooks";
21
+ import { PaymentCard } from "../paymentcard/PaymentCard";
22
+ import { DepositAccounts } from "../depositAccount/depositAccounts";
21
23
  export class Tropipay {
22
24
  readonly clientId: string;
23
25
  readonly clientSecret: string;
@@ -26,6 +28,8 @@ export class Tropipay {
26
28
  public static refreshToken: string | undefined;
27
29
  public serverMode: ServerMode;
28
30
  public hooks: TropipayHooks;
31
+ public paymentCards: PaymentCard;
32
+ public depositAccounts: DepositAccounts;
29
33
 
30
34
  constructor(config: TropipayConfig) {
31
35
  this.clientId = config.clientId;
@@ -43,6 +47,8 @@ export class Tropipay {
43
47
  },
44
48
  });
45
49
  this.hooks = new TropipayHooks(this);
50
+ this.paymentCards = new PaymentCard(this);
51
+ this.depositAccounts = new DepositAccounts(this);
46
52
  }
47
53
 
48
54
  public async login() {
@@ -0,0 +1,138 @@
1
+ import { Tropipay } from "../api/TropipayAPI";
2
+ import { DepositAccountConfig } from "../interfaces/depositaccounts";
3
+
4
+ export class DepositAccounts {
5
+ private tropipay: Tropipay;
6
+ constructor(tropipayInstance: Tropipay) {
7
+ this.tropipay = tropipayInstance;
8
+ }
9
+
10
+ /**
11
+ * List od all beneficiaries of this account
12
+ * @returns Array of DepositAccounts
13
+ */
14
+ public async list() {
15
+ if (!Tropipay.accessToken) {
16
+ await this.tropipay.login();
17
+ }
18
+ try {
19
+ const deposit = await this.tropipay.request.get(
20
+ `/api/v2/deposit_accounts`,
21
+ {
22
+ headers: {
23
+ "Content-Type": "application/json",
24
+ Authorization: `Bearer ${Tropipay.accessToken}`,
25
+ Accept: "application/json",
26
+ },
27
+ }
28
+ );
29
+ return deposit.data;
30
+ } catch (error) {
31
+ throw new Error(`Could not retrieve PaymenCards list`);
32
+ }
33
+ }
34
+ /**
35
+ * Adds a new beneficiary to the user account.
36
+ * @param payload
37
+ * @returns
38
+ */
39
+ public async create(depositAccountObj: DepositAccountConfig) {
40
+ if (!Tropipay.accessToken) {
41
+ await this.tropipay.login();
42
+ }
43
+ try {
44
+ const deposit = await this.tropipay.request.post(
45
+ "/api/v2/deposit_accounts",
46
+ depositAccountObj,
47
+ {
48
+ headers: {
49
+ "Content-Type": "application/json",
50
+ Authorization: `Bearer ${Tropipay.accessToken}`,
51
+ Accept: "application/json",
52
+ },
53
+ }
54
+ );
55
+ return deposit.data;
56
+ } catch (error) {
57
+ throw new Error(`TropipayJS - Error creating the Deposit Accounts.`);
58
+ }
59
+ }
60
+ /**
61
+ * This returns details of a specific
62
+ * Deposit Account (beneficiary) specified by its ID
63
+ * @param id
64
+ * @returns
65
+ */
66
+ public async get(id: string) {
67
+ if (!Tropipay.accessToken) {
68
+ await this.tropipay.login();
69
+ }
70
+ try {
71
+ const deposit = await this.tropipay.request.get(
72
+ `/api/v2/deposit_accounts/${id}`,
73
+ {
74
+ headers: {
75
+ "Content-Type": "application/json",
76
+ Authorization: `Bearer ${Tropipay.accessToken}`,
77
+ Accept: "application/json",
78
+ },
79
+ }
80
+ );
81
+ return deposit.data;
82
+ } catch (error) {
83
+ throw new Error(`Could not retrieve deposit account`);
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Updates certain beneficiary data.
89
+ * @param depositAccountObj
90
+ * @returns
91
+ */
92
+ public async update(depositAccountObj: Partial<DepositAccountConfig>) {
93
+ if (!Tropipay.accessToken) {
94
+ await this.tropipay.login();
95
+ }
96
+ try {
97
+ const deposit = await this.tropipay.request.put(
98
+ `/api/v2/deposit_accounts/`,
99
+ {
100
+ headers: {
101
+ "Content-Type": "application/json",
102
+ Authorization: `Bearer ${Tropipay.accessToken}`,
103
+ Accept: "application/json",
104
+ },
105
+ }
106
+ );
107
+ return deposit.data;
108
+ } catch (error) {
109
+ throw new Error(`Could not retrieve deposit account`);
110
+ }
111
+ }
112
+
113
+ /**
114
+ * (UNTESTED) Deletes the beneficiary indicated by id
115
+ * @param id
116
+ * @returns
117
+ */
118
+ public async delete(id: number) {
119
+ if (!Tropipay.accessToken) {
120
+ await this.tropipay.login();
121
+ }
122
+ try {
123
+ const deposit = await this.tropipay.request.delete(
124
+ `/api/v2/deposit_accounts/${id}`,
125
+ {
126
+ headers: {
127
+ "Content-Type": "application/json",
128
+ Authorization: `Bearer ${Tropipay.accessToken}`,
129
+ Accept: "application/json",
130
+ },
131
+ }
132
+ );
133
+ return deposit.data;
134
+ } catch (error) {
135
+ throw new Error(`Could not retrieve deposit account`);
136
+ }
137
+ }
138
+ }
package/src/index.ts CHANGED
@@ -10,6 +10,8 @@
10
10
  * @license MIT
11
11
  */
12
12
 
13
+ import { DepositAccounts } from "./depositAccount/depositAccounts";
14
+
13
15
  if (typeof window !== "undefined") {
14
16
  console.warn(
15
17
  "DANGER This library should not be used client side, your credentials could be exposed"
@@ -21,6 +23,7 @@ export { ClientSideUtils } from "./api/TropipayAPI";
21
23
  export { ServerSideUtils } from "./utils/TropipayUtils";
22
24
  export { TropipayHooks } from "./hooks/TropipayHooks";
23
25
  export { PaymentCard } from "./paymentcard/PaymentCard";
26
+ export { DepositAccounts } from "./depositAccount/depositAccounts";
24
27
  export * from "./interfaces/index";
25
28
  export { SERVER_MODE } from "./config/TropipayConfig";
26
29
  export * from "./constants/TropipayConstants";
@@ -0,0 +1,27 @@
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?: number;
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;
@@ -3,7 +3,6 @@ import { PaymentLink } from "../interfaces";
3
3
  import { PaymentLinkPayload } from "../interfaces";
4
4
  export class PaymentCard {
5
5
  private tropipay: Tropipay;
6
-
7
6
  constructor(tropipayInstance: Tropipay) {
8
7
  this.tropipay = tropipayInstance;
9
8
  }