@yosle/tropipayjs 0.1.21 → 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
+ }
@@ -5,11 +5,12 @@
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;
@@ -21,6 +22,7 @@ export declare class Tropipay {
21
22
  hooks: TropipayHooks;
22
23
  paymentCards: PaymentCard;
23
24
  depositAccounts: DepositAccounts;
25
+ mediationPaymentCard: MediationPaymentCard;
24
26
  /**
25
27
  * Initializes a new instance of the Tropipay class.
26
28
  *
@@ -82,9 +84,19 @@ export declare class Tropipay {
82
84
  * @see https://tpp.stoplight.io/docs/tropipay-api-doc/12a128ff971e4-creating-a-mediation-payment-card
83
85
  * @param config Payload with the payment details
84
86
  */
85
- createMediationPaymentCard(config: mediationPaymentCardConfig): Promise<PaymentLink>;
87
+ createMediationPaymentCard(config: MediationPaymentCardConfig): Promise<PaymentLink>;
86
88
  }
87
89
  export declare class ClientSideUtils {
88
90
  constructor(tropipayInstance: Tropipay);
89
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
+ };
90
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
  /**
@@ -32,7 +32,7 @@ export declare class TropipayHooks {
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
@@ -59,12 +59,14 @@ interface PaymentLinkPayload {
59
59
  address: string;
60
60
  phone: string;
61
61
  email: string;
62
- countryId: number;
62
+ countryId?: number;
63
+ countryIso?: string;
63
64
  termsAndConditions: boolean;
64
- };
65
+ } | null;
65
66
  directPayment: boolean;
66
67
  paymentMethods?: string[];
67
68
  imageBase?: string;
69
+ saveToken?: boolean;
68
70
  }
69
71
  interface PaymentLink extends PaymentLinkPayload {
70
72
  expirationDate: string;
@@ -75,7 +77,7 @@ interface PaymentLink extends PaymentLinkPayload {
75
77
  shortUrl: string;
76
78
  paymentUrl: string;
77
79
  }
78
- interface mediationPaymentCardConfig {
80
+ interface MediationPaymentCardConfig {
79
81
  amount: number;
80
82
  currency: "EUR" | "USD";
81
83
  concept: string;
@@ -196,7 +198,7 @@ declare class TropipayHooks {
196
198
  * @returns All subscribed hooks or empty Array if none exist.
197
199
  */
198
200
  list(eventType?: HookEventType): Promise<UserHookSubscribed[]>;
199
- update(eventType: string, target: "web" | "email", value: string): Promise<any>;
201
+ update(eventType: HookEventType, target: "web" | "email", value: string): Promise<any>;
200
202
  delete(eventType: HookEventType, target: string): Promise<any>;
201
203
  events(): Promise<any>;
202
204
  }
@@ -217,7 +219,38 @@ declare class PaymentCard {
217
219
  * @returns Array of paymentlinks
218
220
  */
219
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
+ */
220
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>;
221
254
  }
222
255
 
