@yosle/tropipayjs 0.1.7 → 0.1.8
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 +6 -1
- package/docs/index.MD +19 -0
- package/index.d.ts +150 -113
- package/index.js +259 -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 +127 -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
|
|
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/index.d.ts
CHANGED
|
@@ -1,113 +1,150 @@
|
|
|
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
|
-
* @returns
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
*
|
|
94
|
-
* @returns
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
*
|
|
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
|
+
declare class Tropipay {
|
|
77
|
+
protected clientId: string;
|
|
78
|
+
protected clientSecret: string;
|
|
79
|
+
protected request: Axios;
|
|
80
|
+
protected static accessToken: string | undefined;
|
|
81
|
+
protected static refreshToken: string | undefined;
|
|
82
|
+
protected serverMode: ServerMode;
|
|
83
|
+
constructor(config: TropipayConfig);
|
|
84
|
+
login(): Promise<LoginResponse>;
|
|
85
|
+
/**
|
|
86
|
+
* Create a paymentLink with the specified options.
|
|
87
|
+
* @param payload PaymentLinkPayload Object.
|
|
88
|
+
* @returns Promise<PaymentLink> or throws an Exception.
|
|
89
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
90
|
+
*/
|
|
91
|
+
createPaymentCard(payload: PaymentLinkPayload): Promise<PaymentLink>;
|
|
92
|
+
/**
|
|
93
|
+
* Get all deposits in this account.
|
|
94
|
+
* @returns A Promise of an Array of AccountDeposits or throws an Exception
|
|
95
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6OTgyOTQ1Mg-get-deposit-accounts-list
|
|
96
|
+
*/
|
|
97
|
+
getDepositAccounts(): Promise<AccountDeposits[] | Error>;
|
|
98
|
+
/**
|
|
99
|
+
* Get the list of all supported countries by Tropipay.
|
|
100
|
+
* @returns Array of Countries Data
|
|
101
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/bfac21259e2ff-getting-users-countries-list
|
|
102
|
+
*/
|
|
103
|
+
countries(): Promise<Country[]>;
|
|
104
|
+
/**
|
|
105
|
+
* Get the list of all detination countries supported by Tropipay.
|
|
106
|
+
* Obtaining the list of valid countries to send funds to. Useful
|
|
107
|
+
* when adding new beneficiaries to some user.
|
|
108
|
+
*
|
|
109
|
+
* @returns Array of Country Objects
|
|
110
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/3cfe5504f0524-getting-list-of-beneficiary-countries
|
|
111
|
+
*/
|
|
112
|
+
destinations(): Promise<Country[]>;
|
|
113
|
+
/**
|
|
114
|
+
* Get list of all the favorites payment links.
|
|
115
|
+
* @returns Array of account Object or throws an error
|
|
116
|
+
*/
|
|
117
|
+
favorites(): Promise<any>;
|
|
118
|
+
/**
|
|
119
|
+
* List all account movements. You can optionaly specify
|
|
120
|
+
* offset and limit params for pagination.
|
|
121
|
+
* @returns
|
|
122
|
+
*/
|
|
123
|
+
movements(offset?: number, limit?: number): Promise<any>;
|
|
124
|
+
/**
|
|
125
|
+
* Return profile data for this account.
|
|
126
|
+
* @returns
|
|
127
|
+
*/
|
|
128
|
+
profile(): Promise<any>;
|
|
129
|
+
/**
|
|
130
|
+
* Obtain current Tropipay conversion rate. For example USD to EUR
|
|
131
|
+
* targetCurrency must be 'EUR'
|
|
132
|
+
* @param originCurrency Target currency code supported by Tropipay.
|
|
133
|
+
* @param targetCurrency Must be 'EUR'? (not documented by Tropipay)
|
|
134
|
+
* @returns Conversion rate (number)
|
|
135
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/85163f6f28b23-get-rate
|
|
136
|
+
*/
|
|
137
|
+
rates(originCurrency: string, targetCurrency?: string): Promise<number | Error>;
|
|
138
|
+
/**
|
|
139
|
+
* (ONLY in Bussiness Accounts)
|
|
140
|
+
* An escrow payment link. This allows a payment to be made to persons
|
|
141
|
+
* belonging or not to the TropiPay platform with the particularity
|
|
142
|
+
* that the payment will be held in custody or retained until it is
|
|
143
|
+
* released with the approval of the payer.
|
|
144
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/12a128ff971e4-creating-a-mediation-payment-card
|
|
145
|
+
* @param config Payload with the payment details
|
|
146
|
+
*/
|
|
147
|
+
createMediationPaymentCard(config: mediationPaymentCardConfig): Promise<PaymentLink>;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export { Tropipay };
|
package/index.js
CHANGED
|
@@ -1,223 +1,259 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var axios = require('axios');
|
|
6
|
-
|
|
7
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
-
|
|
9
|
-
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Tropipayjs is a Typescript/Javascript library for the Tropipay API.
|
|
13
|
-
*
|
|
14
|
-
* @author Yosleivy Baez Acosta
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
class Tropipay {
|
|
18
|
-
clientId;
|
|
19
|
-
clientSecret;
|
|
20
|
-
request;
|
|
21
|
-
accessToken;
|
|
22
|
-
refreshToken;
|
|
23
|
-
serverMode;
|
|
24
|
-
constructor(
|
|
25
|
-
this.clientId =
|
|
26
|
-
this.clientSecret =
|
|
27
|
-
this.serverMode =
|
|
28
|
-
this.request = axios__default["default"].create({
|
|
29
|
-
baseURL: this.serverMode === 'Production'
|
|
30
|
-
? 'https://www.tropipay.com'
|
|
31
|
-
: 'https://tropipay-dev.herokuapp.com',
|
|
32
|
-
headers: {
|
|
33
|
-
'Content-Type': 'application/json',
|
|
34
|
-
Accept: 'application/json',
|
|
35
|
-
Authorization: `Bearer ${
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
async login() {
|
|
40
|
-
try {
|
|
41
|
-
const { data } = await this.request.post('/api/v2/access/token', {
|
|
42
|
-
client_id: this.clientId,
|
|
43
|
-
client_secret: this.clientSecret,
|
|
44
|
-
grant_type: "client_credentials",
|
|
45
|
-
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"
|
|
46
|
-
}, {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return data;
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
if (axios__default["default"].isAxiosError(error)) {
|
|
58
|
-
throw new Error(`Could not obtain the access token from credentials ${error}`);
|
|
59
|
-
}
|
|
60
|
-
throw new Error(`Could not obtain the access token from credentials ${error}`);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Create a paymentLink with the specified options.
|
|
65
|
-
* @param payload PaymentLinkPayload Object.
|
|
66
|
-
* @returns Promise<PaymentLink> or throws an Exception.
|
|
67
|
-
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
68
|
-
*/
|
|
69
|
-
async
|
|
70
|
-
if (!
|
|
71
|
-
await this.login();
|
|
72
|
-
}
|
|
73
|
-
try {
|
|
74
|
-
const paylink = await this.request.post('/api/v2/paymentcards', payload, {
|
|
75
|
-
headers: {
|
|
76
|
-
|
|
77
|
-
Authorization: `Bearer ${
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
return paylink.data;
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
throw new Error(`Could not obtain the access token with the given credentials.`);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Get all deposits in this account.
|
|
89
|
-
* @returns A Promise of an Array of AccountDeposits or throws an Exception
|
|
90
|
-
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6OTgyOTQ1Mg-get-deposit-accounts-list
|
|
91
|
-
*/
|
|
92
|
-
async getDepositAccounts() {
|
|
93
|
-
if (!
|
|
94
|
-
await this.login();
|
|
95
|
-
}
|
|
96
|
-
try {
|
|
97
|
-
const deposits = await this.request.get('/api/v2/deposit_accounts', {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var axios = require('axios');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Tropipayjs is a Typescript/Javascript library for the Tropipay API.
|
|
13
|
+
*
|
|
14
|
+
* @author Yosleivy Baez Acosta
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
class Tropipay {
|
|
18
|
+
clientId;
|
|
19
|
+
clientSecret;
|
|
20
|
+
request;
|
|
21
|
+
static accessToken;
|
|
22
|
+
static refreshToken;
|
|
23
|
+
serverMode;
|
|
24
|
+
constructor(config) {
|
|
25
|
+
this.clientId = config.clientId;
|
|
26
|
+
this.clientSecret = config.clientSecret;
|
|
27
|
+
this.serverMode = config.serverMode || 'Development';
|
|
28
|
+
this.request = axios__default["default"].create({
|
|
29
|
+
baseURL: this.serverMode === 'Production'
|
|
30
|
+
? 'https://www.tropipay.com'
|
|
31
|
+
: 'https://tropipay-dev.herokuapp.com',
|
|
32
|
+
headers: {
|
|
33
|
+
'Content-Type': 'application/json',
|
|
34
|
+
Accept: 'application/json',
|
|
35
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async login() {
|
|
40
|
+
try {
|
|
41
|
+
const { data } = await this.request.post('/api/v2/access/token', {
|
|
42
|
+
client_id: this.clientId,
|
|
43
|
+
client_secret: this.clientSecret,
|
|
44
|
+
grant_type: "client_credentials",
|
|
45
|
+
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"
|
|
46
|
+
}, {
|
|
47
|
+
headers: {
|
|
48
|
+
'Content-Type': 'application/json',
|
|
49
|
+
Accept: 'application/json',
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
Tropipay.accessToken = data.access_token;
|
|
53
|
+
Tropipay.refreshToken = data.refresh_token;
|
|
54
|
+
return data;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (axios__default["default"].isAxiosError(error)) {
|
|
58
|
+
throw new Error(`Could not obtain the access token from credentials ${error}`);
|
|
59
|
+
}
|
|
60
|
+
throw new Error(`Could not obtain the access token from credentials ${error}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create a paymentLink with the specified options.
|
|
65
|
+
* @param payload PaymentLinkPayload Object.
|
|
66
|
+
* @returns Promise<PaymentLink> or throws an Exception.
|
|
67
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
68
|
+
*/
|
|
69
|
+
async createPaymentCard(payload) {
|
|
70
|
+
if (!Tropipay.accessToken) {
|
|
71
|
+
await this.login();
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
const paylink = await this.request.post('/api/v2/paymentcards', payload, {
|
|
75
|
+
headers: {
|
|
76
|
+
'Content-Type': 'application/json',
|
|
77
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
78
|
+
Accept: 'application/json'
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return paylink.data;
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
throw new Error(`Could not obtain the access token with the given credentials.`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get all deposits in this account.
|
|
89
|
+
* @returns A Promise of an Array of AccountDeposits or throws an Exception
|
|
90
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6OTgyOTQ1Mg-get-deposit-accounts-list
|
|
91
|
+
*/
|
|
92
|
+
async getDepositAccounts() {
|
|
93
|
+
if (!Tropipay.accessToken) {
|
|
94
|
+
await this.login();
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const deposits = await this.request.get('/api/v2/deposit_accounts', {
|
|
98
|
+
headers: {
|
|
99
|
+
'Content-Type': 'application/json',
|
|
100
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
101
|
+
Accept: 'application/json'
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
return deposits.data;
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
throw new Error(`Could not retrieve the account deposits ${error}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get the list of all supported countries by Tropipay.
|
|
112
|
+
* @returns Array of Countries Data
|
|
113
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/bfac21259e2ff-getting-users-countries-list
|
|
114
|
+
*/
|
|
115
|
+
async countries() {
|
|
116
|
+
try {
|
|
117
|
+
const countries = await this.request.get('/api/v2/countries');
|
|
118
|
+
return countries.data;
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
throw new Error(`TropipayJS Error - Could not retrieve the countries list`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Get the list of all detination countries supported by Tropipay.
|
|
126
|
+
* Obtaining the list of valid countries to send funds to. Useful
|
|
127
|
+
* when adding new beneficiaries to some user.
|
|
128
|
+
*
|
|
129
|
+
* @returns Array of Country Objects
|
|
130
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/3cfe5504f0524-getting-list-of-beneficiary-countries
|
|
131
|
+
*/
|
|
132
|
+
async destinations() {
|
|
133
|
+
try {
|
|
134
|
+
const countries = await this.request.get('/api/v2/countries/destinations');
|
|
135
|
+
return countries.data;
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
throw new Error(`Could not retrieve the destination countries list`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Get list of all the favorites payment links.
|
|
143
|
+
* @returns Array of account Object or throws an error
|
|
144
|
+
*/
|
|
145
|
+
async favorites() {
|
|
146
|
+
if (!Tropipay.accessToken) {
|
|
147
|
+
await this.login();
|
|
148
|
+
}
|
|
149
|
+
try {
|
|
150
|
+
const favoritesList = await this.request.get('/api/v2/paymentcards/favorites', {
|
|
151
|
+
headers: {
|
|
152
|
+
'Content-Type': 'application/json',
|
|
153
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
154
|
+
Accept: 'application/json'
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
return favoritesList?.data?.rows;
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
throw new Error(`Could not retrieve favorites list ${error}`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* List all account movements. You can optionaly specify
|
|
165
|
+
* offset and limit params for pagination.
|
|
166
|
+
* @returns
|
|
167
|
+
*/
|
|
168
|
+
async movements(offset = 0, limit = 10) {
|
|
169
|
+
if (!Tropipay.accessToken)
|
|
170
|
+
await this.login();
|
|
171
|
+
try {
|
|
172
|
+
const movements = await this.request.get('/api/v2/movements', {
|
|
173
|
+
params: { limit: limit, offset: offset },
|
|
174
|
+
headers: {
|
|
175
|
+
'Content-Type': 'application/json',
|
|
176
|
+
Accept: 'application/json',
|
|
177
|
+
Authorization: `Bearer ${Tropipay.accessToken}`
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
return movements.data;
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
throw new Error(`Could not retrieve movements list ${error}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Return profile data for this account.
|
|
188
|
+
* @returns
|
|
189
|
+
*/
|
|
190
|
+
async profile() {
|
|
191
|
+
if (!Tropipay.accessToken)
|
|
192
|
+
await this.login();
|
|
193
|
+
try {
|
|
194
|
+
const profile = await this.request.get('/api/users/profile');
|
|
195
|
+
return profile.data;
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
throw new Error(`Could not retrieve movements list ${error}`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Obtain current Tropipay conversion rate. For example USD to EUR
|
|
203
|
+
* targetCurrency must be 'EUR'
|
|
204
|
+
* @param originCurrency Target currency code supported by Tropipay.
|
|
205
|
+
* @param targetCurrency Must be 'EUR'? (not documented by Tropipay)
|
|
206
|
+
* @returns Conversion rate (number)
|
|
207
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/85163f6f28b23-get-rate
|
|
208
|
+
*/
|
|
209
|
+
async rates(originCurrency, targetCurrency = 'EUR') {
|
|
210
|
+
if (!Tropipay.accessToken) {
|
|
211
|
+
await this.login();
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
const rates = await this.request.post('/api/v2/movements/get_rate', {
|
|
215
|
+
currencyFrom: originCurrency,
|
|
216
|
+
currencyTo: targetCurrency
|
|
217
|
+
}, {
|
|
218
|
+
headers: {
|
|
219
|
+
'Content-Type': 'application/json',
|
|
220
|
+
Accept: 'application/json',
|
|
221
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
return rates.data.rate;
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
throw new Error(`Could not retrieve rates ${error}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* (ONLY in Bussiness Accounts)
|
|
232
|
+
* An escrow payment link. This allows a payment to be made to persons
|
|
233
|
+
* belonging or not to the TropiPay platform with the particularity
|
|
234
|
+
* that the payment will be held in custody or retained until it is
|
|
235
|
+
* released with the approval of the payer.
|
|
236
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/12a128ff971e4-creating-a-mediation-payment-card
|
|
237
|
+
* @param config Payload with the payment details
|
|
238
|
+
*/
|
|
239
|
+
async createMediationPaymentCard(config) {
|
|
240
|
+
if (!Tropipay.accessToken)
|
|
241
|
+
await this.login();
|
|
242
|
+
try {
|
|
243
|
+
const mediation = await this.request.post('/api/v2/paymentcards/mediation', config, {
|
|
244
|
+
headers: {
|
|
245
|
+
'Content-Type': 'application/json',
|
|
246
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
247
|
+
Accept: 'application/json'
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
return mediation.data;
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
throw new Error(`Could not generate mediation paymentCard ${error}`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
exports.Tropipay = Tropipay;
|
|
259
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type TropipayCountry = {};
|
package/interfaces/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import * as countries from './countries';
|
|
2
|
-
export { countries };
|
|
1
|
+
import * as countries from './countries';
|
|
2
|
+
export { countries };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
*/
|
|
4
|
+
export interface mediationPaymentCardConfig {
|
|
5
|
+
amount: number;
|
|
6
|
+
currency: "EUR" | "USD";
|
|
7
|
+
concept: string;
|
|
8
|
+
description: string;
|
|
9
|
+
reference: string;
|
|
10
|
+
singleUse: boolean;
|
|
11
|
+
lang: string;
|
|
12
|
+
productUrl?: string;
|
|
13
|
+
buyer: null | any;
|
|
14
|
+
seller: {
|
|
15
|
+
sellerId?: number;
|
|
16
|
+
type?: number;
|
|
17
|
+
email?: string;
|
|
18
|
+
};
|
|
19
|
+
feePercent?: number;
|
|
20
|
+
feeFixed?: number;
|
|
21
|
+
sendMail: boolean;
|
|
22
|
+
}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
export interface PaymentLinkPayload {
|
|
2
|
-
reference: string;
|
|
3
|
-
concept: string;
|
|
4
|
-
favorite: boolean;
|
|
5
|
-
amount: number;
|
|
6
|
-
currency: string;
|
|
7
|
-
description: string;
|
|
8
|
-
singleUse: boolean;
|
|
9
|
-
reasonId: number;
|
|
10
|
-
expirationDays: number;
|
|
11
|
-
lang: string;
|
|
12
|
-
urlSuccess: string;
|
|
13
|
-
urlFailed: string;
|
|
14
|
-
urlNotification: string;
|
|
15
|
-
serviceDate: string;
|
|
16
|
-
client: {
|
|
17
|
-
name: string;
|
|
18
|
-
lastName: string;
|
|
19
|
-
address: string;
|
|
20
|
-
phone: string;
|
|
21
|
-
email: string;
|
|
22
|
-
countryId: number;
|
|
23
|
-
termsAndConditions: boolean;
|
|
24
|
-
};
|
|
25
|
-
directPayment: boolean;
|
|
26
|
-
paymentMethods?: string[];
|
|
27
|
-
}
|
|
28
|
-
export interface PaymentLink extends PaymentLinkPayload {
|
|
29
|
-
expirationDate: string;
|
|
30
|
-
hasClient: boolean;
|
|
31
|
-
updatedAt: string;
|
|
32
|
-
createdAt: string;
|
|
33
|
-
qrImage: string;
|
|
34
|
-
shortUrl: string;
|
|
35
|
-
paymentUrl: string;
|
|
36
|
-
}
|
|
1
|
+
export interface PaymentLinkPayload {
|
|
2
|
+
reference: string;
|
|
3
|
+
concept: string;
|
|
4
|
+
favorite: boolean;
|
|
5
|
+
amount: number;
|
|
6
|
+
currency: string;
|
|
7
|
+
description: string;
|
|
8
|
+
singleUse: boolean;
|
|
9
|
+
reasonId: number;
|
|
10
|
+
expirationDays: number;
|
|
11
|
+
lang: string;
|
|
12
|
+
urlSuccess: string;
|
|
13
|
+
urlFailed: string;
|
|
14
|
+
urlNotification: string;
|
|
15
|
+
serviceDate: string;
|
|
16
|
+
client: {
|
|
17
|
+
name: string;
|
|
18
|
+
lastName: string;
|
|
19
|
+
address: string;
|
|
20
|
+
phone: string;
|
|
21
|
+
email: string;
|
|
22
|
+
countryId: number;
|
|
23
|
+
termsAndConditions: boolean;
|
|
24
|
+
};
|
|
25
|
+
directPayment: boolean;
|
|
26
|
+
paymentMethods?: string[];
|
|
27
|
+
}
|
|
28
|
+
export interface PaymentLink extends PaymentLinkPayload {
|
|
29
|
+
expirationDate: string;
|
|
30
|
+
hasClient: boolean;
|
|
31
|
+
updatedAt: string;
|
|
32
|
+
createdAt: string;
|
|
33
|
+
qrImage: string;
|
|
34
|
+
shortUrl: string;
|
|
35
|
+
paymentUrl: string;
|
|
36
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yosle/tropipayjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Javascript / Typescript SDK for the Tropipay API",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"_clear": "rimraf src/dist/*",
|
|
9
9
|
"_tsc": "tsc",
|
|
10
10
|
"_make-bundle": "rollup --config",
|
|
11
|
-
"build": "
|
|
11
|
+
"build": "yarn _clear && yarn _tsc && yarn _make-bundle"
|
|
12
12
|
},
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"rimraf": "^3.0.2",
|
|
34
34
|
"rollup": "^2.79.1",
|
|
35
35
|
"rollup-plugin-dts": "^4.2.2",
|
|
36
|
-
"run-s": "^0.0.0"
|
|
36
|
+
"run-s": "^0.0.0",
|
|
37
|
+
"typescript": "^5.0.4"
|
|
37
38
|
},
|
|
38
39
|
"funding": {
|
|
39
40
|
"type": "individual",
|
package/src/index.ts
CHANGED
|
@@ -7,27 +7,28 @@
|
|
|
7
7
|
|
|
8
8
|
import axios, { Axios } from "axios";
|
|
9
9
|
import { PaymentLink, PaymentLinkPayload } from './interfaces/paymentlink'
|
|
10
|
-
|
|
10
|
+
import { mediationPaymentCardConfig } from "./interfaces/mediation";
|
|
11
11
|
|
|
12
12
|
type ServerMode = 'Development' | 'Production'
|
|
13
13
|
|
|
14
|
+
interface TropipayConfig {
|
|
15
|
+
clientId: string;
|
|
16
|
+
clientSecret: string;
|
|
17
|
+
serverMode?: ServerMode;
|
|
18
|
+
}
|
|
14
19
|
|
|
15
20
|
export class Tropipay {
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
protected clientId: string;
|
|
22
|
+
protected clientSecret: string;
|
|
18
23
|
protected request: Axios;
|
|
19
|
-
protected accessToken: string | undefined;
|
|
20
|
-
protected refreshToken: string | undefined;
|
|
24
|
+
protected static accessToken: string | undefined;
|
|
25
|
+
protected static refreshToken: string | undefined;
|
|
21
26
|
protected serverMode: ServerMode;
|
|
22
27
|
|
|
23
|
-
constructor(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.clientId = client_id;
|
|
28
|
-
this.clientSecret = client_secret
|
|
29
|
-
this.serverMode = server_mode
|
|
30
|
-
|
|
28
|
+
constructor(config: TropipayConfig) {
|
|
29
|
+
this.clientId = config.clientId;
|
|
30
|
+
this.clientSecret = config.clientSecret;
|
|
31
|
+
this.serverMode = config.serverMode || 'Development';
|
|
31
32
|
this.request = axios.create({
|
|
32
33
|
baseURL: this.serverMode === 'Production'
|
|
33
34
|
? 'https://www.tropipay.com'
|
|
@@ -35,10 +36,9 @@ export class Tropipay {
|
|
|
35
36
|
headers: {
|
|
36
37
|
'Content-Type': 'application/json',
|
|
37
38
|
Accept: 'application/json',
|
|
38
|
-
Authorization: `Bearer ${
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
})
|
|
39
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
|
|
@@ -50,20 +50,20 @@ export class Tropipay {
|
|
|
50
50
|
grant_type: "client_credentials",
|
|
51
51
|
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"
|
|
52
52
|
}, {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
})
|
|
53
|
+
headers: {
|
|
54
|
+
'Content-Type': 'application/json',
|
|
55
|
+
Accept: 'application/json',
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
Tropipay.accessToken = data.access_token
|
|
60
|
+
Tropipay.refreshToken = data.refresh_token
|
|
61
61
|
return data
|
|
62
62
|
} catch (error) {
|
|
63
63
|
if (axios.isAxiosError(error)) {
|
|
64
64
|
throw new Error(`Could not obtain the access token from credentials ${error}`);
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
}
|
|
66
|
+
throw new Error(`Could not obtain the access token from credentials ${error}`);
|
|
67
67
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -74,22 +74,21 @@ export class Tropipay {
|
|
|
74
74
|
* @returns Promise<PaymentLink> or throws an Exception.
|
|
75
75
|
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
76
76
|
*/
|
|
77
|
-
async
|
|
78
|
-
if (!
|
|
77
|
+
async createPaymentCard(payload: PaymentLinkPayload): Promise<PaymentLink> {
|
|
78
|
+
if (!Tropipay.accessToken) {
|
|
79
79
|
await this.login()
|
|
80
80
|
}
|
|
81
81
|
try {
|
|
82
82
|
const paylink = await this.request.post('/api/v2/paymentcards', payload, {
|
|
83
83
|
headers: {
|
|
84
|
-
|
|
85
|
-
Authorization: `Bearer ${
|
|
86
|
-
|
|
84
|
+
'Content-Type': 'application/json',
|
|
85
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
86
|
+
Accept: 'application/json'
|
|
87
87
|
}
|
|
88
88
|
})
|
|
89
89
|
return paylink.data as PaymentLink
|
|
90
90
|
} catch (error) {
|
|
91
91
|
throw new Error(`Could not obtain the access token with the given credentials.`);
|
|
92
|
-
|
|
93
92
|
}
|
|
94
93
|
}
|
|
95
94
|
|
|
@@ -98,15 +97,21 @@ export class Tropipay {
|
|
|
98
97
|
* @returns A Promise of an Array of AccountDeposits or throws an Exception
|
|
99
98
|
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6OTgyOTQ1Mg-get-deposit-accounts-list
|
|
100
99
|
*/
|
|
101
|
-
async getDepositAccounts(): Promise<AccountDeposits[] | Error>{
|
|
102
|
-
if (!
|
|
100
|
+
async getDepositAccounts(): Promise<AccountDeposits[] | Error> {
|
|
101
|
+
if (!Tropipay.accessToken) {
|
|
103
102
|
await this.login()
|
|
104
103
|
}
|
|
105
104
|
try {
|
|
106
|
-
const deposits
|
|
105
|
+
const deposits = await this.request.get('/api/v2/deposit_accounts', {
|
|
106
|
+
headers: {
|
|
107
|
+
'Content-Type': 'application/json',
|
|
108
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
109
|
+
Accept: 'application/json'
|
|
110
|
+
}
|
|
111
|
+
})
|
|
107
112
|
return deposits.data
|
|
108
113
|
} catch (error) {
|
|
109
|
-
throw new Error(`Could not retrieve the account deposits ${error}`);
|
|
114
|
+
throw new Error(`Could not retrieve the account deposits ${error}`);
|
|
110
115
|
}
|
|
111
116
|
}
|
|
112
117
|
|
|
@@ -115,17 +120,15 @@ export class Tropipay {
|
|
|
115
120
|
* @returns Array of Countries Data
|
|
116
121
|
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/bfac21259e2ff-getting-users-countries-list
|
|
117
122
|
*/
|
|
118
|
-
async countries(): Promise<Country[]
|
|
119
|
-
|
|
123
|
+
async countries(): Promise<Country[]> {
|
|
120
124
|
try {
|
|
121
|
-
const countries
|
|
125
|
+
const countries = await this.request.get('/api/v2/countries')
|
|
122
126
|
return countries.data
|
|
123
127
|
} catch (error) {
|
|
124
|
-
throw new Error(`Could not retrieve the countries list`);
|
|
128
|
+
throw new Error(`TropipayJS Error - Could not retrieve the countries list`);
|
|
125
129
|
}
|
|
126
130
|
}
|
|
127
131
|
|
|
128
|
-
|
|
129
132
|
/**
|
|
130
133
|
* Get the list of all detination countries supported by Tropipay.
|
|
131
134
|
* Obtaining the list of valid countries to send funds to. Useful
|
|
@@ -136,28 +139,32 @@ export class Tropipay {
|
|
|
136
139
|
*/
|
|
137
140
|
async destinations(): Promise<Country[]> {
|
|
138
141
|
try {
|
|
139
|
-
const countries
|
|
142
|
+
const countries = await this.request.get('/api/v2/countries/destinations')
|
|
140
143
|
return countries.data
|
|
141
144
|
} catch (error) {
|
|
142
|
-
throw new Error(`Could not retrieve the destination countries list`);
|
|
145
|
+
throw new Error(`Could not retrieve the destination countries list`);
|
|
143
146
|
}
|
|
144
147
|
}
|
|
145
148
|
|
|
146
149
|
/**
|
|
147
|
-
* Get list of all the favorites
|
|
148
|
-
*
|
|
149
|
-
* @returns
|
|
150
|
+
* Get list of all the favorites payment links.
|
|
151
|
+
* @returns Array of account Object or throws an error
|
|
150
152
|
*/
|
|
151
|
-
async favorites(){
|
|
152
|
-
if (!
|
|
153
|
+
async favorites() {
|
|
154
|
+
if (!Tropipay.accessToken) {
|
|
153
155
|
await this.login()
|
|
154
156
|
}
|
|
155
157
|
try {
|
|
156
|
-
const favoritesList
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
const favoritesList = await this.request.get('/api/v2/paymentcards/favorites', {
|
|
159
|
+
headers: {
|
|
160
|
+
'Content-Type': 'application/json',
|
|
161
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
162
|
+
Accept: 'application/json'
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
return favoritesList?.data?.rows
|
|
166
|
+
} catch (error) {
|
|
167
|
+
throw new Error(`Could not retrieve favorites list ${error}`);
|
|
161
168
|
}
|
|
162
169
|
}
|
|
163
170
|
|
|
@@ -166,41 +173,39 @@ export class Tropipay {
|
|
|
166
173
|
* offset and limit params for pagination.
|
|
167
174
|
* @returns
|
|
168
175
|
*/
|
|
169
|
-
async movements(offset = 0
|
|
170
|
-
if (!
|
|
171
|
-
await this.login()
|
|
172
|
-
}
|
|
173
|
-
try {
|
|
174
|
-
const movements = await this.request.get('/api/v2/movements',
|
|
175
|
-
{params: {limit: limit, offset: offset},
|
|
176
|
-
headers: {
|
|
177
|
-
'Content-Type': 'application/json',
|
|
178
|
-
Accept: 'application/json',
|
|
179
|
-
Authorization: `Bearer ${this.accessToken}`,
|
|
176
|
+
async movements(offset = 0, limit = 10) {
|
|
177
|
+
if (!Tropipay.accessToken) await this.login()
|
|
180
178
|
|
|
181
|
-
|
|
182
|
-
|
|
179
|
+
try {
|
|
180
|
+
const movements = await this.request.get('/api/v2/movements',
|
|
181
|
+
{
|
|
182
|
+
params: { limit: limit, offset: offset },
|
|
183
|
+
headers: {
|
|
184
|
+
'Content-Type': 'application/json',
|
|
185
|
+
Accept: 'application/json',
|
|
186
|
+
Authorization: `Bearer ${Tropipay.accessToken}`
|
|
187
|
+
}
|
|
188
|
+
})
|
|
189
|
+
return movements.data
|
|
183
190
|
} catch (error) {
|
|
184
|
-
throw new Error(`Could not retrieve movements list`);
|
|
191
|
+
throw new Error(`Could not retrieve movements list ${error}`);
|
|
185
192
|
}
|
|
186
|
-
|
|
187
193
|
}
|
|
188
194
|
|
|
189
195
|
/**
|
|
190
196
|
* Return profile data for this account.
|
|
191
197
|
* @returns
|
|
192
198
|
*/
|
|
193
|
-
async profile(){
|
|
194
|
-
if (!
|
|
195
|
-
await this.login()
|
|
196
|
-
}
|
|
199
|
+
async profile() {
|
|
200
|
+
if (!Tropipay.accessToken) await this.login();
|
|
197
201
|
try {
|
|
198
|
-
const profile
|
|
199
|
-
return profile.data
|
|
202
|
+
const profile = await this.request.get('/api/users/profile')
|
|
203
|
+
return profile.data
|
|
200
204
|
} catch (error) {
|
|
201
|
-
throw new Error(`Could not retrieve movements list ${error}`);
|
|
205
|
+
throw new Error(`Could not retrieve movements list ${error}`);
|
|
202
206
|
}
|
|
203
207
|
}
|
|
208
|
+
|
|
204
209
|
/**
|
|
205
210
|
* Obtain current Tropipay conversion rate. For example USD to EUR
|
|
206
211
|
* targetCurrency must be 'EUR'
|
|
@@ -209,28 +214,56 @@ export class Tropipay {
|
|
|
209
214
|
* @returns Conversion rate (number)
|
|
210
215
|
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/85163f6f28b23-get-rate
|
|
211
216
|
*/
|
|
212
|
-
async rates(originCurrency: string
|
|
213
|
-
if (!
|
|
217
|
+
async rates(originCurrency: string, targetCurrency: string = 'EUR'): Promise<number | Error> {
|
|
218
|
+
if (!Tropipay.accessToken) {
|
|
214
219
|
await this.login()
|
|
215
220
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
221
|
+
try {
|
|
222
|
+
const rates = await this.request.post('/api/v2/movements/get_rate',
|
|
223
|
+
{
|
|
224
|
+
currencyFrom: originCurrency,
|
|
225
|
+
currencyTo: targetCurrency
|
|
226
|
+
}, {
|
|
227
|
+
headers: {
|
|
228
|
+
'Content-Type': 'application/json',
|
|
229
|
+
Accept: 'application/json',
|
|
230
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
231
|
+
|
|
232
|
+
}
|
|
233
|
+
})
|
|
234
|
+
return rates.data.rate
|
|
235
|
+
} catch (error) {
|
|
236
|
+
throw new Error(`Could not retrieve rates ${error}`);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* (ONLY in Bussiness Accounts)
|
|
243
|
+
* An escrow payment link. This allows a payment to be made to persons
|
|
244
|
+
* belonging or not to the TropiPay platform with the particularity
|
|
245
|
+
* that the payment will be held in custody or retained until it is
|
|
246
|
+
* released with the approval of the payer.
|
|
247
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/12a128ff971e4-creating-a-mediation-payment-card
|
|
248
|
+
* @param config Payload with the payment details
|
|
249
|
+
*/
|
|
250
|
+
async createMediationPaymentCard(config: mediationPaymentCardConfig): Promise<PaymentLink> {
|
|
251
|
+
if (!Tropipay.accessToken) await this.login();
|
|
252
|
+
try {
|
|
253
|
+
const mediation = await this.request.post('/api/v2/paymentcards/mediation', config, {
|
|
254
|
+
headers: {
|
|
255
|
+
'Content-Type': 'application/json',
|
|
256
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
257
|
+
Accept: 'application/json'
|
|
258
|
+
}
|
|
259
|
+
})
|
|
260
|
+
return mediation.data as PaymentLink;
|
|
261
|
+
} catch (error) {
|
|
262
|
+
throw new Error(`Could not generate mediation paymentCard ${error}`);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
|
|
231
266
|
}
|
|
232
|
-
|
|
233
|
-
}
|
|
234
267
|
|
|
235
268
|
}
|
|
236
269
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
export interface mediationPaymentCardConfig {
|
|
6
|
+
amount: number //5000,
|
|
7
|
+
currency: "EUR" | "USD",
|
|
8
|
+
concept: string //Celular,
|
|
9
|
+
description: string,
|
|
10
|
+
reference: string, //458424548,
|
|
11
|
+
singleUse: boolean,
|
|
12
|
+
lang: string// es,
|
|
13
|
+
productUrl?: string,
|
|
14
|
+
buyer: null | any //null,
|
|
15
|
+
seller: {
|
|
16
|
+
sellerId?: number,
|
|
17
|
+
type?: number,
|
|
18
|
+
email?: string
|
|
19
|
+
},
|
|
20
|
+
feePercent?: number,//in cents
|
|
21
|
+
feeFixed?: number,
|
|
22
|
+
sendMail: boolean
|
|
23
|
+
}
|
package/docs/README.MD
DELETED