@yosle/tropipayjs 0.1.20 → 0.1.22

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.
@@ -0,0 +1,18 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "type": "node",
9
+ "name": "vscode-jest-tests",
10
+ "request": "launch",
11
+ "program": "${workspaceFolder}/node_modules/jest/bin/jest",
12
+ "args": ["paymentcard.spec.ts"],
13
+ "cwd": "${workspaceFolder}",
14
+ "console": "integratedTerminal",
15
+ "runtimeExecutable": "/home/yosle/.nvm/versions/node/v20.10.0/bin/node"
16
+ }
17
+ ]
18
+ }
package/README.md CHANGED
@@ -47,7 +47,7 @@ or
47
47
 
48
48
  ## Setting up your app credentials
49
49
 
50
- ![alt](https://yosle.github.io/tropipayjs-docs/images/cred1.png)
50
+ ![alt](https://yosle.github.io/tropipayjs-docs/images/cred2.png)
51
51
  ![alt](https://yosle.github.io/tropipayjs-docs/images/cred3.png)
52
52
 
53
53
  In order to use the Tropipay API you'll need a client ID and a client secret. Sign up with your [Tropipay](www.tropipay.com) account, go to the App Menu->Applications and credentials. You'll be asked to enter a confirmation code (use 123456 in the test enviroment). _Make sure you test everything in the [test environment](https://tropipay-dev.herokuapp.com) first before using your real account._ Create an app and configure the client id an client secret for the app.
@@ -5,21 +5,29 @@
5
5
  *
6
6
  */
7
7
  import { Axios } from "axios";
8
- import { TropipayConfig, AccountBalance, Country, PaymentLink, mediationPaymentCardConfig, LoginResponse } from "../interfaces";
8
+ import { TropipayConfig, AccountBalance, Country, PaymentLink, MediationPaymentCardConfig, LoginResponse } from "../interfaces";
9
9
  type ServerMode = "Development" | "Production";
10
- import { TropipayHooks } from "../hooks/TropipayHooks";
11
- import { PaymentCard } from "../paymentcard/PaymentCard";
12
- import { DepositAccounts } from "../depositAccount/depositAccounts";
10
+ import TropipayHooks from "../hooks/TropipayHooks";
11
+ import PaymentCard from "../paymentcard/PaymentCard";
12
+ import MediationPaymentCard from "../mediationPaymentCard/MediationPaymentCard";
13
+ import DepositAccounts from "../depositAccount/depositAccounts";
13
14
  export declare class Tropipay {
14
15
  readonly clientId: string;
15
16
  readonly clientSecret: string;
17
+ readonly scopes: String[];
16
18
  request: Axios;
17
- static accessToken: string | undefined;
18
- static refreshToken: string | undefined;
19
+ static accessToken: string | null;
20
+ static refreshToken: string | null;
19
21
  serverMode: ServerMode;
20
22
  hooks: TropipayHooks;
21
23
  paymentCards: PaymentCard;
22
24
  depositAccounts: DepositAccounts;
25
+ mediationPaymentCard: MediationPaymentCard;
26
+ /**
27
+ * Initializes a new instance of the Tropipay class.
28
+ *
29
+ * @param {TropipayConfig} config - The configuration object.
30
+ */
23
31
  constructor(config: TropipayConfig);
24
32
  login(): Promise<LoginResponse>;
25
33
  /**
@@ -76,9 +84,19 @@ export declare class Tropipay {
76
84
  * @see https://tpp.stoplight.io/docs/tropipay-api-doc/12a128ff971e4-creating-a-mediation-payment-card
77
85
  * @param config Payload with the payment details
78
86
  */
79
- createMediationPaymentCard(config: mediationPaymentCardConfig): Promise<PaymentLink>;
87
+ createMediationPaymentCard(config: MediationPaymentCardConfig): Promise<PaymentLink>;
80
88
  }
81
89
  export declare class ClientSideUtils {
82
90
  constructor(tropipayInstance: Tropipay);
83
91
  }
92
+ export declare const Scopes: {
93
+ ALLOW_PAYMENT_IN: string;
94
+ ALLOW_EXTERNAL_CHARGE: string;
95
+ KYC3_FULL_ALLOW: string;
96
+ ALLOW_PAYMENT_OUT: string;
97
+ ALLOW_MARKET_PURCHASES: string;
98
+ ALLOW_GET_BALANCE: string;
99
+ ALLOW_GET_MOVEMENT_LIST: string;
100
+ ALLOW_GET_CREDENTIAL: string;
101
+ };
84
102
  export {};
@@ -1,6 +1,6 @@
1
1
  import { Tropipay } from "../api/TropipayAPI";
2
2
  import { DepositAccountConfig } from "../interfaces/depositaccounts";
3
- export declare class DepositAccounts {
3
+ export default class DepositAccounts {
4
4
  private tropipay;
5
5
  constructor(tropipayInstance: Tropipay);
6
6
  /**
@@ -1,6 +1,6 @@
1
1
  import { HookEventType, UserHookSubscribed } from "../interfaces";
2
2
  import { Tropipay } from "../api/TropipayAPI";
3
- export declare class TropipayHooks {
3
+ export default class TropipayHooks {
4
4
  private tropipay;
5
5
  constructor(tropipayInstance: Tropipay);
6
6
  /**
@@ -25,14 +25,14 @@ export declare class TropipayHooks {
25
25
  value: string;
26
26
  }): Promise<any>;
27
27
  /**
28
- * Get the sucbcribed hook info by his event type.
28
+ * Get the subscribed hook info by his event type.
29
29
  * If no event type is passed, it will return
30
30
  * all subscribed hooks or empty Array if none exist.
31
31
  * @param eventType or no params for retrieving all hooks
32
32
  * @returns All subscribed hooks or empty Array if none exist.
33
33
  */
34
34
  list(eventType?: HookEventType): Promise<UserHookSubscribed[]>;
35
- update(eventType: string, target: "web" | "email", value: string): Promise<any>;
35
+ update(eventType: HookEventType, target: "web" | "email", value: string): Promise<any>;
36
36
  delete(eventType: HookEventType, target: string): Promise<any>;
37
37
  events(): Promise<any>;
38
38
  }
package/index.d.ts CHANGED
@@ -11,6 +11,7 @@ type AccountBalance = {
11
11
  interface TropipayConfig {
12
12
  clientId: string;
13
13
  clientSecret: string;
14
+ scopes?: string[];
14
15
  serverMode?: ServerMode$1;
15
16
  }
16
17
  type TropipayCredentials = {
@@ -58,12 +59,14 @@ interface PaymentLinkPayload {
58
59
  address: string;
59
60
  phone: string;
60
61
  email: string;
61
- countryId: number;
62
+ countryId?: number;
63
+ countryIso?: string;
62
64
  termsAndConditions: boolean;
63
- };
65
+ } | null;
64
66
  directPayment: boolean;
65
67
  paymentMethods?: string[];
66
68
  imageBase?: string;
69
+ saveToken?: boolean;
67
70
  }
68
71
  interface PaymentLink extends PaymentLinkPayload {
69
72
  expirationDate: string;
@@ -74,7 +77,7 @@ interface PaymentLink extends PaymentLinkPayload {
74
77
  shortUrl: string;
75
78
  paymentUrl: string;
76
79
  }
77
- interface mediationPaymentCardConfig {
80
+ interface MediationPaymentCardConfig {
78
81
  amount: number;
79
82
  currency: "EUR" | "USD";
80
83
  concept: string;
@@ -188,14 +191,14 @@ declare class TropipayHooks {
188
191
  value: string;
189
192
  }): Promise<any>;
190
193
  /**
191
- * Get the sucbcribed hook info by his event type.
194
+ * Get the subscribed hook info by his event type.
192
195
  * If no event type is passed, it will return
193
196
  * all subscribed hooks or empty Array if none exist.
194
197
  * @param eventType or no params for retrieving all hooks
195
198
  * @returns All subscribed hooks or empty Array if none exist.
196
199
  */
197
200
  list(eventType?: HookEventType): Promise<UserHookSubscribed[]>;
198
- update(eventType: string, target: "web" | "email", value: string): Promise<any>;
201
+ update(eventType: HookEventType, target: "web" | "email", value: string): Promise<any>;
199
202
  delete(eventType: HookEventType, target: string): Promise<any>;
200
203
  events(): Promise<any>;
201
204
  }
@@ -216,7 +219,38 @@ declare class PaymentCard {
216
219
  * @returns Array of paymentlinks
217
220
  */
218
221
  list(): Promise<any>;
222
+ /**
223
+ * Retrieves a payment card with the specified ID.
224
+ *
225
+ * @param {string} id - The ID of the payment card to retrieve.
226
+ * @return {Promise<any>} A Promise that resolves to the payment card data.
227
+ * @throws {Error} If an error occurs while retrieving the payment card.
228
+ */
219
229
  get(id: string): Promise<any>;
230
+ /**
231
+ * Deletes a payment card with the specified ID. Its a LOGIC delete
232
+ * so this will delete the paymentcard from paymentcard list and
233
+ * disable shortUrl but not paymentUrl
234
+ * @param {string} id - The ID of the payment card to delete.
235
+ * @return {Promise<any>} A Promise that resolves to the deleted payment card data.
236
+ * @throws {Error} If an error occurs while deleting the payment card.
237
+ */
238
+ delete(id: string): Promise<any>;
239
+ }
240
+
241
+ declare class MediationPaymentCard {
242
+ private tropipay;
243
+ constructor(tropipayInstance: Tropipay);
244
+ /**
245
+ * (ONLY FOR BUSINESS ACCOUNTS) Create a mediation paymentcard (an escrow payment link) with the specified options.
246
+ * This allows a payment to be made to persons belonging or not to the TropiPay platform with the
247
+ * particularity that the payment will be held in custody or retained until it is released with
248
+ * the approval of the payer.
249
+ * @param payload PaymentLinkPayload Object.
250
+ * @returns Promise<PaymentLink> or throws an Exception.
251
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/12a128ff971e4-creating-a-mediation-payment-card
252
+ */
253
+ create(payload: MediationPaymentCardConfig): Promise<PaymentLink>;
220
254
  }
221
255
 
222
256
  interface DepositAccountConfig {
@@ -294,13 +328,20 @@ type ServerMode = "Development" | "Production";
294
328
  declare class Tropipay {
295
329
  readonly clientId: string;
296
330
  readonly clientSecret: string;
331
+ readonly scopes: String[];
297
332
  request: Axios;
298
- static accessToken: string | undefined;
299
- static refreshToken: string | undefined;
333
+ static accessToken: string | null;
334
+ static refreshToken: string | null;
300
335
  serverMode: ServerMode;
301
336
  hooks: TropipayHooks;
302
337
  paymentCards: PaymentCard;
303
338
  depositAccounts: DepositAccounts;
339
+ mediationPaymentCard: MediationPaymentCard;
340
+ /**
341
+ * Initializes a new instance of the Tropipay class.
342
+ *
343
+ * @param {TropipayConfig} config - The configuration object.
344
+ */
304
345
  constructor(config: TropipayConfig);
305
346
  login(): Promise<LoginResponse>;
306
347
  /**
@@ -357,7 +398,7 @@ declare class Tropipay {
357
398
  * @see https://tpp.stoplight.io/docs/tropipay-api-doc/12a128ff971e4-creating-a-mediation-payment-card
358
399
  * @param config Payload with the payment details
359
400
  */
360
- createMediationPaymentCard(config: mediationPaymentCardConfig): Promise<PaymentLink>;
401
+ createMediationPaymentCard(config: MediationPaymentCardConfig): Promise<PaymentLink>;
361
402
  }
362
403
  declare class ClientSideUtils {
363
404
  constructor(tropipayInstance: Tropipay);
@@ -410,4 +451,4 @@ declare class ServerSideUtils {
410
451
 
411
452
  declare const SERVER_MODE: ServerMode$1;
412
453
 
413
- export { AccountBalance, AccountDeposits, ClientSideUtils, Country, Deposit, DepositAccounts, HookEventType, HookTargetType, LoginError, LoginResponse, MAX_IMAGE_SIZE_MB, PaymentCard, PaymentLink, PaymentLinkPayload, SERVER_MODE, ServerMode$1 as ServerMode, ServerSideUtils, Tropipay, TropipayConfig, TropipayCredentials, TropipayHooks, UserHook, UserHookSubscribed, mediationPaymentCardConfig };
454
+ export { AccountBalance, AccountDeposits, ClientSideUtils, Country, Deposit, HookEventType, HookTargetType, LoginError, LoginResponse, MAX_IMAGE_SIZE_MB, MediationPaymentCardConfig, PaymentLink, PaymentLinkPayload, SERVER_MODE, ServerMode$1 as ServerMode, ServerSideUtils, Tropipay, TropipayConfig, TropipayCredentials, UserHook, UserHookSubscribed };
package/index.js CHANGED
@@ -36,14 +36,13 @@ function handleExceptions(error) {
36
36
  const axiosResponse = error.response;
37
37
  const errorMessage = axiosResponse.data?.error?.message || "An error occurred";
38
38
  switch (axiosResponse.status) {
39
+ case 400:
39
40
  case 401:
40
- return new TropipayJSException(errorMessage, axiosResponse.status, axiosResponse.data.error);
41
41
  case 403:
42
- return new TropipayJSException(errorMessage, axiosResponse.status, axiosResponse.data.error);
43
42
  case 404:
44
43
  return new TropipayJSException(errorMessage, axiosResponse.status, axiosResponse.data.error);
45
- // case 429:
46
- // return new TooManyRequestsException(errorMessage);
44
+ case 429:
45
+ return new TropipayJSException(`${errorMessage} Too many request or rate limited`, axiosResponse.status, axiosResponse.data.error);
47
46
  default:
48
47
  return new TropipayJSException(errorMessage, axiosResponse.status, axiosResponse.data.error);
49
48
  }
@@ -58,7 +57,7 @@ function handleExceptions(error) {
58
57
  }
59
58
  }
60
59
  else {
61
- return new TropipayJSException(`jsbfvbsfvbf`, 500, null);
60
+ return new TropipayJSException("An Unknown error occurred", 500, null);
62
61
  }
63
62
  }
64
63
  class TropipayJSException extends Error {
@@ -120,7 +119,7 @@ class TropipayHooks {
120
119
  }
121
120
  }
122
121
  /**
123
- * Get the sucbcribed hook info by his event type.
122
+ * Get the subscribed hook info by his event type.
124
123
  * If no event type is passed, it will return
125
124
  * all subscribed hooks or empty Array if none exist.
126
125
  * @param eventType or no params for retrieving all hooks
@@ -257,6 +256,13 @@ class PaymentCard {
257
256
  throw new Error(`Could not retrieve PaymenCards list`);
258
257
  }
259
258
  }
259
+ /**
260
+ * Retrieves a payment card with the specified ID.
261
+ *
262
+ * @param {string} id - The ID of the payment card to retrieve.
263
+ * @return {Promise<any>} A Promise that resolves to the payment card data.
264
+ * @throws {Error} If an error occurs while retrieving the payment card.
265
+ */
260
266
  async get(id) {
261
267
  if (!Tropipay.accessToken) {
262
268
  await this.tropipay.login();
@@ -275,6 +281,69 @@ class PaymentCard {
275
281
  throw handleExceptions(error);
276
282
  }
277
283
  }
284
+ /**
285
+ * Deletes a payment card with the specified ID. Its a LOGIC delete
286
+ * so this will delete the paymentcard from paymentcard list and
287
+ * disable shortUrl but not paymentUrl
288
+ * @param {string} id - The ID of the payment card to delete.
289
+ * @return {Promise<any>} A Promise that resolves to the deleted payment card data.
290
+ * @throws {Error} If an error occurs while deleting the payment card.
291
+ */
292
+ async delete(id) {
293
+ if (!Tropipay.accessToken) {
294
+ await this.tropipay.login();
295
+ }
296
+ try {
297
+ const paymentcard = await this.tropipay.request.delete(`/api/v2/paymentcards/`, {
298
+ headers: {
299
+ "Content-Type": "application/json",
300
+ Authorization: `Bearer ${Tropipay.accessToken}`,
301
+ Accept: "application/json",
302
+ },
303
+ data: {
304
+ cardId: id,
305
+ },
306
+ });
307
+ return paymentcard.data;
308
+ }
309
+ catch (error) {
310
+ throw handleExceptions(error);
311
+ }
312
+ }
313
+ }
314
+
315
+ class MediationPaymentCard {
316
+ tropipay;
317
+ constructor(tropipayInstance) {
318
+ this.tropipay = tropipayInstance;
319
+ }
320
+ /**
321
+ * (ONLY FOR BUSINESS ACCOUNTS) Create a mediation paymentcard (an escrow payment link) with the specified options.
322
+ * This allows a payment to be made to persons belonging or not to the TropiPay platform with the
323
+ * particularity that the payment will be held in custody or retained until it is released with
324
+ * the approval of the payer.
325
+ * @param payload PaymentLinkPayload Object.
326
+ * @returns Promise<PaymentLink> or throws an Exception.
327
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/12a128ff971e4-creating-a-mediation-payment-card
328
+ */
329
+ async create(payload) {
330
+ if (!Tropipay.accessToken) {
331
+ await this.tropipay.login();
332
+ }
333
+ try {
334
+ const paylink = await this.tropipay.request.post("/api/v2/paymentcards/mediation", payload, {
335
+ headers: {
336
+ "Content-Type": "application/json",
337
+ Authorization: `Bearer ${Tropipay.accessToken}`,
338
+ Accept: "application/json",
339
+ },
340
+ });
341
+ return paylink.data;
342
+ }
343
+ catch (error) {
344
+ throw handleExceptions(error);
345
+ }
346
+ }
278
347
  }
279
348
 
280
349
  class DepositAccounts {
@@ -408,6 +477,7 @@ class DepositAccounts {
408
477
  class Tropipay {
409
478
  clientId;
410
479
  clientSecret;
480
+ scopes;
411
481
  request;
412
482
  static accessToken;
413
483
  static refreshToken;
@@ -415,7 +485,33 @@ class Tropipay {
415
485
  hooks;
416
486
  paymentCards;
417
487
  depositAccounts;
488
+ mediationPaymentCard;
489
+ /**
490
+ * Initializes a new instance of the Tropipay class.
491
+ *
492
+ * @param {TropipayConfig} config - The configuration object.
493
+ */
418
494
  constructor(config) {
495
+ // use all scopes if none is passed
496
+ if (!config?.scopes) {
497
+ this.scopes = [
498
+ "ALLOW_GET_PROFILE_DATA",
499
+ "ALLOW_PAYMENT_IN",
500
+ "ALLOW_EXTERNAL_CHARGE",
501
+ "KYC3_FULL_ALLOW",
502
+ "ALLOW_PAYMENT_OUT",
503
+ "ALLOW_MARKET_PURCHASES",
504
+ "ALLOW_GET_BALANCE",
505
+ "ALLOW_GET_MOVEMENT_LIST",
506
+ "ALLOW_GET_CREDENTIAL",
507
+ ];
508
+ }
509
+ else {
510
+ this.scopes = config.scopes;
511
+ }
512
+ if (!config.clientId || !config.clientSecret) {
513
+ throw new TropipayJSException(`You must pass clientId and clientSecret in Tropipay constructor`, 400, null);
514
+ }
419
515
  this.clientId = config.clientId;
420
516
  this.clientSecret = config.clientSecret;
421
517
  this.serverMode = config.serverMode || "Development";
@@ -431,15 +527,31 @@ class Tropipay {
431
527
  });
432
528
  this.hooks = new TropipayHooks(this);
433
529
  this.paymentCards = new PaymentCard(this);
530
+ this.mediationPaymentCard = new MediationPaymentCard(this);
434
531
  this.depositAccounts = new DepositAccounts(this);
435
532
  }
436
533
  async login() {
437
534
  try {
535
+ if (Tropipay.refreshToken) {
536
+ const { data } = await this.request.post("/api/v2/access/token", {
537
+ client_id: this.clientId,
538
+ client_secret: this.clientSecret,
539
+ grant_type: "refresh_token",
540
+ refresh_token: Tropipay.refreshToken,
541
+ }, {
542
+ headers: {
543
+ "Content-Type": "application/json",
544
+ Accept: "application/json",
545
+ },
546
+ });
547
+ return data;
548
+ }
549
+ // normal credetials login
438
550
  const { data } = await this.request.post("/api/v2/access/token", {
439
551
  client_id: this.clientId,
440
552
  client_secret: this.clientSecret,
441
553
  grant_type: "client_credentials",
442
- scope: "ALLOW_GET_PROFILE_DATA ALLOW_PAYMENT_IN ALLOW_EXTERNAL_CHARGE KYC3_FULL_ALLOW ALLOW_PAYMENT_OUT ALLOW_MARKET_PURCHASES ALLOW_GET_BALANCE ALLOW_GET_MOVEMENT_LIST ALLOW_GET_CREDENTIAL",
554
+ scope: this.scopes.join(" "), // "ALLOW_GET_PROFILE_DATA ALLOW_PAYMENT_IN ALLOW_EXTERNAL_CHARGE KYC3_FULL_ALLOW ALLOW_PAYMENT_OUT ALLOW_MARKET_PURCHASES ALLOW_GET_BALANCE ALLOW_GET_MOVEMENT_LIST ALLOW_GET_CREDENTIAL",
443
555
  }, {
444
556
  headers: {
445
557
  "Content-Type": "application/json",
@@ -451,6 +563,8 @@ class Tropipay {
451
563
  return data;
452
564
  }
453
565
  catch (error) {
566
+ Tropipay.accessToken = null;
567
+ Tropipay.refreshToken = null;
454
568
  throw handleExceptions(error);
455
569
  }
456
570
  }
@@ -749,11 +863,8 @@ if (typeof window !== "undefined") {
749
863
  }
750
864
 
751
865
  exports.ClientSideUtils = ClientSideUtils;
752
- exports.DepositAccounts = DepositAccounts;
753
866
  exports.MAX_IMAGE_SIZE_MB = MAX_IMAGE_SIZE_MB;
754
- exports.PaymentCard = PaymentCard;
755
867
  exports.SERVER_MODE = SERVER_MODE;
756
868
  exports.ServerSideUtils = ServerSideUtils;
757
869
  exports.Tropipay = Tropipay;
758
- exports.TropipayHooks = TropipayHooks;
759
870
  //# sourceMappingURL=index.js.map
@@ -7,6 +7,7 @@ export type AccountBalance = {
7
7
  export interface TropipayConfig {
8
8
  clientId: string;
9
9
  clientSecret: string;
10
+ scopes?: string[];
10
11
  serverMode?: ServerMode;
11
12
  }
12
13
  export type TropipayCredentials = {
@@ -54,12 +55,14 @@ export interface PaymentLinkPayload {
54
55
  address: string;
55
56
  phone: string;
56
57
  email: string;
57
- countryId: number;
58
+ countryId?: number;
59
+ countryIso?: string;
58
60
  termsAndConditions: boolean;
59
- };
61
+ } | null;
60
62
  directPayment: boolean;
61
63
  paymentMethods?: string[];
62
64
  imageBase?: string;
65
+ saveToken?: boolean;
63
66
  }
64
67
  export interface PaymentLink extends PaymentLinkPayload {
65
68
  expirationDate: string;
@@ -70,7 +73,7 @@ export interface PaymentLink extends PaymentLinkPayload {
70
73
  shortUrl: string;
71
74
  paymentUrl: string;
72
75
  }
73
- export interface mediationPaymentCardConfig {
76
+ export interface MediationPaymentCardConfig {
74
77
  amount: number;
75
78
  currency: "EUR" | "USD";
76
79
  concept: string;
package/jest.config.js ADDED
@@ -0,0 +1,5 @@
1
+ /** @type {import('ts-jest').JestConfigWithTsJest} */
2
+ module.exports = {
3
+ preset: "ts-jest",
4
+ testEnvironment: "node",
5
+ };
@@ -0,0 +1,17 @@
1
+ import { Tropipay } from "../api/TropipayAPI";
2
+ import { PaymentLink } from "../interfaces";
3
+ import { MediationPaymentCardConfig } from "../interfaces";
4
+ export default class MediationPaymentCard {
5
+ private tropipay;
6
+ constructor(tropipayInstance: Tropipay);
7
+ /**
8
+ * (ONLY FOR BUSINESS ACCOUNTS) Create a mediation paymentcard (an escrow payment link) with the specified options.
9
+ * This allows a payment to be made to persons belonging or not to the TropiPay platform with the
10
+ * particularity that the payment will be held in custody or retained until it is released with
11
+ * the approval of the payer.
12
+ * @param payload PaymentLinkPayload Object.
13
+ * @returns Promise<PaymentLink> or throws an Exception.
14
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/12a128ff971e4-creating-a-mediation-payment-card
15
+ */
16
+ create(payload: MediationPaymentCardConfig): Promise<PaymentLink>;
17
+ }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@yosle/tropipayjs",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "description": "Javascript / Typescript SDK for the Tropipay API",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "test": "vitest run",
7
+ "test": "jest --passWithNoTests --updateSnapshot --coverage",
8
8
  "_clear": "rimraf src/dist/*",
9
9
  "_tsc": "tsc",
10
10
  "_make-bundle": "rollup --config",
@@ -30,13 +30,17 @@
30
30
  },
31
31
  "devDependencies": {
32
32
  "@rollup/plugin-typescript": "^8.5.0",
33
+ "@types/jest": "^29.5.12",
34
+ "@types/node": "^20.12.7",
33
35
  "@types/tough-cookie": "^4.0.5",
36
+ "babel-jest": "^29.7.0",
37
+ "jest": "^29.7.0",
34
38
  "rimraf": "^3.0.2",
35
39
  "rollup": "^2.79.1",
36
40
  "rollup-plugin-dts": "^4.2.2",
37
41
  "run-s": "^0.0.0",
38
- "typescript": "^5.0.4",
39
- "vitest": "^1.2.2"
42
+ "ts-jest": "^29.1.2",
43
+ "typescript": "^5.4.5"
40
44
  },
41
45
  "funding": {
42
46
  "type": "individual",
@@ -1,7 +1,7 @@
1
1
  import { Tropipay } from "../api/TropipayAPI";
2
2
  import { PaymentLink } from "../interfaces";
3
3
  import { PaymentLinkPayload } from "../interfaces";
4
- export declare class PaymentCard {
4
+ export default class PaymentCard {
5
5
  private tropipay;
6
6
  constructor(tropipayInstance: Tropipay);
7
7
  /**
@@ -17,5 +17,21 @@ export declare class PaymentCard {
17
17
  * @returns Array of paymentlinks
18
18
  */
19
19
  list(): Promise<any>;
20
+ /**
21
+ * Retrieves a payment card with the specified ID.
22
+ *
23
+ * @param {string} id - The ID of the payment card to retrieve.
24
+ * @return {Promise<any>} A Promise that resolves to the payment card data.
25
+ * @throws {Error} If an error occurs while retrieving the payment card.
26
+ */
20
27
  get(id: string): Promise<any>;
28
+ /**
29
+ * Deletes a payment card with the specified ID. Its a LOGIC delete
30
+ * so this will delete the paymentcard from paymentcard list and
31
+ * disable shortUrl but not paymentUrl
32
+ * @param {string} id - The ID of the payment card to delete.
33
+ * @return {Promise<any>} A Promise that resolves to the deleted payment card data.
34
+ * @throws {Error} If an error occurs while deleting the payment card.
35
+ */
36
+ delete(id: string): Promise<any>;
21
37
  }
@@ -1 +1 @@
1
- export {};
1
+ declare function sum(a: number, b: number): number;
@@ -12,27 +12,61 @@ import {
12
12
  Country,
13
13
  PaymentLinkPayload,
14
14
  PaymentLink,
15
- mediationPaymentCardConfig,
15
+ MediationPaymentCardConfig,
16
16
  LoginResponse,
17
17
  AccountDeposits,
18
18
  } from "../interfaces";
19
19
  type ServerMode = "Development" | "Production";
20
- import { TropipayHooks } from "../hooks/TropipayHooks";
21
- import { PaymentCard } from "../paymentcard/PaymentCard";
22
- import { DepositAccounts } from "../depositAccount/depositAccounts";
23
- import { handleExceptions } from "../utils/errors";
20
+ import TropipayHooks from "../hooks/TropipayHooks";
21
+ import PaymentCard from "../paymentcard/PaymentCard";
22
+ import MediationPaymentCard from "../mediationPaymentCard/MediationPaymentCard";
23
+ import DepositAccounts from "../depositAccount/depositAccounts";
24
+ import { TropipayJSException, handleExceptions } from "../utils/errors";
24
25
  export class Tropipay {
25
26
  readonly clientId: string;
26
27
  readonly clientSecret: string;
28
+ readonly scopes: String[];
27
29
  public request: Axios;
28
- public static accessToken: string | undefined;
29
- public static refreshToken: string | undefined;
30
+ public static accessToken: string | null;
31
+ public static refreshToken: string | null;
30
32
  public serverMode: ServerMode;
31
33
  public hooks: TropipayHooks;
32
34
  public paymentCards: PaymentCard;
33
35
  public depositAccounts: DepositAccounts;
36
+ public mediationPaymentCard: MediationPaymentCard;
37
+
38
+ /**
39
+ * Initializes a new instance of the Tropipay class.
40
+ *
41
+ * @param {TropipayConfig} config - The configuration object.
42
+ */
34
43
 
35
44
  constructor(config: TropipayConfig) {
45
+ // use all scopes if none is passed
46
+ if (!config?.scopes) {
47
+ this.scopes = [
48
+ "ALLOW_GET_PROFILE_DATA",
49
+ "ALLOW_PAYMENT_IN",
50
+ "ALLOW_EXTERNAL_CHARGE",
51
+ "KYC3_FULL_ALLOW",
52
+ "ALLOW_PAYMENT_OUT",
53
+ "ALLOW_MARKET_PURCHASES",
54
+ "ALLOW_GET_BALANCE",
55
+ "ALLOW_GET_MOVEMENT_LIST",
56
+ "ALLOW_GET_CREDENTIAL",
57
+ ];
58
+ } else {
59
+ this.scopes = config.scopes;
60
+ }
61
+
62
+ if (!config.clientId || !config.clientSecret) {
63
+ throw new TropipayJSException(
64
+ `You must pass clientId and clientSecret in Tropipay constructor`,
65
+ 400,
66
+ null
67
+ );
68
+ }
69
+
36
70
  this.clientId = config.clientId;
37
71
  this.clientSecret = config.clientSecret;
38
72
  this.serverMode = config.serverMode || "Development";
@@ -49,19 +83,40 @@ export class Tropipay {
49
83
  });
50
84
  this.hooks = new TropipayHooks(this);
51
85
  this.paymentCards = new PaymentCard(this);
86
+ this.mediationPaymentCard = new MediationPaymentCard(this);
87
+
52
88
  this.depositAccounts = new DepositAccounts(this);
53
89
  }
54
90
 
55
91
  public async login() {
56
92
  try {
93
+ if (Tropipay.refreshToken) {
94
+ const { data } = await this.request.post<LoginResponse>(
95
+ "/api/v2/access/token",
96
+ {
97
+ client_id: this.clientId,
98
+ client_secret: this.clientSecret,
99
+ grant_type: "refresh_token",
100
+ refresh_token: Tropipay.refreshToken,
101
+ },
102
+ {
103
+ headers: {
104
+ "Content-Type": "application/json",
105
+ Accept: "application/json",
106
+ },
107
+ }
108
+ );
109
+ return data;
110
+ }
111
+
112
+ // normal credetials login
57
113
  const { data } = await this.request.post<LoginResponse>(
58
114
  "/api/v2/access/token",
59
115
  {
60
116
  client_id: this.clientId,
61
117
  client_secret: this.clientSecret,
62
118
  grant_type: "client_credentials",
63
- scope:
64
- "ALLOW_GET_PROFILE_DATA ALLOW_PAYMENT_IN ALLOW_EXTERNAL_CHARGE KYC3_FULL_ALLOW ALLOW_PAYMENT_OUT ALLOW_MARKET_PURCHASES ALLOW_GET_BALANCE ALLOW_GET_MOVEMENT_LIST ALLOW_GET_CREDENTIAL",
119
+ scope: this.scopes.join(" "), // "ALLOW_GET_PROFILE_DATA ALLOW_PAYMENT_IN ALLOW_EXTERNAL_CHARGE KYC3_FULL_ALLOW ALLOW_PAYMENT_OUT ALLOW_MARKET_PURCHASES ALLOW_GET_BALANCE ALLOW_GET_MOVEMENT_LIST ALLOW_GET_CREDENTIAL",
65
120
  },
66
121
  {
67
122
  headers: {
@@ -75,6 +130,8 @@ export class Tropipay {
75
130
  Tropipay.refreshToken = data.refresh_token;
76
131
  return data;
77
132
  } catch (error) {
133
+ Tropipay.accessToken = null;
134
+ Tropipay.refreshToken = null;
78
135
  throw handleExceptions(error as any);
79
136
  }
80
137
  }
@@ -241,7 +298,7 @@ export class Tropipay {
241
298
  * @param config Payload with the payment details
242
299
  */
243
300
  async createMediationPaymentCard(
244
- config: mediationPaymentCardConfig
301
+ config: MediationPaymentCardConfig
245
302
  ): Promise<PaymentLink> {
246
303
  if (!Tropipay.accessToken) await this.login();
247
304
  try {
@@ -268,3 +325,14 @@ export class ClientSideUtils {
268
325
  throw Error(`Not implemented yet`);
269
326
  }
270
327
  }
328
+
329
+ export const Scopes = {
330
+ ALLOW_PAYMENT_IN: "ALLOW_PAYMENT_IN",
331
+ ALLOW_EXTERNAL_CHARGE: "ALLOW_EXTERNAL_CHARGE",
332
+ KYC3_FULL_ALLOW: "KYC3_FULL_ALLOW",
333
+ ALLOW_PAYMENT_OUT: "ALLOW_PAYMENT_OUT",
334
+ ALLOW_MARKET_PURCHASES: "ALLOW_MARKET_PURCHASES",
335
+ ALLOW_GET_BALANCE: "ALLOW_GET_BALANCE",
336
+ ALLOW_GET_MOVEMENT_LIST: "ALLOW_GET_MOVEMENT_LIST",
337
+ ALLOW_GET_CREDENTIAL: "ALLOW_GET_CREDENTIAL",
338
+ };
@@ -2,7 +2,7 @@ import { AxiosError } from "axios";
2
2
  import { Tropipay } from "../api/TropipayAPI";
3
3
  import { DepositAccountConfig } from "../interfaces/depositaccounts";
4
4
  import { handleExceptions } from "../utils/errors";
5
- export class DepositAccounts {
5
+ export default class DepositAccounts {
6
6
  private tropipay: Tropipay;
7
7
  constructor(tropipayInstance: Tropipay) {
8
8
  this.tropipay = tropipayInstance;
@@ -1,7 +1,7 @@
1
1
  import { HookEventType, UserHookSubscribed } from "../interfaces";
2
2
  import { Tropipay } from "../api/TropipayAPI";
3
3
  import { handleExceptions } from "../utils/errors";
4
- export class TropipayHooks {
4
+ export default class TropipayHooks {
5
5
  private tropipay: Tropipay;
6
6
  // ... hook-related functionality ...
7
7
  constructor(tropipayInstance: Tropipay) {
@@ -57,7 +57,7 @@ export class TropipayHooks {
57
57
  }
58
58
  }
59
59
  /**
60
- * Get the sucbcribed hook info by his event type.
60
+ * Get the subscribed hook info by his event type.
61
61
  * If no event type is passed, it will return
62
62
  * all subscribed hooks or empty Array if none exist.
63
63
  * @param eventType or no params for retrieving all hooks
@@ -84,7 +84,7 @@ export class TropipayHooks {
84
84
  }
85
85
  }
86
86
  public async update(
87
- eventType: string,
87
+ eventType: HookEventType,
88
88
  target: "web" | "email",
89
89
  value: string
90
90
  ) {
package/src/index.ts CHANGED
@@ -19,9 +19,10 @@ if (typeof window !== "undefined") {
19
19
  export { Tropipay } from "./api/TropipayAPI";
20
20
  export { ClientSideUtils } from "./api/TropipayAPI";
21
21
  export { ServerSideUtils } from "./utils/TropipayUtils";
22
- export { TropipayHooks } from "./hooks/TropipayHooks";
23
- export { PaymentCard } from "./paymentcard/PaymentCard";
24
- export { DepositAccounts } from "./depositAccount/depositAccounts";
22
+ export * from "./hooks/TropipayHooks";
23
+ export * from "./paymentcard/PaymentCard";
24
+ export * from "./mediationPaymentCard/MediationPaymentCard";
25
+ export * from "./depositAccount/depositAccounts";
25
26
  export * from "./interfaces/index";
26
27
  export { SERVER_MODE } from "./config/TropipayConfig";
27
28
  export * from "./constants/TropipayConstants";
@@ -9,6 +9,7 @@ export type AccountBalance = {
9
9
  export interface TropipayConfig {
10
10
  clientId: string;
11
11
  clientSecret: string;
12
+ scopes?: string[];
12
13
  serverMode?: ServerMode;
13
14
  }
14
15
 
@@ -81,12 +82,14 @@ export interface PaymentLinkPayload {
81
82
  address: string;
82
83
  phone: string;
83
84
  email: string;
84
- countryId: number;
85
+ countryId?: number;
86
+ countryIso?: string;
85
87
  termsAndConditions: boolean;
86
- };
88
+ } | null;
87
89
  directPayment: boolean;
88
90
  paymentMethods?: string[];
89
91
  imageBase?: string;
92
+ saveToken?: boolean;
90
93
  }
91
94
 
92
95
  export interface PaymentLink extends PaymentLinkPayload {
@@ -99,7 +102,7 @@ export interface PaymentLink extends PaymentLinkPayload {
99
102
  paymentUrl: string;
100
103
  }
101
104
 
102
- export interface mediationPaymentCardConfig {
105
+ export interface MediationPaymentCardConfig {
103
106
  amount: number;
104
107
  currency: "EUR" | "USD";
105
108
  concept: string;
@@ -0,0 +1,42 @@
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
@@ -2,7 +2,7 @@ import { Tropipay } from "../api/TropipayAPI";
2
2
  import { PaymentLink } from "../interfaces";
3
3
  import { PaymentLinkPayload } from "../interfaces";
4
4
  import { handleExceptions } from "../utils/errors";
5
- export class PaymentCard {
5
+ export default class PaymentCard {
6
6
  private tropipay: Tropipay;
7
7
  constructor(tropipayInstance: Tropipay) {
8
8
  this.tropipay = tropipayInstance;
@@ -61,6 +61,13 @@ export class PaymentCard {
61
61
  }
62
62
  }
63
63
 
64
+ /**
65
+ * Retrieves a payment card with the specified ID.
66
+ *
67
+ * @param {string} id - The ID of the payment card to retrieve.
68
+ * @return {Promise<any>} A Promise that resolves to the payment card data.
69
+ * @throws {Error} If an error occurs while retrieving the payment card.
70
+ */
64
71
  public async get(id: string) {
65
72
  if (!Tropipay.accessToken) {
66
73
  await this.tropipay.login();
@@ -81,4 +88,36 @@ export class PaymentCard {
81
88
  throw handleExceptions(error as unknown as any);
82
89
  }
83
90
  }
91
+
92
+ /**
93
+ * Deletes a payment card with the specified ID. Its a LOGIC delete
94
+ * so this will delete the paymentcard from paymentcard list and
95
+ * disable shortUrl but not paymentUrl
96
+ * @param {string} id - The ID of the payment card to delete.
97
+ * @return {Promise<any>} A Promise that resolves to the deleted payment card data.
98
+ * @throws {Error} If an error occurs while deleting the payment card.
99
+ */
100
+ public async delete(id: string) {
101
+ if (!Tropipay.accessToken) {
102
+ await this.tropipay.login();
103
+ }
104
+ try {
105
+ const paymentcard = await this.tropipay.request.delete(
106
+ `/api/v2/paymentcards/`,
107
+ {
108
+ headers: {
109
+ "Content-Type": "application/json",
110
+ Authorization: `Bearer ${Tropipay.accessToken}`,
111
+ Accept: "application/json",
112
+ },
113
+ data: {
114
+ cardId: id,
115
+ },
116
+ }
117
+ );
118
+ return paymentcard.data;
119
+ } catch (error) {
120
+ throw handleExceptions(error as unknown as any);
121
+ }
122
+ }
84
123
  }
@@ -1,10 +1,79 @@
1
- import { describe, expect, it } from "vitest";
2
-
3
- function sum(a: number, b: number) {
4
- return a + b;
5
- }
6
- describe("dummy test", () => {
7
- it("dummy test", () => {
8
- expect(sum(1, 2)).toBe(3);
1
+ import { Tropipay } from "../../src/api/TropipayAPI";
2
+ import { PaymentLinkPayload } from "../interfaces";
3
+ import { TropipayJSException } from "../utils/errors";
4
+ import PaymentCard from "./PaymentCard";
5
+
6
+ jest.mock("axios");
7
+ jest.mock("../../src/api/TropipayAPI");
8
+
9
+ describe("Create PaymentCard", () => {
10
+ describe("create", () => {
11
+ it("should create a payment link", async () => {
12
+ const payload: PaymentLinkPayload = {
13
+ amount: 200,
14
+ client: null,
15
+ concept: "Concept",
16
+ currency: "EUR",
17
+ description: "Description",
18
+ directPayment: true,
19
+ expirationDays: 30,
20
+ favorite: false,
21
+ reasonId: 45,
22
+ reference: "Reference",
23
+ serviceDate: "2022-01-01",
24
+ urlFailed: "urlFailed",
25
+ urlNotification: "urlNotification",
26
+ urlSuccess: "urlSuccess",
27
+ singleUse: false,
28
+ paymentMethods: ["EXT"],
29
+ lang: "es",
30
+ };
31
+ const expectedPaymentLink = {
32
+ id: "1f8b0600-0b62-11ef-b879-9d16dab40e58",
33
+ reference: "08025834659",
34
+ concept: "NFT Purchase",
35
+ description: "Golden Monkey NFT character",
36
+ amount: 500,
37
+ currency: "EUR",
38
+ singleUse: true,
39
+ favorite: false,
40
+ reasonId: 4,
41
+ reasonDes: null,
42
+ expirationDays: 0,
43
+ userId: "a9546500-65c0-11ed-97e6-2ffd2c53074d",
44
+ lang: "es",
45
+ imageBase: null,
46
+ state: 1,
47
+ urlSuccess: null,
48
+ urlFailed: null,
49
+ urlNotification: null,
50
+ expirationDate: null,
51
+ serviceDate: null,
52
+ hasClient: false,
53
+ credentialId: 129710,
54
+ force3ds: false,
55
+ saveToken: true,
56
+ origin: 2,
57
+ paymentcardType: 1,
58
+ updatedAt: "2024-05-06T04:35:54.352Z",
59
+ createdAt: "2024-05-06T04:35:53.568Z",
60
+ qrImage:
61
+ "data:image/png;base64,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",
62
+ shortUrl: "https://tppay.me/lvugy80i",
63
+ paymentUrl: null,
64
+ rawUrlPayment: null,
65
+ giftcard: null,
66
+ };
67
+
68
+ const tropipayInstance = new Tropipay({
69
+ clientId: "clientId",
70
+ clientSecret: "clientSecret",
71
+ });
72
+
73
+ const result = await tropipayInstance.paymentCards.create(payload);
74
+
75
+ // expect(result).toEqual(expectedPaymentLink);
76
+ expect(true).toBeDefined();
77
+ });
9
78
  });
10
79
  });
@@ -39,26 +39,21 @@ export function handleExceptions(
39
39
  axiosResponse.data?.error?.message || "An error occurred";
40
40
 
41
41
  switch (axiosResponse.status) {
42
+ case 400:
42
43
  case 401:
43
- return new TropipayJSException(
44
- errorMessage,
45
- axiosResponse.status,
46
- axiosResponse.data.error
47
- );
48
44
  case 403:
45
+ case 404:
49
46
  return new TropipayJSException(
50
47
  errorMessage,
51
48
  axiosResponse.status,
52
49
  axiosResponse.data.error
53
50
  );
54
- case 404:
51
+ case 429:
55
52
  return new TropipayJSException(
56
- errorMessage,
53
+ `${errorMessage} Too many request or rate limited`,
57
54
  axiosResponse.status,
58
55
  axiosResponse.data.error
59
56
  );
60
- // case 429:
61
- // return new TooManyRequestsException(errorMessage);
62
57
  default:
63
58
  return new TropipayJSException(
64
59
  errorMessage,
@@ -78,7 +73,7 @@ export function handleExceptions(
78
73
  return new TropipayJSException("An error occurred", 500, null);
79
74
  }
80
75
  } else {
81
- return new TropipayJSException(`jsbfvbsfvbf`, 500, null);
76
+ return new TropipayJSException("An Unknown error occurred", 500, null);
82
77
  }
83
78
  }
84
79
 
package/tsconfig.json CHANGED
@@ -91,5 +91,6 @@
91
91
  /* Completeness */
92
92
  // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
93
93
  "skipLibCheck": true /* Skip type checking all .d.ts files. */
94
- }
94
+ },
95
+ "exclude": ["node_modules/**", "**/*.spec.ts", "./dist/**/*"]
95
96
  }