@yosle/tropipayjs 0.1.7 → 0.1.9
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 +23 -11
- package/docs/index.MD +19 -0
- package/globals.d.ts +18 -17
- package/index.d.ts +160 -113
- package/index.js +282 -223
- package/interfaces/countries/index.d.ts +1 -1
- package/interfaces/index.d.ts +2 -2
- package/interfaces/mediation/index.d.ts +22 -0
- package/interfaces/paymentlink/index.d.ts +36 -36
- package/package.json +4 -3
- package/src/index.ts +154 -94
- package/src/interfaces/mediation/index.ts +23 -0
- package/docs/README.MD +0 -4
package/README.md
CHANGED
|
@@ -22,8 +22,13 @@ TropiPay is an electronic wallet that allows you to execute the most common fina
|
|
|
22
22
|
- [Generating a Payment Link](#generating-a-payment-link)
|
|
23
23
|
- [Contributing](#contributing)
|
|
24
24
|
- [License](#license)
|
|
25
|
+
|
|
25
26
|
## About the project
|
|
26
|
-
This library is a community effort
|
|
27
|
+
This library is a community effort. Tropipay may make some changes on the API specification. Use the [test environment](https://tropipay-dev.herokuapp.com) to make sure everything is working as expected.
|
|
28
|
+
|
|
29
|
+
**Note:** This library is provided as-is and serves as a client for the Tropipay API. While every effort has been made to ensure the accuracy and reliability of the library, Tropipay is solely responsible for maintaining and updating the API documentation.
|
|
30
|
+
|
|
31
|
+
The library is intended to simplify the integration process with Tropipay's services, but it is essential to consult the official documentation to ensure that you are using the API correctly and taking into account any recent changes or updates made by Tropipay.
|
|
27
32
|
# Getting started
|
|
28
33
|
You can use npm or yarn to install this package:
|
|
29
34
|
|
|
@@ -55,24 +60,32 @@ import { Tropipay } from '@yosle/tropipayjs'
|
|
|
55
60
|
You can instantiate the Tropipay class passing the client Id ,client secret and optionally the serverMode parameter, if no serverMode is provided, `Development` will be used as default. Make sure you use the [test environment](https://tropipay-dev.herokuapp.com) credentials when serverMode is on `Development`.
|
|
56
61
|
|
|
57
62
|
```javascript
|
|
58
|
-
// test environment server
|
|
59
|
-
const
|
|
60
|
-
|
|
63
|
+
// test environment server tropipay-dev.herokuapp.com
|
|
64
|
+
const config = {
|
|
65
|
+
clientId: process.env.TROPIPAY_CLIENT_ID,
|
|
66
|
+
clientSecret: process.env.TROPIPAY_CLIENT_SECRET
|
|
67
|
+
serverMode: 'Development' // it will be used as default if omited
|
|
68
|
+
}
|
|
69
|
+
const tpp = new Tropipay(config)
|
|
61
70
|
```
|
|
62
71
|
|
|
63
72
|
To use your live credentials (real account) you must explicity set serverMode to `Production`.
|
|
64
73
|
|
|
65
74
|
```javascript
|
|
66
75
|
//real account credentials
|
|
67
|
-
const
|
|
68
|
-
|
|
76
|
+
const config = {
|
|
77
|
+
clientId: process.env.TROPIPAY_CLIENT_ID,
|
|
78
|
+
clientSecret: process.env.TROPIPAY_CLIENT_SECRET,
|
|
79
|
+
serverMode: 'Production' //live account
|
|
80
|
+
}
|
|
81
|
+
const tpp = new Tropipay(config)
|
|
69
82
|
```
|
|
70
83
|
### Generating a Payment Link
|
|
71
84
|
```javascript
|
|
72
85
|
/*
|
|
73
86
|
* Example Payload
|
|
74
87
|
*/
|
|
75
|
-
const payload =
|
|
88
|
+
const payload = {
|
|
76
89
|
reference: "my-paylink-1",
|
|
77
90
|
concept: "Bicycle",
|
|
78
91
|
favorite: "true",
|
|
@@ -97,11 +110,10 @@ const payload = await tpp.createPayLink({
|
|
|
97
110
|
termsAndConditions: "true"
|
|
98
111
|
},
|
|
99
112
|
directPayment: "true"
|
|
100
|
-
}
|
|
101
|
-
|
|
113
|
+
}
|
|
102
114
|
// Use inside an async function
|
|
103
|
-
const paylink = await tpp.
|
|
104
|
-
console.log(paylink.shortUrl)
|
|
115
|
+
const paylink = await tpp.createPaymentCard(payload);
|
|
116
|
+
console.log(paylink.shortUrl);
|
|
105
117
|
```
|
|
106
118
|
|
|
107
119
|
For more examples, please refer to the [Documentation](https://github.com/yosle/tropipayjs/blob/master/docs/)
|
package/docs/index.MD
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Tropipayjs
|
|
2
|
+
|
|
3
|
+
Tropipayjs is a TypeScript/JavaScript library for the Tropipay API.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Installation](#installation)
|
|
8
|
+
- [Usage](#usage)
|
|
9
|
+
- [API Reference](#api-reference)
|
|
10
|
+
- [Contributing](#contributing)
|
|
11
|
+
- [License](#license)
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
To use Tropipayjs in your project, you need to install it via npm. Run the following command:
|
|
16
|
+
|
|
17
|
+
```npm install tropipayjs```
|
|
18
|
+
or
|
|
19
|
+
```yarn add tropipayjs```
|
package/globals.d.ts
CHANGED
|
@@ -11,20 +11,20 @@ type LoginError = {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
type Country = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
id: number,
|
|
15
|
+
name: string,
|
|
16
|
+
sepaZone: boolean,
|
|
17
|
+
state: number,
|
|
18
|
+
slug: string,
|
|
19
|
+
slugn: number,
|
|
20
|
+
callingCode: number,
|
|
21
|
+
isDestination: boolean,
|
|
22
|
+
isRisky: boolean,
|
|
23
|
+
currentCurrency: string | null,
|
|
24
|
+
createdAt: string,
|
|
25
|
+
updatedAt: string,
|
|
26
|
+
isFavorite: boolean,
|
|
27
|
+
position: any
|
|
28
28
|
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -69,6 +69,7 @@ type Deposit = {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
type AccountDeposits = {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
72
|
+
count: number,
|
|
73
|
+
rows: Deposit[]
|
|
74
|
+
}
|
|
75
|
+
|
package/index.d.ts
CHANGED
|
@@ -1,113 +1,160 @@
|
|
|
1
|
-
import { Axios } from 'axios';
|
|
2
|
-
|
|
3
|
-
interface PaymentLinkPayload {
|
|
4
|
-
reference: string;
|
|
5
|
-
concept: string;
|
|
6
|
-
favorite: boolean;
|
|
7
|
-
amount: number;
|
|
8
|
-
currency: string;
|
|
9
|
-
description: string;
|
|
10
|
-
singleUse: boolean;
|
|
11
|
-
reasonId: number;
|
|
12
|
-
expirationDays: number;
|
|
13
|
-
lang: string;
|
|
14
|
-
urlSuccess: string;
|
|
15
|
-
urlFailed: string;
|
|
16
|
-
urlNotification: string;
|
|
17
|
-
serviceDate: string;
|
|
18
|
-
client: {
|
|
19
|
-
name: string;
|
|
20
|
-
lastName: string;
|
|
21
|
-
address: string;
|
|
22
|
-
phone: string;
|
|
23
|
-
email: string;
|
|
24
|
-
countryId: number;
|
|
25
|
-
termsAndConditions: boolean;
|
|
26
|
-
};
|
|
27
|
-
directPayment: boolean;
|
|
28
|
-
paymentMethods?: string[];
|
|
29
|
-
}
|
|
30
|
-
interface PaymentLink extends PaymentLinkPayload {
|
|
31
|
-
expirationDate: string;
|
|
32
|
-
hasClient: boolean;
|
|
33
|
-
updatedAt: string;
|
|
34
|
-
createdAt: string;
|
|
35
|
-
qrImage: string;
|
|
36
|
-
shortUrl: string;
|
|
37
|
-
paymentUrl: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
*
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* @
|
|
95
|
-
*/
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
*
|
|
99
|
-
* @returns
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
*
|
|
105
|
-
* @
|
|
106
|
-
* @
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
1
|
+
import { Axios } from 'axios';
|
|
2
|
+
|
|
3
|
+
interface PaymentLinkPayload {
|
|
4
|
+
reference: string;
|
|
5
|
+
concept: string;
|
|
6
|
+
favorite: boolean;
|
|
7
|
+
amount: number;
|
|
8
|
+
currency: string;
|
|
9
|
+
description: string;
|
|
10
|
+
singleUse: boolean;
|
|
11
|
+
reasonId: number;
|
|
12
|
+
expirationDays: number;
|
|
13
|
+
lang: string;
|
|
14
|
+
urlSuccess: string;
|
|
15
|
+
urlFailed: string;
|
|
16
|
+
urlNotification: string;
|
|
17
|
+
serviceDate: string;
|
|
18
|
+
client: {
|
|
19
|
+
name: string;
|
|
20
|
+
lastName: string;
|
|
21
|
+
address: string;
|
|
22
|
+
phone: string;
|
|
23
|
+
email: string;
|
|
24
|
+
countryId: number;
|
|
25
|
+
termsAndConditions: boolean;
|
|
26
|
+
};
|
|
27
|
+
directPayment: boolean;
|
|
28
|
+
paymentMethods?: string[];
|
|
29
|
+
}
|
|
30
|
+
interface PaymentLink extends PaymentLinkPayload {
|
|
31
|
+
expirationDate: string;
|
|
32
|
+
hasClient: boolean;
|
|
33
|
+
updatedAt: string;
|
|
34
|
+
createdAt: string;
|
|
35
|
+
qrImage: string;
|
|
36
|
+
shortUrl: string;
|
|
37
|
+
paymentUrl: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
43
|
+
interface mediationPaymentCardConfig {
|
|
44
|
+
amount: number;
|
|
45
|
+
currency: "EUR" | "USD";
|
|
46
|
+
concept: string;
|
|
47
|
+
description: string;
|
|
48
|
+
reference: string;
|
|
49
|
+
singleUse: boolean;
|
|
50
|
+
lang: string;
|
|
51
|
+
productUrl?: string;
|
|
52
|
+
buyer: null | any;
|
|
53
|
+
seller: {
|
|
54
|
+
sellerId?: number;
|
|
55
|
+
type?: number;
|
|
56
|
+
email?: string;
|
|
57
|
+
};
|
|
58
|
+
feePercent?: number;
|
|
59
|
+
feeFixed?: number;
|
|
60
|
+
sendMail: boolean;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Tropipayjs is a Typescript/Javascript library for the Tropipay API.
|
|
65
|
+
*
|
|
66
|
+
* @author Yosleivy Baez Acosta
|
|
67
|
+
*
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
type ServerMode = 'Development' | 'Production';
|
|
71
|
+
interface TropipayConfig {
|
|
72
|
+
clientId: string;
|
|
73
|
+
clientSecret: string;
|
|
74
|
+
serverMode?: ServerMode;
|
|
75
|
+
}
|
|
76
|
+
type AccountBalance = {
|
|
77
|
+
balance: number;
|
|
78
|
+
pendingIn: number;
|
|
79
|
+
pendingOut: number;
|
|
80
|
+
};
|
|
81
|
+
declare class Tropipay {
|
|
82
|
+
protected clientId: string;
|
|
83
|
+
protected clientSecret: string;
|
|
84
|
+
protected request: Axios;
|
|
85
|
+
protected static accessToken: string | undefined;
|
|
86
|
+
protected static refreshToken: string | undefined;
|
|
87
|
+
protected serverMode: ServerMode;
|
|
88
|
+
constructor(config: TropipayConfig);
|
|
89
|
+
login(): Promise<LoginResponse>;
|
|
90
|
+
/**
|
|
91
|
+
* Create a paymentLink with the specified options.
|
|
92
|
+
* @param payload PaymentLinkPayload Object.
|
|
93
|
+
* @returns Promise<PaymentLink> or throws an Exception.
|
|
94
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
95
|
+
*/
|
|
96
|
+
createPaymentCard(payload: PaymentLinkPayload): Promise<PaymentLink>;
|
|
97
|
+
/**
|
|
98
|
+
* Get all deposits in this account.
|
|
99
|
+
* @returns A Promise of an Array of AccountDeposits or throws an Exception
|
|
100
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6OTgyOTQ1Mg-get-deposit-accounts-list
|
|
101
|
+
*/
|
|
102
|
+
getDepositAccounts(): Promise<AccountDeposits[] | Error>;
|
|
103
|
+
/**
|
|
104
|
+
* Get the list of all supported countries by Tropipay.
|
|
105
|
+
* @returns Array of Countries Data
|
|
106
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/bfac21259e2ff-getting-users-countries-list
|
|
107
|
+
*/
|
|
108
|
+
countries(): Promise<Country[]>;
|
|
109
|
+
/**
|
|
110
|
+
* Get user balance
|
|
111
|
+
* @returns balance object
|
|
112
|
+
*/
|
|
113
|
+
getBalance(): Promise<AccountBalance>;
|
|
114
|
+
/**
|
|
115
|
+
* Get the list of all detination countries supported by Tropipay.
|
|
116
|
+
* Obtaining the list of valid countries to send funds to. Useful
|
|
117
|
+
* when adding new beneficiaries to some user.
|
|
118
|
+
*
|
|
119
|
+
* @returns Array of Country Objects
|
|
120
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/3cfe5504f0524-getting-list-of-beneficiary-countries
|
|
121
|
+
*/
|
|
122
|
+
destinations(): Promise<Country[]>;
|
|
123
|
+
/**
|
|
124
|
+
* Get list of all the favorites payment links.
|
|
125
|
+
* @returns Array of account Object or throws an error
|
|
126
|
+
*/
|
|
127
|
+
favorites(): Promise<any>;
|
|
128
|
+
/**
|
|
129
|
+
* List all account movements. You can optionaly specify
|
|
130
|
+
* offset and limit params for pagination.
|
|
131
|
+
* @returns
|
|
132
|
+
*/
|
|
133
|
+
movements(offset?: number, limit?: number): Promise<any>;
|
|
134
|
+
/**
|
|
135
|
+
* Return profile data for this account.
|
|
136
|
+
* @returns
|
|
137
|
+
*/
|
|
138
|
+
profile(): Promise<any>;
|
|
139
|
+
/**
|
|
140
|
+
* Obtain current Tropipay conversion rate. For example USD to EUR
|
|
141
|
+
* targetCurrency must be 'EUR'
|
|
142
|
+
* @param originCurrency Target currency code supported by Tropipay.
|
|
143
|
+
* @param targetCurrency Must be 'EUR'? (not documented by Tropipay)
|
|
144
|
+
* @returns Conversion rate (number)
|
|
145
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/85163f6f28b23-get-rate
|
|
146
|
+
*/
|
|
147
|
+
rates(originCurrency: string, targetCurrency?: string): Promise<number | Error>;
|
|
148
|
+
/**
|
|
149
|
+
* (ONLY in Bussiness Accounts)
|
|
150
|
+
* An escrow payment link. This allows a payment to be made to persons
|
|
151
|
+
* belonging or not to the TropiPay platform with the particularity
|
|
152
|
+
* that the payment will be held in custody or retained until it is
|
|
153
|
+
* released with the approval of the payer.
|
|
154
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/12a128ff971e4-creating-a-mediation-payment-card
|
|
155
|
+
* @param config Payload with the payment details
|
|
156
|
+
*/
|
|
157
|
+
createMediationPaymentCard(config: mediationPaymentCardConfig): Promise<PaymentLink>;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export { Tropipay };
|