@yosle/tropipayjs 0.2.1 → 0.2.3

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
@@ -133,6 +133,33 @@ console.log(paylink.shortUrl);
133
133
 
134
134
  For more examples, please refer to the [Documentation](https://github.com/yosle/tropipayjs/blob/master/docs/)
135
135
 
136
+ ### Refunding a Transaction
137
+
138
+ The library provides two methods for handling refunds with 2FA confirmation:
139
+
140
+ #### Request a Security Code (Production only)
141
+
142
+ In **Production** mode, you must first request a 2FA code via SMS:
143
+
144
+ ```javascript
145
+ await tpp.requestSecurityCode();
146
+ // An SMS with the code will be sent to your phone
147
+ ```
148
+
149
+ #### Refund a Movement
150
+
151
+ Once you have the security code (or in Development mode), you can refund a transaction:
152
+
153
+ ```javascript
154
+ // Development mode — use the default test code
155
+ const result = await tpp.refundMovement("ORD-123456", 5000, "123456");
156
+
157
+ // Production mode — pass the code received via SMS
158
+ const result = await tpp.refundMovement("ORD-123456", 5000, "847291");
159
+ ```
160
+
161
+ **Note:** The refund endpoint requires the `ALLOW_REFUND` scope and 2FA to be enabled on your Tropipay account. In Development mode the default 2FA code is `123456` unless you have configured the Authenticator app.
162
+
136
163
  # Contributing
137
164
 
138
165
  If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
package/SECURITY.md ADDED
@@ -0,0 +1,43 @@
1
+ # Supply Chain Security Plan
2
+
3
+ ## 1. Lockfile Integrity
4
+ - Always commit `package-lock.json` — it pins exact sub-dependency versions
5
+ - Verify integrity: `npm audit signatures` after install (requires npm 9+)
6
+
7
+ ## 2. Automated Scanning
8
+ ```yaml
9
+ # CI steps
10
+ - run: npm audit --audit-level=high # fail on high/critical known CVEs
11
+ - run: npx socket-cli scan # detect protestware, typo-squatting, obfuscation
12
+ ```
13
+ - [Socket.dev](https://socket.dev) — free tier detects behavioral risks (not just CVEs)
14
+ - [Snyk](https://snyk.io) — broader CVE coverage, integrates with GitHub
15
+
16
+ ## 3. Dependency Updates
17
+ - Enable **Dependabot** or **Renovate** — auto-create PRs for security patches
18
+ - Review every new dependency before adding: check downloads, maintenance, publisher
19
+
20
+ ## 4. Overrides for Transitive Dependencies
21
+ ```json
22
+ {
23
+ "overrides": {
24
+ "axios": "1.18.1",
25
+ "semver": "^7.6.0"
26
+ }
27
+ }
28
+ ```
29
+ Use `overrides` to force-patch transitive deps when upstream is slow to release.
30
+
31
+ ## 5. Minimal Surface Area
32
+ - Fewer dependencies = fewer attack vectors
33
+ - Regularly audit with `npm ls --depth=0` and remove unused packages
34
+
35
+ ## 6. SBOM Generation
36
+ ```bash
37
+ npm sbom --sbom-format cyclonedx > sbom.json
38
+ ```
39
+ Generate a Software Bill of Materials for compliance and tracking.
40
+
41
+ ## 7. Package Provenance
42
+ - Prefer packages with [provenance attestations](https://docs.npmjs.com/generating-provenance-statements) (npm publish --provenance)
43
+ - Check publisher reputation and maintainer count before adding
@@ -5,19 +5,17 @@
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, RefundResponse } from "../interfaces";
9
9
  type ServerMode = "Development" | "Production";
10
10
  import TropipayHooks from "../hooks/TropipayHooks";
11
11
  import PaymentCard from "../paymentcard/PaymentCard";
12
12
  import MediationPaymentCard from "../mediationPaymentCard/MediationPaymentCard";
13
13
  import DepositAccounts from "../depositAccount/depositAccounts";
14
- import Accounts from "../accounts/accounts";
15
14
  export declare class Tropipay {
16
15
  readonly clientId: string;
17
16
  readonly clientSecret: string;
18
17
  readonly scopes: String[];
19
18
  request: Axios;
20
- loginRequest: Axios;
21
19
  static accessToken: string | null;
22
20
  static refreshToken: string | null;
23
21
  static expiresIn: number | null;
@@ -26,7 +24,6 @@ export declare class Tropipay {
26
24
  paymentCards: PaymentCard;
27
25
  depositAccounts: DepositAccounts;
28
26
  mediationPaymentCard: MediationPaymentCard;
29
- accounts: Accounts;
30
27
  /**
31
28
  * Initializes a new instance of the Tropipay class.
32
29
  *
@@ -85,10 +82,39 @@ export declare class Tropipay {
85
82
  * belonging or not to the TropiPay platform with the particularity
86
83
  * that the payment will be held in custody or retained until it is
87
84
  * released with the approval of the payer.
85
+ * @deprecated This method is no longer supported and may be removed in a future release.
88
86
  * @see https://tpp.stoplight.io/docs/tropipay-api-doc/12a128ff971e4-creating-a-mediation-payment-card
89
87
  * @param config Payload with the payment details
90
88
  */
91
89
  createMediationPaymentCard(config: MediationPaymentCardConfig): Promise<PaymentLink>;
90
+ /**
91
+ * Refund a completed transaction.
92
+ * Requires 2FA enabled and ALLOW_REFUND permission on the Tropipay account.
93
+ *
94
+ * In Development mode, `securityCode` defaults to `"123456"` when omitted.
95
+ * In Production mode, you must first call `requestSecurityCode()` to receive
96
+ * the 2FA code via SMS, then pass it as the `securityCode` parameter.
97
+ *
98
+ * @see https://doc.tropipay.com/docs/api-reference/movements#refund-a-transaction
99
+ * @param orderCode Code of the order/transaction to refund (e.g. "ORD-123456")
100
+ * @param amount Amount to refund in cents (e.g. 5000 = 50.00 USD/EUR)
101
+ * @param securityCode 2FA confirmation code. Use "123456" in Development or
102
+ * the code received via SMS in Production (obtained via requestSecurityCode()).
103
+ */
104
+ refundMovement(orderCode: string, amount: number, securityCode: string): Promise<RefundResponse>;
105
+ /**
106
+ * Request a 2FA security code to be sent via SMS for confirming sensitive
107
+ * operations like refunds.
108
+ *
109
+ * In Production mode, you must call this method first to trigger an SMS with
110
+ * the code, then use the received code when calling `refundMovement()`.
111
+ * In Development mode this is not required as the default code "123456"
112
+ * is used automatically.
113
+ *
114
+ * @see https://doc.tropipay.com/docs/api-reference/movements#refund-a-transaction
115
+ * @returns The API response confirming the code was sent
116
+ */
117
+ requestSecurityCode(type?: "sms" | "email"): Promise<any>;
92
118
  }
93
119
  export declare class ClientSideUtils {
94
120
  constructor(tropipayInstance: Tropipay);
@@ -102,5 +128,6 @@ export declare const Scopes: {
102
128
  ALLOW_GET_BALANCE: string;
103
129
  ALLOW_GET_MOVEMENT_LIST: string;
104
130
  ALLOW_GET_CREDENTIAL: string;
131
+ ALLOW_REFUND: string;
105
132
  };
106
133
  export {};
package/index.d.ts CHANGED
@@ -39,71 +39,36 @@ interface UserHookSubscribed extends UserHook {
39
39
  createdAt: string;
40
40
  updatedAt: string;
41
41
  }
42
- /**
43
- * Interface for creating payment links/cards
44
- * @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
45
- */
46
42
  interface PaymentLinkPayload {
47
- /** Account ID where the funds will be received if compatible */
48
- accountId?: number;
49
- /** Reference code for the payment, preferred to be unique */
50
43
  reference: string;
51
- /** Short description of the payment */
52
44
  concept: string;
53
- /** Whether to mark this payment link as favorite */
54
45
  favorite: boolean;
55
- /** Amount to charge in the specified currency */
56
46
  amount: number;
57
- /** Currency code (EUR, USD, etc.) */
58
47
  currency: string;
59
- /** Detailed description of the payment */
60
48
  description: string;
61
- /** If true, the payment link can only be used once */
62
49
  singleUse: boolean;
63
- /** Reason ID for the payment */
64
50
  reasonId: number;
65
- /** Number of days until the payment link expires */
66
51
  expirationDays: number;
67
- /** Language code for the payment page (en, es, etc.) */
68
52
  lang: string;
69
- /** URL to redirect after successful payment */
70
53
  urlSuccess: string;
71
- /** URL to redirect after failed payment */
72
54
  urlFailed: string;
73
- /** Webhook URL for payment notifications */
74
55
  urlNotification: string;
75
- /** Date when the service will be provided (ISO format) */
76
56
  serviceDate: string;
77
- /** Client information for the payment */
78
57
  client?: {
79
- /** Client's first name */
80
58
  name?: string;
81
- /** Client's last name */
82
59
  lastName?: string;
83
- /** Client's address */
84
60
  address?: string;
85
- /** Client's phone number */
86
61
  phone?: string;
87
- /** Client's email address */
88
62
  email?: string;
89
- /** Client's country ID */
90
63
  countryId?: number;
91
- /** Client's country ISO code */
92
64
  countryIso?: string;
93
- /** Client's city */
94
65
  city: string;
95
- /** Client's postal code */
96
66
  postCode: string;
97
- /** Whether client accepted terms and conditions */
98
67
  termsAndConditions: boolean;
99
68
  } | null;
100
- /** @deprecated If true, redirects directly to payment page */
101
69
  directPayment: boolean;
102
- /** List of allowed payment methods */
103
70
  paymentMethods?: string[];
104
- /** Base64 encoded image for the payment page */
105
71
  imageBase?: string;
106
- /** Whether to save the payment token for future use */
107
72
  saveToken?: boolean;
108
73
  }
109
74
  interface PaymentLink extends PaymentLinkPayload {
@@ -203,6 +168,16 @@ type AccountDeposits = {
203
168
  count: number;
204
169
  rows: Deposit[];
205
170
  };
171
+ type RefundResponse = {
172
+ id: number;
173
+ orderCode: string;
174
+ amount: number;
175
+ currency: string;
176
+ state: string;
177
+ type: string;
178
+ createdAt: string;
179
+ completedAt: string;
180
+ };
206
181
 
207
182
  declare class TropipayHooks {
208
183
  private tropipay;
@@ -354,58 +329,6 @@ declare class DepositAccounts {
354
329
  delete(id: number): Promise<any>;
355
330
  }
356
331
 
357
- interface PaymentMethod {
358
- slug: string;
359
- name: string;
360
- enabled: boolean;
361
- allowedCurrencies: string[];
362
- }
363
- interface ServiceLimit {
364
- value: number | null;
365
- currency: string;
366
- }
367
- interface ServiceLimits {
368
- min: ServiceLimit;
369
- max: ServiceLimit;
370
- }
371
- interface Service {
372
- slug: string;
373
- enabled: boolean;
374
- allowed_currencies: string[];
375
- limits: ServiceLimits;
376
- }
377
- interface TropiCard {
378
- }
379
- interface Account {
380
- id: number;
381
- accountNumber: string;
382
- userId: string;
383
- alias: string;
384
- balance: number;
385
- pendingIn: number;
386
- pendingOut: number;
387
- state: number;
388
- paymentEntityId: number;
389
- currency: string;
390
- type: number;
391
- createdAt: string;
392
- updatedAt: string;
393
- isDefault: boolean;
394
- groupId: number | null;
395
- TropiCards: TropiCard[];
396
- services: Service[];
397
- paymentMethods: PaymentMethod[];
398
- }
399
- declare class Accounts {
400
- private tropipay;
401
- constructor(tropipayInstance: Tropipay);
402
- /**
403
- * List all accounts of the authenticated user
404
- * @returns Array of Account objects
405
- */
406
- list(): Promise<Account[]>;
407
- }
408
-
409
332
  /**
410
333
  * Tropipayjs is a Typescript/Javascript library for the Tropipay API.
411
334
  *
@@ -420,7 +343,6 @@ declare class Tropipay {
420
343
  readonly clientSecret: string;
421
344
  readonly scopes: String[];
422
345
  request: Axios;
423
- loginRequest: Axios;
424
346
  static accessToken: string | null;
425
347
  static refreshToken: string | null;
426
348
  static expiresIn: number | null;
@@ -429,7 +351,6 @@ declare class Tropipay {
429
351
  paymentCards: PaymentCard;
430
352
  depositAccounts: DepositAccounts;
431
353
  mediationPaymentCard: MediationPaymentCard;
432
- accounts: Accounts;
433
354
  /**
434
355
  * Initializes a new instance of the Tropipay class.
435
356
  *
@@ -488,10 +409,39 @@ declare class Tropipay {
488
409
  * belonging or not to the TropiPay platform with the particularity
489
410
  * that the payment will be held in custody or retained until it is
490
411
  * released with the approval of the payer.
412
+ * @deprecated This method is no longer supported and may be removed in a future release.
491
413
  * @see https://tpp.stoplight.io/docs/tropipay-api-doc/12a128ff971e4-creating-a-mediation-payment-card
492
414
  * @param config Payload with the payment details
493
415
  */
494
416
  createMediationPaymentCard(config: MediationPaymentCardConfig): Promise<PaymentLink>;
417
+ /**
418
+ * Refund a completed transaction.
419
+ * Requires 2FA enabled and ALLOW_REFUND permission on the Tropipay account.
420
+ *
421
+ * In Development mode, `securityCode` defaults to `"123456"` when omitted.
422
+ * In Production mode, you must first call `requestSecurityCode()` to receive
423
+ * the 2FA code via SMS, then pass it as the `securityCode` parameter.
424
+ *
425
+ * @see https://doc.tropipay.com/docs/api-reference/movements#refund-a-transaction
426
+ * @param orderCode Code of the order/transaction to refund (e.g. "ORD-123456")
427
+ * @param amount Amount to refund in cents (e.g. 5000 = 50.00 USD/EUR)
428
+ * @param securityCode 2FA confirmation code. Use "123456" in Development or
429
+ * the code received via SMS in Production (obtained via requestSecurityCode()).
430
+ */
431
+ refundMovement(orderCode: string, amount: number, securityCode: string): Promise<RefundResponse>;
432
+ /**
433
+ * Request a 2FA security code to be sent via SMS for confirming sensitive
434
+ * operations like refunds.
435
+ *
436
+ * In Production mode, you must call this method first to trigger an SMS with
437
+ * the code, then use the received code when calling `refundMovement()`.
438
+ * In Development mode this is not required as the default code "123456"
439
+ * is used automatically.
440
+ *
441
+ * @see https://doc.tropipay.com/docs/api-reference/movements#refund-a-transaction
442
+ * @returns The API response confirming the code was sent
443
+ */
444
+ requestSecurityCode(type?: "sms" | "email"): Promise<any>;
495
445
  }
496
446
  declare class ClientSideUtils {
497
447
  constructor(tropipayInstance: Tropipay);
@@ -501,9 +451,7 @@ declare class ServerSideUtils {
501
451
  private tropipay;
502
452
  constructor(tropipayInstance: Tropipay);
503
453
  /**
504
- * DEPRECATED Verify Topipay's signature on API V2 webhooks.
505
- * @deprecated This method is deprecated and will be removed in future versions.
506
- * Use the `verifySignatureV3` method from the `ServerSideUtils` class instead.
454
+ * Verify Topipay's signature on webhooks.
507
455
  * @param credentials Credential object or Tropipay instance
508
456
  * @param {String} originalCurrencyAmount
509
457
  * @param bankOrderCode
@@ -542,19 +490,9 @@ declare class ServerSideUtils {
542
490
  * @return {Promise<string>} the valid base64 image
543
491
  */
544
492
  static isValidImage(base64Image: string): boolean;
545
- /**
546
- * Verify Topipay's signature on API V3 webhooks.
547
- * @param {string} originalCurrencyAmount
548
- * @param {string} bankOrderCode
549
- * @param {string} signature signaturev3 field to be verified
550
- * @returns {boolean}
551
- */
552
- static verifySignatureV3(credentials: {
553
- clientId: string;
554
- clientSecret: string;
555
- } | Tropipay, originalCurrencyAmount: string, bankOrderCode: string, signature: string): boolean;
556
493
  }
557
494
 
558
495
  declare const SERVER_MODE: ServerMode$1;
559
496
 
560
- 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 };
497
+ export { ClientSideUtils, MAX_IMAGE_SIZE_MB, SERVER_MODE, ServerSideUtils, Tropipay };
498
+ export type { AccountBalance, AccountDeposits, Country, Deposit, HookEventType, HookTargetType, LoginError, LoginResponse, MediationPaymentCardConfig, PaymentLink, PaymentLinkPayload, RefundResponse, ServerMode$1 as ServerMode, TropipayConfig, TropipayCredentials, UserHook, UserHookSubscribed };