@yosle/tropipayjs 0.1.28 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/accounts/accounts.d.ts +52 -0
- package/api/TropipayAPI.d.ts +2 -0
- package/index.d.ts +102 -1
- package/index.js +68 -15
- package/interfaces/index.d.ts +35 -0
- package/interfaces/paymentlink/index.d.ts +1 -3
- package/package.json +2 -2
- package/src/accounts/accounts.ts +86 -0
- package/src/api/TropipayAPI.ts +23 -29
- package/src/depositAccount/depositAccounts.ts +5 -5
- package/src/interfaces/index.ts +264 -201
- package/src/interfaces/paymentlink/index.d.ts +33 -32
- package/src/interfaces/paymentlink/index.ts +1 -3
- package/src/paymentcard/PaymentCard.ts +4 -4
- package/src/utils/TropipayUtils.ts +40 -1
- package/utils/TropipayUtils.d.ts +14 -1
- package/paymentcard/paymentcard.spec.d.ts +0 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Tropipay } from "../api/TropipayAPI";
|
|
2
|
+
export interface PaymentMethod {
|
|
3
|
+
slug: string;
|
|
4
|
+
name: string;
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
allowedCurrencies: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface ServiceLimit {
|
|
9
|
+
value: number | null;
|
|
10
|
+
currency: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ServiceLimits {
|
|
13
|
+
min: ServiceLimit;
|
|
14
|
+
max: ServiceLimit;
|
|
15
|
+
}
|
|
16
|
+
export interface Service {
|
|
17
|
+
slug: string;
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
allowed_currencies: string[];
|
|
20
|
+
limits: ServiceLimits;
|
|
21
|
+
}
|
|
22
|
+
export interface TropiCard {
|
|
23
|
+
}
|
|
24
|
+
export interface Account {
|
|
25
|
+
id: number;
|
|
26
|
+
accountNumber: string;
|
|
27
|
+
userId: string;
|
|
28
|
+
alias: string;
|
|
29
|
+
balance: number;
|
|
30
|
+
pendingIn: number;
|
|
31
|
+
pendingOut: number;
|
|
32
|
+
state: number;
|
|
33
|
+
paymentEntityId: number;
|
|
34
|
+
currency: string;
|
|
35
|
+
type: number;
|
|
36
|
+
createdAt: string;
|
|
37
|
+
updatedAt: string;
|
|
38
|
+
isDefault: boolean;
|
|
39
|
+
groupId: number | null;
|
|
40
|
+
TropiCards: TropiCard[];
|
|
41
|
+
services: Service[];
|
|
42
|
+
paymentMethods: PaymentMethod[];
|
|
43
|
+
}
|
|
44
|
+
export default class Accounts {
|
|
45
|
+
private tropipay;
|
|
46
|
+
constructor(tropipayInstance: Tropipay);
|
|
47
|
+
/**
|
|
48
|
+
* List all accounts of the authenticated user
|
|
49
|
+
* @returns Array of Account objects
|
|
50
|
+
*/
|
|
51
|
+
list(): Promise<Account[]>;
|
|
52
|
+
}
|
package/api/TropipayAPI.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ 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";
|
|
14
15
|
export declare class Tropipay {
|
|
15
16
|
readonly clientId: string;
|
|
16
17
|
readonly clientSecret: string;
|
|
@@ -25,6 +26,7 @@ export declare class Tropipay {
|
|
|
25
26
|
paymentCards: PaymentCard;
|
|
26
27
|
depositAccounts: DepositAccounts;
|
|
27
28
|
mediationPaymentCard: MediationPaymentCard;
|
|
29
|
+
accounts: Accounts;
|
|
28
30
|
/**
|
|
29
31
|
* Initializes a new instance of the Tropipay class.
|
|
30
32
|
*
|
package/index.d.ts
CHANGED
|
@@ -39,36 +39,71 @@ 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
|
+
*/
|
|
42
46
|
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 */
|
|
43
50
|
reference: string;
|
|
51
|
+
/** Short description of the payment */
|
|
44
52
|
concept: string;
|
|
53
|
+
/** Whether to mark this payment link as favorite */
|
|
45
54
|
favorite: boolean;
|
|
55
|
+
/** Amount to charge in the specified currency */
|
|
46
56
|
amount: number;
|
|
57
|
+
/** Currency code (EUR, USD, etc.) */
|
|
47
58
|
currency: string;
|
|
59
|
+
/** Detailed description of the payment */
|
|
48
60
|
description: string;
|
|
61
|
+
/** If true, the payment link can only be used once */
|
|
49
62
|
singleUse: boolean;
|
|
63
|
+
/** Reason ID for the payment */
|
|
50
64
|
reasonId: number;
|
|
65
|
+
/** Number of days until the payment link expires */
|
|
51
66
|
expirationDays: number;
|
|
67
|
+
/** Language code for the payment page (en, es, etc.) */
|
|
52
68
|
lang: string;
|
|
69
|
+
/** URL to redirect after successful payment */
|
|
53
70
|
urlSuccess: string;
|
|
71
|
+
/** URL to redirect after failed payment */
|
|
54
72
|
urlFailed: string;
|
|
73
|
+
/** Webhook URL for payment notifications */
|
|
55
74
|
urlNotification: string;
|
|
75
|
+
/** Date when the service will be provided (ISO format) */
|
|
56
76
|
serviceDate: string;
|
|
77
|
+
/** Client information for the payment */
|
|
57
78
|
client?: {
|
|
79
|
+
/** Client's first name */
|
|
58
80
|
name?: string;
|
|
81
|
+
/** Client's last name */
|
|
59
82
|
lastName?: string;
|
|
83
|
+
/** Client's address */
|
|
60
84
|
address?: string;
|
|
85
|
+
/** Client's phone number */
|
|
61
86
|
phone?: string;
|
|
87
|
+
/** Client's email address */
|
|
62
88
|
email?: string;
|
|
89
|
+
/** Client's country ID */
|
|
63
90
|
countryId?: number;
|
|
91
|
+
/** Client's country ISO code */
|
|
64
92
|
countryIso?: string;
|
|
93
|
+
/** Client's city */
|
|
65
94
|
city: string;
|
|
95
|
+
/** Client's postal code */
|
|
66
96
|
postCode: string;
|
|
97
|
+
/** Whether client accepted terms and conditions */
|
|
67
98
|
termsAndConditions: boolean;
|
|
68
99
|
} | null;
|
|
100
|
+
/** @deprecated If true, redirects directly to payment page */
|
|
69
101
|
directPayment: boolean;
|
|
102
|
+
/** List of allowed payment methods */
|
|
70
103
|
paymentMethods?: string[];
|
|
104
|
+
/** Base64 encoded image for the payment page */
|
|
71
105
|
imageBase?: string;
|
|
106
|
+
/** Whether to save the payment token for future use */
|
|
72
107
|
saveToken?: boolean;
|
|
73
108
|
}
|
|
74
109
|
interface PaymentLink extends PaymentLinkPayload {
|
|
@@ -319,6 +354,58 @@ declare class DepositAccounts {
|
|
|
319
354
|
delete(id: number): Promise<any>;
|
|
320
355
|
}
|
|
321
356
|
|
|
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
|
+
|
|
322
409
|
/**
|
|
323
410
|
* Tropipayjs is a Typescript/Javascript library for the Tropipay API.
|
|
324
411
|
*
|
|
@@ -342,6 +429,7 @@ declare class Tropipay {
|
|
|
342
429
|
paymentCards: PaymentCard;
|
|
343
430
|
depositAccounts: DepositAccounts;
|
|
344
431
|
mediationPaymentCard: MediationPaymentCard;
|
|
432
|
+
accounts: Accounts;
|
|
345
433
|
/**
|
|
346
434
|
* Initializes a new instance of the Tropipay class.
|
|
347
435
|
*
|
|
@@ -413,7 +501,9 @@ declare class ServerSideUtils {
|
|
|
413
501
|
private tropipay;
|
|
414
502
|
constructor(tropipayInstance: Tropipay);
|
|
415
503
|
/**
|
|
416
|
-
* Verify Topipay's signature on webhooks.
|
|
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.
|
|
417
507
|
* @param credentials Credential object or Tropipay instance
|
|
418
508
|
* @param {String} originalCurrencyAmount
|
|
419
509
|
* @param bankOrderCode
|
|
@@ -452,6 +542,17 @@ declare class ServerSideUtils {
|
|
|
452
542
|
* @return {Promise<string>} the valid base64 image
|
|
453
543
|
*/
|
|
454
544
|
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;
|
|
455
556
|
}
|
|
456
557
|
|
|
457
558
|
declare const SERVER_MODE: ServerMode$1;
|
package/index.js
CHANGED
|
@@ -220,7 +220,7 @@ class PaymentCard {
|
|
|
220
220
|
await this.tropipay.login();
|
|
221
221
|
}
|
|
222
222
|
try {
|
|
223
|
-
const paylink = await this.tropipay.request.post("/api/
|
|
223
|
+
const paylink = await this.tropipay.request.post("/api/v3/paymentcards", payload, {
|
|
224
224
|
headers: {
|
|
225
225
|
"Content-Type": "application/json",
|
|
226
226
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
@@ -243,7 +243,7 @@ class PaymentCard {
|
|
|
243
243
|
await this.tropipay.login();
|
|
244
244
|
}
|
|
245
245
|
try {
|
|
246
|
-
const paymentcards = await this.tropipay.request.get(`/api/
|
|
246
|
+
const paymentcards = await this.tropipay.request.get(`/api/v3/paymentcards`, {
|
|
247
247
|
headers: {
|
|
248
248
|
"Content-Type": "application/json",
|
|
249
249
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
@@ -268,7 +268,7 @@ class PaymentCard {
|
|
|
268
268
|
await this.tropipay.login();
|
|
269
269
|
}
|
|
270
270
|
try {
|
|
271
|
-
const paymentcard = await this.tropipay.request.get(`/api/
|
|
271
|
+
const paymentcard = await this.tropipay.request.get(`/api/v3/paymentcards/${id}`, {
|
|
272
272
|
headers: {
|
|
273
273
|
"Content-Type": "application/json",
|
|
274
274
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
@@ -294,7 +294,7 @@ class PaymentCard {
|
|
|
294
294
|
await this.tropipay.login();
|
|
295
295
|
}
|
|
296
296
|
try {
|
|
297
|
-
const paymentcard = await this.tropipay.request.delete(`/api/
|
|
297
|
+
const paymentcard = await this.tropipay.request.delete(`/api/v3/paymentcards/`, {
|
|
298
298
|
headers: {
|
|
299
299
|
"Content-Type": "application/json",
|
|
300
300
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
@@ -360,7 +360,7 @@ class DepositAccounts {
|
|
|
360
360
|
await this.tropipay.login();
|
|
361
361
|
}
|
|
362
362
|
try {
|
|
363
|
-
const deposit = await this.tropipay.request.get(`/api/
|
|
363
|
+
const deposit = await this.tropipay.request.get(`/api/v3/deposit_accounts`, {
|
|
364
364
|
headers: {
|
|
365
365
|
"Content-Type": "application/json",
|
|
366
366
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
@@ -383,7 +383,7 @@ class DepositAccounts {
|
|
|
383
383
|
await this.tropipay.login();
|
|
384
384
|
}
|
|
385
385
|
try {
|
|
386
|
-
const deposit = await this.tropipay.request.post("/api/
|
|
386
|
+
const deposit = await this.tropipay.request.post("/api/v3/deposit_accounts", depositAccountObj, {
|
|
387
387
|
headers: {
|
|
388
388
|
"Content-Type": "application/json",
|
|
389
389
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
@@ -407,7 +407,7 @@ class DepositAccounts {
|
|
|
407
407
|
await this.tropipay.login();
|
|
408
408
|
}
|
|
409
409
|
try {
|
|
410
|
-
const deposit = await this.tropipay.request.get(`/api/
|
|
410
|
+
const deposit = await this.tropipay.request.get(`/api/v3/deposit_accounts/${id}`, {
|
|
411
411
|
headers: {
|
|
412
412
|
"Content-Type": "application/json",
|
|
413
413
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
@@ -430,7 +430,7 @@ class DepositAccounts {
|
|
|
430
430
|
await this.tropipay.login();
|
|
431
431
|
}
|
|
432
432
|
try {
|
|
433
|
-
const deposit = await this.tropipay.request.put(`/api/
|
|
433
|
+
const deposit = await this.tropipay.request.put(`/api/v3/deposit_accounts/`, {
|
|
434
434
|
headers: {
|
|
435
435
|
"Content-Type": "application/json",
|
|
436
436
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
@@ -453,7 +453,7 @@ class DepositAccounts {
|
|
|
453
453
|
await this.tropipay.login();
|
|
454
454
|
}
|
|
455
455
|
try {
|
|
456
|
-
const deposit = await this.tropipay.request.delete(`/api/
|
|
456
|
+
const deposit = await this.tropipay.request.delete(`/api/v3/deposit_accounts/${id}`, {
|
|
457
457
|
headers: {
|
|
458
458
|
"Content-Type": "application/json",
|
|
459
459
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
@@ -468,6 +468,35 @@ class DepositAccounts {
|
|
|
468
468
|
}
|
|
469
469
|
}
|
|
470
470
|
|
|
471
|
+
class Accounts {
|
|
472
|
+
tropipay;
|
|
473
|
+
constructor(tropipayInstance) {
|
|
474
|
+
this.tropipay = tropipayInstance;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* List all accounts of the authenticated user
|
|
478
|
+
* @returns Array of Account objects
|
|
479
|
+
*/
|
|
480
|
+
async list() {
|
|
481
|
+
if (!Tropipay.accessToken) {
|
|
482
|
+
await this.tropipay.login();
|
|
483
|
+
}
|
|
484
|
+
try {
|
|
485
|
+
const accounts = await this.tropipay.request.get(`/api/v3/accounts/`, {
|
|
486
|
+
headers: {
|
|
487
|
+
"Content-Type": "application/json",
|
|
488
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
489
|
+
Accept: "application/json",
|
|
490
|
+
},
|
|
491
|
+
});
|
|
492
|
+
return accounts.data;
|
|
493
|
+
}
|
|
494
|
+
catch (error) {
|
|
495
|
+
throw handleExceptions(error);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
471
500
|
/**
|
|
472
501
|
* Tropipayjs is a Typescript/Javascript library for the Tropipay API.
|
|
473
502
|
*
|
|
@@ -488,6 +517,7 @@ class Tropipay {
|
|
|
488
517
|
paymentCards;
|
|
489
518
|
depositAccounts;
|
|
490
519
|
mediationPaymentCard;
|
|
520
|
+
accounts;
|
|
491
521
|
/**
|
|
492
522
|
* Initializes a new instance of the Tropipay class.
|
|
493
523
|
*
|
|
@@ -519,7 +549,7 @@ class Tropipay {
|
|
|
519
549
|
this.serverMode = config.serverMode || "Development";
|
|
520
550
|
const tpp_env = this.serverMode === "Production"
|
|
521
551
|
? "https://www.tropipay.com"
|
|
522
|
-
: "https://tropipay
|
|
552
|
+
: "https://sandbox.tropipay.me";
|
|
523
553
|
this.request = axios__default["default"].create({
|
|
524
554
|
baseURL: config.customTropipayUrl || tpp_env,
|
|
525
555
|
headers: {
|
|
@@ -533,12 +563,11 @@ class Tropipay {
|
|
|
533
563
|
baseURL: config.customTropipayUrl || tpp_env,
|
|
534
564
|
headers: {
|
|
535
565
|
"Content-Type": "application/json",
|
|
536
|
-
Accept: "application/json"
|
|
566
|
+
Accept: "application/json",
|
|
537
567
|
},
|
|
538
568
|
});
|
|
539
569
|
// Add request interceptor for Token expired
|
|
540
570
|
this.request.interceptors.request.use(async (config) => {
|
|
541
|
-
console.log("Executing interceptor!!");
|
|
542
571
|
const currentTimestamp = Math.floor(Date.now() / 1000);
|
|
543
572
|
if (Tropipay.expiresIn && Tropipay.expiresIn < currentTimestamp) {
|
|
544
573
|
console.debug("Token expired, attempting to log in");
|
|
@@ -559,11 +588,12 @@ class Tropipay {
|
|
|
559
588
|
this.paymentCards = new PaymentCard(this);
|
|
560
589
|
this.mediationPaymentCard = new MediationPaymentCard(this);
|
|
561
590
|
this.depositAccounts = new DepositAccounts(this);
|
|
591
|
+
this.accounts = new Accounts(this);
|
|
562
592
|
}
|
|
563
593
|
async login() {
|
|
564
594
|
try {
|
|
565
595
|
// normal credetials login
|
|
566
|
-
const { data } = await this.loginRequest.post("/api/
|
|
596
|
+
const { data } = await this.loginRequest.post("/api/v3/access/token", {
|
|
567
597
|
client_id: this.clientId,
|
|
568
598
|
client_secret: this.clientSecret,
|
|
569
599
|
grant_type: "client_credentials",
|
|
@@ -579,7 +609,6 @@ class Tropipay {
|
|
|
579
609
|
return data;
|
|
580
610
|
}
|
|
581
611
|
catch (error) {
|
|
582
|
-
console.log("RAW login error ", error);
|
|
583
612
|
Tropipay.accessToken = null;
|
|
584
613
|
Tropipay.refreshToken = null;
|
|
585
614
|
Tropipay.expiresIn = null;
|
|
@@ -770,7 +799,9 @@ class ServerSideUtils {
|
|
|
770
799
|
this.tropipay = tropipayInstance;
|
|
771
800
|
}
|
|
772
801
|
/**
|
|
773
|
-
* Verify Topipay's signature on webhooks.
|
|
802
|
+
* DEPRECATED Verify Topipay's signature on API V2 webhooks.
|
|
803
|
+
* @deprecated This method is deprecated and will be removed in future versions.
|
|
804
|
+
* Use the `verifySignatureV3` method from the `ServerSideUtils` class instead.
|
|
774
805
|
* @param credentials Credential object or Tropipay instance
|
|
775
806
|
* @param {String} originalCurrencyAmount
|
|
776
807
|
* @param bankOrderCode
|
|
@@ -860,6 +891,28 @@ class ServerSideUtils {
|
|
|
860
891
|
throw new Error(`Error checking base64 image`);
|
|
861
892
|
}
|
|
862
893
|
}
|
|
894
|
+
/**
|
|
895
|
+
* Verify Topipay's signature on API V3 webhooks.
|
|
896
|
+
* @param {string} originalCurrencyAmount
|
|
897
|
+
* @param {string} bankOrderCode
|
|
898
|
+
* @param {string} signature signaturev3 field to be verified
|
|
899
|
+
* @returns {boolean}
|
|
900
|
+
*/
|
|
901
|
+
static verifySignatureV3(credentials, originalCurrencyAmount, bankOrderCode, signature) {
|
|
902
|
+
const sha1Secret = crypto__namespace
|
|
903
|
+
.createHash("sha1")
|
|
904
|
+
.update(credentials.clientSecret)
|
|
905
|
+
.digest("hex");
|
|
906
|
+
const dataToHash = bankOrderCode +
|
|
907
|
+
credentials.clientId +
|
|
908
|
+
sha1Secret +
|
|
909
|
+
originalCurrencyAmount;
|
|
910
|
+
const localSignature = crypto__namespace
|
|
911
|
+
.createHash("sha256")
|
|
912
|
+
.update(dataToHash)
|
|
913
|
+
.digest("hex");
|
|
914
|
+
return localSignature === signature;
|
|
915
|
+
}
|
|
863
916
|
}
|
|
864
917
|
|
|
865
918
|
const SERVER_MODE = "Development"; // Move the constant here
|
package/interfaces/index.d.ts
CHANGED
|
@@ -35,36 +35,71 @@ export interface UserHookSubscribed extends UserHook {
|
|
|
35
35
|
createdAt: string;
|
|
36
36
|
updatedAt: string;
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Interface for creating payment links/cards
|
|
40
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
41
|
+
*/
|
|
38
42
|
export interface PaymentLinkPayload {
|
|
43
|
+
/** Account ID where the funds will be received if compatible */
|
|
44
|
+
accountId?: number;
|
|
45
|
+
/** Reference code for the payment, preferred to be unique */
|
|
39
46
|
reference: string;
|
|
47
|
+
/** Short description of the payment */
|
|
40
48
|
concept: string;
|
|
49
|
+
/** Whether to mark this payment link as favorite */
|
|
41
50
|
favorite: boolean;
|
|
51
|
+
/** Amount to charge in the specified currency */
|
|
42
52
|
amount: number;
|
|
53
|
+
/** Currency code (EUR, USD, etc.) */
|
|
43
54
|
currency: string;
|
|
55
|
+
/** Detailed description of the payment */
|
|
44
56
|
description: string;
|
|
57
|
+
/** If true, the payment link can only be used once */
|
|
45
58
|
singleUse: boolean;
|
|
59
|
+
/** Reason ID for the payment */
|
|
46
60
|
reasonId: number;
|
|
61
|
+
/** Number of days until the payment link expires */
|
|
47
62
|
expirationDays: number;
|
|
63
|
+
/** Language code for the payment page (en, es, etc.) */
|
|
48
64
|
lang: string;
|
|
65
|
+
/** URL to redirect after successful payment */
|
|
49
66
|
urlSuccess: string;
|
|
67
|
+
/** URL to redirect after failed payment */
|
|
50
68
|
urlFailed: string;
|
|
69
|
+
/** Webhook URL for payment notifications */
|
|
51
70
|
urlNotification: string;
|
|
71
|
+
/** Date when the service will be provided (ISO format) */
|
|
52
72
|
serviceDate: string;
|
|
73
|
+
/** Client information for the payment */
|
|
53
74
|
client?: {
|
|
75
|
+
/** Client's first name */
|
|
54
76
|
name?: string;
|
|
77
|
+
/** Client's last name */
|
|
55
78
|
lastName?: string;
|
|
79
|
+
/** Client's address */
|
|
56
80
|
address?: string;
|
|
81
|
+
/** Client's phone number */
|
|
57
82
|
phone?: string;
|
|
83
|
+
/** Client's email address */
|
|
58
84
|
email?: string;
|
|
85
|
+
/** Client's country ID */
|
|
59
86
|
countryId?: number;
|
|
87
|
+
/** Client's country ISO code */
|
|
60
88
|
countryIso?: string;
|
|
89
|
+
/** Client's city */
|
|
61
90
|
city: string;
|
|
91
|
+
/** Client's postal code */
|
|
62
92
|
postCode: string;
|
|
93
|
+
/** Whether client accepted terms and conditions */
|
|
63
94
|
termsAndConditions: boolean;
|
|
64
95
|
} | null;
|
|
96
|
+
/** @deprecated If true, redirects directly to payment page */
|
|
65
97
|
directPayment: boolean;
|
|
98
|
+
/** List of allowed payment methods */
|
|
66
99
|
paymentMethods?: string[];
|
|
100
|
+
/** Base64 encoded image for the payment page */
|
|
67
101
|
imageBase?: string;
|
|
102
|
+
/** Whether to save the payment token for future use */
|
|
68
103
|
saveToken?: boolean;
|
|
69
104
|
}
|
|
70
105
|
export interface PaymentLink extends PaymentLinkPayload {
|
|
@@ -46,6 +46,7 @@ declare enum Reasons {
|
|
|
46
46
|
SENDING_YOU_A_KISS = 80
|
|
47
47
|
}
|
|
48
48
|
export interface PaymentLinkPayload {
|
|
49
|
+
accountId: number;
|
|
49
50
|
reference: string;
|
|
50
51
|
concept: string;
|
|
51
52
|
favorite: boolean;
|
|
@@ -60,9 +61,6 @@ export interface PaymentLinkPayload {
|
|
|
60
61
|
urlFailed: string;
|
|
61
62
|
urlNotification: string;
|
|
62
63
|
serviceDate: string;
|
|
63
|
-
/**
|
|
64
|
-
* fgfsgdfgdfgd
|
|
65
|
-
*/
|
|
66
64
|
client?: {
|
|
67
65
|
name: string;
|
|
68
66
|
lastName: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yosle/tropipayjs",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Javascript / Typescript SDK for the Tropipay API",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -46,4 +46,4 @@
|
|
|
46
46
|
"type": "individual",
|
|
47
47
|
"url": "https://tppay.me/l94qaa3h"
|
|
48
48
|
}
|
|
49
|
-
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Tropipay } from "../api/TropipayAPI";
|
|
2
|
+
import { handleExceptions } from "../utils/errors";
|
|
3
|
+
|
|
4
|
+
// Account interfaces
|
|
5
|
+
export interface PaymentMethod {
|
|
6
|
+
slug: string;
|
|
7
|
+
name: string;
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
allowedCurrencies: string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ServiceLimit {
|
|
13
|
+
value: number | null;
|
|
14
|
+
currency: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ServiceLimits {
|
|
18
|
+
min: ServiceLimit;
|
|
19
|
+
max: ServiceLimit;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface Service {
|
|
23
|
+
slug: string;
|
|
24
|
+
enabled: boolean;
|
|
25
|
+
allowed_currencies: string[];
|
|
26
|
+
limits: ServiceLimits;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface TropiCard {
|
|
30
|
+
// TropiCard properties can be added here as needed
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface Account {
|
|
34
|
+
id: number;
|
|
35
|
+
accountNumber: string;
|
|
36
|
+
userId: string;
|
|
37
|
+
alias: string;
|
|
38
|
+
balance: number;
|
|
39
|
+
pendingIn: number;
|
|
40
|
+
pendingOut: number;
|
|
41
|
+
state: number;
|
|
42
|
+
paymentEntityId: number;
|
|
43
|
+
currency: string;
|
|
44
|
+
type: number;
|
|
45
|
+
createdAt: string;
|
|
46
|
+
updatedAt: string;
|
|
47
|
+
isDefault: boolean;
|
|
48
|
+
groupId: number | null;
|
|
49
|
+
TropiCards: TropiCard[];
|
|
50
|
+
services: Service[];
|
|
51
|
+
paymentMethods: PaymentMethod[];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default class Accounts {
|
|
55
|
+
private tropipay: Tropipay;
|
|
56
|
+
|
|
57
|
+
constructor(tropipayInstance: Tropipay) {
|
|
58
|
+
this.tropipay = tropipayInstance;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* List all accounts of the authenticated user
|
|
63
|
+
* @returns Array of Account objects
|
|
64
|
+
*/
|
|
65
|
+
public async list(): Promise<Account[]> {
|
|
66
|
+
if (!Tropipay.accessToken) {
|
|
67
|
+
await this.tropipay.login();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
const accounts = await this.tropipay.request.get(
|
|
72
|
+
`/api/v3/accounts/`,
|
|
73
|
+
{
|
|
74
|
+
headers: {
|
|
75
|
+
"Content-Type": "application/json",
|
|
76
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
77
|
+
Accept: "application/json",
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
return accounts.data;
|
|
82
|
+
} catch (error) {
|
|
83
|
+
throw handleExceptions(error as unknown as any);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|