223
256
  interface DepositAccountConfig {
@@ -303,6 +336,7 @@ declare class Tropipay {
303
336
  hooks: TropipayHooks;
304
337
  paymentCards: PaymentCard;
305
338
  depositAccounts: DepositAccounts;
339
+ mediationPaymentCard: MediationPaymentCard;
306
340
  /**
307
341
  * Initializes a new instance of the Tropipay class.
308
342
  *
@@ -364,7 +398,7 @@ declare class Tropipay {
364
398
  * @see https://tpp.stoplight.io/docs/tropipay-api-doc/12a128ff971e4-creating-a-mediation-payment-card
365
399
  * @param config Payload with the payment details
366
400
  */
367
- createMediationPaymentCard(config: mediationPaymentCardConfig): Promise<PaymentLink>;
401
+ createMediationPaymentCard(config: MediationPaymentCardConfig): Promise<PaymentLink>;
368
402
  }
369
403
  declare class ClientSideUtils {
370
404
  constructor(tropipayInstance: Tropipay);
@@ -417,4 +451,4 @@ declare class ServerSideUtils {
417
451
 
418
452
  declare const SERVER_MODE: ServerMode$1;
419
453
 
420
- 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,10 +36,9 @@ 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
44
  case 429:
@@ -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 {
@@ -416,6 +485,7 @@ class Tropipay {
416
485
  hooks;
417
486
  paymentCards;
418
487
  depositAccounts;
488
+ mediationPaymentCard;
419
489
  /**
420
490
  * Initializes a new instance of the Tropipay class.
421
491
  *
@@ -457,6 +527,7 @@ class Tropipay {
457
527
  });
458
528
  this.hooks = new TropipayHooks(this);
459
529
  this.paymentCards = new PaymentCard(this);
530
+ this.mediationPaymentCard = new MediationPaymentCard(this);
460
531
  this.depositAccounts = new DepositAccounts(this);
461
532
  }
462
533
  async login() {
@@ -792,11 +863,8 @@ if (typeof window !== "undefined") {
792
863
  }
793
864
 
794
865
  exports.ClientSideUtils = ClientSideUtils;
795
- exports.DepositAccounts = DepositAccounts;
796
866
  exports.MAX_IMAGE_SIZE_MB = MAX_IMAGE_SIZE_MB;
797
- exports.PaymentCard = PaymentCard;
798
867
  exports.SERVER_MODE = SERVER_MODE;
799
868
  exports.ServerSideUtils = ServerSideUtils;
800
869
  exports.Tropipay = Tropipay;
801
- exports.TropipayHooks = TropipayHooks;
802
870
  //# sourceMappingURL=index.js.map
@@ -55,12 +55,14 @@ export interface PaymentLinkPayload {
55
55
  address: string;
56
56
  phone: string;
57
57
  email: string;
58
- countryId: number;
58
+ countryId?: number;
59
+ countryIso?: string;
59
60
  termsAndConditions: boolean;
60
- };
61
+ } | null;
61
62
  directPayment: boolean;
62
63
  paymentMethods?: string[];
63
64
  imageBase?: string;
65
+ saveToken?: boolean;
64
66
  }
65
67
  export interface PaymentLink extends PaymentLinkPayload {
66
68
  expirationDate: string;
@@ -71,7 +73,7 @@ export interface PaymentLink extends PaymentLinkPayload {
71
73
  shortUrl: string;
72
74
  paymentUrl: string;
73
75
  }
74
- export interface mediationPaymentCardConfig {
76
+ export interface MediationPaymentCardConfig {
75
77
  amount: number;
76
78
  currency: "EUR" | "USD";
77
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.21",
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,14 +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",
40
- "@types/node": "^20.12.7"
42
+ "ts-jest": "^29.1.2",
43
+ "typescript": "^5.4.5"
41
44
  },
42
45
  "funding": {
43
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,14 +12,15 @@ 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";
20
+ import TropipayHooks from "../hooks/TropipayHooks";
21
+ import PaymentCard from "../paymentcard/PaymentCard";
22
+ import MediationPaymentCard from "../mediationPaymentCard/MediationPaymentCard";
23
+ import DepositAccounts from "../depositAccount/depositAccounts";
23
24
  import { TropipayJSException, handleExceptions } from "../utils/errors";
24
25
  export class Tropipay {
25
26
  readonly clientId: string;
@@ -32,6 +33,7 @@ export class Tropipay {
32
33
  public hooks: TropipayHooks;
33
34
  public paymentCards: PaymentCard;
34
35
  public depositAccounts: DepositAccounts;
36
+ public mediationPaymentCard: MediationPaymentCard;
35
37
 
36
38
  /**
37
39
  * Initializes a new instance of the Tropipay class.
@@ -81,6 +83,8 @@ export class Tropipay {
81
83
  });
82
84
  this.hooks = new TropipayHooks(this);
83
85
  this.paymentCards = new PaymentCard(this);
86
+ this.mediationPaymentCard = new MediationPaymentCard(this);
87
+
84
88
  this.depositAccounts = new DepositAccounts(this);
85
89
  }
86
90
 
@@ -294,7 +298,7 @@ export class Tropipay {
294
298
  * @param config Payload with the payment details
295
299
  */
296
300
  async createMediationPaymentCard(
297
- config: mediationPaymentCardConfig
301
+ config: MediationPaymentCardConfig
298
302
  ): Promise<PaymentLink> {
299
303
  if (!Tropipay.accessToken) await this.login();
300
304
  try {
@@ -321,3 +325,14 @@ export class ClientSideUtils {
321
325
  throw Error(`Not implemented yet`);
322
326
  }
323
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) {
@@ -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";
@@ -82,12 +82,14 @@ export interface PaymentLinkPayload {
82
82
  address: string;
83
83
  phone: string;
84
84
  email: string;
85
- countryId: number;
85
+ countryId?: number;
86
+ countryIso?: string;
86
87
  termsAndConditions: boolean;
87
- };
88
+ } | null;
88
89
  directPayment: boolean;
89
90
  paymentMethods?: string[];
90
91
  imageBase?: string;
92
+ saveToken?: boolean;
91
93
  }
92
94
 
93
95
  export interface PaymentLink extends PaymentLinkPayload {
@@ -100,7 +102,7 @@ export interface PaymentLink extends PaymentLinkPayload {
100
102
  paymentUrl: string;
101
103
  }
102
104
 
103
- export interface mediationPaymentCardConfig {
105
+ export interface MediationPaymentCardConfig {
104
106
  amount: number;
105
107
  currency: "EUR" | "USD";
106
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,iVBORw0KGgoAAAANSUhEUgAAAKQAAACkCAYAAAAZtYVBAAAAAklEQVR4AewaftIAAAcPSURBVO3B0ald3QqA0S+yexKsxfKsRbCq3LxdnyZM1ton5scxfv3+g7WGENYaRFhrEGGtQYS1BhHWGkRYaxBhrUGEtQYR1hpEWGsQYa1BhLUGEdYaRFhrEGGtQT48ZOr8pKzgxNQ5yQqeMHVuZAVvMnVOsoLO1PlJWcETwlqDCGsNIqw1yIeXZQVvMnXeZOp0WcGJqfOEqdNlBZ2p02UFnalzkhXcyAreZOq8SVhrEGGtQYS1BvnwZabOjazgiazgCVOnyw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gwlqDCGsNIqw1iLDWIMJagwhrDSKsNYiw1iD/Ayc0u8My6tdVAAAAAElFTkSuQmCC",
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,18 +39,9 @@ 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:
49
- return new TropipayJSException(
50
- errorMessage,
51
- axiosResponse.status,
52
- axiosResponse.data.error
53
- );
54
45
  case 404:
55
46
  return new TropipayJSException(
56
47
  errorMessage,
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
  }