@yosle/tropipayjs 0.1.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/README.md +28 -0
- package/globals.d.ts +74 -0
- package/index.d.ts +59 -0
- package/index.js +211 -0
- package/index.ts +214 -0
- package/interfaces/countries/index.js +1 -0
- package/interfaces/countries/index.ts +0 -0
- package/interfaces/index.js +1 -0
- package/interfaces/index.ts +0 -0
- package/interfaces/paymentlink/index.d.ts +36 -0
- package/interfaces/paymentlink/index.js +2 -0
- package/interfaces/paymentlink/index.ts +40 -0
- package/interfaces/paymentlink.js +1 -0
- package/package.json +27 -0
- package/tsconfig.json +103 -0
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
TropipayJS - A typed SDK for Tropipay Payments API
|
|
2
|
+
===========
|
|
3
|
+
|
|
4
|
+
TropiPay is an electronic wallet that allows you to execute the most common financial operations of the day to day. This is a SDK for Typescript and Javacript that helps you build integrations with the Tropipay platform in a easier way. Can save you a lot of time and effort implementing all the API features. You can use this library with your prefered framework like Express or Nextjs.
|
|
5
|
+
|
|
6
|
+
# Instalation
|
|
7
|
+
You can use npm or yarn to install this package:
|
|
8
|
+
|
|
9
|
+
`npm install tropipayjs` or
|
|
10
|
+
`yarn add tropipayjs`
|
|
11
|
+
|
|
12
|
+
# How to use
|
|
13
|
+
The Tropipay instance allows you to access all the method available in the API. This Object is meant to be used *only* in server side code. Do not use the Tropipay object on the client side (browser). This would expose your app credetials (the client secret of your account). You can create a endpoint at your backend using express and consume it in your frontend, or use SSR if your're using NextJS.
|
|
14
|
+
|
|
15
|
+
## Setting up your credentials
|
|
16
|
+
In order to use the Tropipay API you need to signup in a live (production) or the test enviroment. Create an app and configure the client id an client secret for the app.
|
|
17
|
+
|
|
18
|
+
# Examples
|
|
19
|
+
|
|
20
|
+
# Using Typescript
|
|
21
|
+
|
|
22
|
+
# Contributing and Help
|
|
23
|
+
Having problems? want to contribute? join our community slack.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
package/globals.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
type LoginResponse = {
|
|
2
|
+
access_token: string,
|
|
3
|
+
refresh_token: string
|
|
4
|
+
token_type: "Bearer",
|
|
5
|
+
expires_in: number,
|
|
6
|
+
scope: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type LoginError = {
|
|
10
|
+
error: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type Country = {
|
|
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
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type Deposit = {
|
|
32
|
+
id: number,
|
|
33
|
+
accountNumber: string,
|
|
34
|
+
alias: string,
|
|
35
|
+
swift: string,
|
|
36
|
+
type: number,
|
|
37
|
+
country: number | null,
|
|
38
|
+
firstName: string,
|
|
39
|
+
default: null,
|
|
40
|
+
state: number,
|
|
41
|
+
userId: string,
|
|
42
|
+
countryDestinationId: number,
|
|
43
|
+
lastName: string,
|
|
44
|
+
documentNumber: number,
|
|
45
|
+
userRelationTypeId: number,
|
|
46
|
+
city: string,
|
|
47
|
+
postalCode: string,
|
|
48
|
+
address: string,
|
|
49
|
+
phone: string,
|
|
50
|
+
checked: boolean,
|
|
51
|
+
province: string,
|
|
52
|
+
beneficiaryType: number,
|
|
53
|
+
relatedUserId: null | string,
|
|
54
|
+
currency: string,
|
|
55
|
+
correspondent?: any,
|
|
56
|
+
location: any,
|
|
57
|
+
office: any,
|
|
58
|
+
officeValue: any,
|
|
59
|
+
paymentType: number,
|
|
60
|
+
paymentEntityBeneficiaryId: number,
|
|
61
|
+
paymentEntityAccountId: number,
|
|
62
|
+
verified: any,
|
|
63
|
+
paymentEntityInfo: any,
|
|
64
|
+
documentTypeId: any,
|
|
65
|
+
documentExpirationDate: Date,
|
|
66
|
+
createdAt: Date<string>,
|
|
67
|
+
updatedAt: Date<string>,
|
|
68
|
+
countryDestination: Country
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
type AccountDeposits = {
|
|
72
|
+
count: number,
|
|
73
|
+
rows: Deposit[]
|
|
74
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tropipayjs is a wrapper for the Tropipay API. It was made in
|
|
3
|
+
* typescript but you can use Javascript.
|
|
4
|
+
* @author Yosleivy baez Acosta
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
import { Axios } from "axios";
|
|
8
|
+
import { PaymentLink, PaymentLinkPayload } from './interfaces/paymentlink';
|
|
9
|
+
declare type ServerMode = 'Development' | 'Production';
|
|
10
|
+
declare class Tropipay {
|
|
11
|
+
readonly client_id: string;
|
|
12
|
+
readonly client_secret: string;
|
|
13
|
+
request: Axios;
|
|
14
|
+
access_token: string | undefined;
|
|
15
|
+
refresh_token: string | undefined;
|
|
16
|
+
server_mode: ServerMode;
|
|
17
|
+
constructor(client_id: string, client_secret: string, server_mode?: ServerMode);
|
|
18
|
+
login(): Promise<LoginResponse>;
|
|
19
|
+
/**
|
|
20
|
+
* Create a paymentLink width the specifued payload
|
|
21
|
+
* @param payload Object of PaymentLinkPayload type with paylink payload
|
|
22
|
+
* @returns Promise<PaymentLink> or Error
|
|
23
|
+
* @see {https} ://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
24
|
+
*/
|
|
25
|
+
createPayLink(payload: PaymentLinkPayload): Promise<PaymentLink>;
|
|
26
|
+
/**
|
|
27
|
+
* Get all deposits in this account.
|
|
28
|
+
* @returns Promise of AccountDeposits Object or Error
|
|
29
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6OTgyOTQ1Mg-get-deposit-accounts-list
|
|
30
|
+
*/
|
|
31
|
+
getDepositAccounts(): Promise<AccountDeposits[] | Error>;
|
|
32
|
+
/**
|
|
33
|
+
* Get the list of all supported countries.
|
|
34
|
+
* @returns
|
|
35
|
+
* @see
|
|
36
|
+
*/
|
|
37
|
+
countries(): Promise<Country[] | Error>;
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @returns
|
|
41
|
+
* @see
|
|
42
|
+
*/
|
|
43
|
+
favorites(): Promise<any>;
|
|
44
|
+
/**
|
|
45
|
+
* List all movements in current account. You can optionaly specify
|
|
46
|
+
* offset and limit params for pagination.
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
movements(offset?: number, limit?: number): Promise<any>;
|
|
50
|
+
/**
|
|
51
|
+
* Return user profile
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
profile(): Promise<any>;
|
|
55
|
+
getRates(payload?: {
|
|
56
|
+
currencyFrom: string;
|
|
57
|
+
}): Promise<any>;
|
|
58
|
+
}
|
|
59
|
+
export default Tropipay;
|
package/index.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tropipayjs is a wrapper for the Tropipay API. It was made in
|
|
4
|
+
* typescript but you can use Javascript.
|
|
5
|
+
* @author Yosleivy baez Acosta
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
const axios_1 = __importDefault(require("axios"));
|
|
22
|
+
class Tropipay {
|
|
23
|
+
constructor(client_id, client_secret, server_mode = 'Development') {
|
|
24
|
+
this.client_id = client_id;
|
|
25
|
+
this.client_secret = client_secret;
|
|
26
|
+
this.server_mode = server_mode;
|
|
27
|
+
this.request = axios_1.default.create({
|
|
28
|
+
baseURL: this.server_mode === 'Production'
|
|
29
|
+
? 'https://www.tropipay.com'
|
|
30
|
+
: 'https://tropipay-dev.herokuapp.com',
|
|
31
|
+
headers: {
|
|
32
|
+
'Content-Type': 'application/json',
|
|
33
|
+
Accept: 'application/json',
|
|
34
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
login() {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
try {
|
|
41
|
+
const { data } = yield this.request.post('/api/v2/access/token', {
|
|
42
|
+
client_id: this.client_id,
|
|
43
|
+
client_secret: this.client_secret,
|
|
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
|
+
this.access_token = data.access_token;
|
|
53
|
+
this.refresh_token = data.refresh_token;
|
|
54
|
+
return data;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
58
|
+
// 👇️ error: AxiosError<any, any>
|
|
59
|
+
throw new Error("Conection error: " + error.message);
|
|
60
|
+
}
|
|
61
|
+
throw new Error("Could not obtain the access token from credentials ");
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create a paymentLink width the specifued payload
|
|
67
|
+
* @param payload Object of PaymentLinkPayload type with paylink payload
|
|
68
|
+
* @returns Promise<PaymentLink> or Error
|
|
69
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
70
|
+
*/
|
|
71
|
+
createPayLink(payload) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
if (!this.access_token) {
|
|
74
|
+
yield this.login();
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
const paylink = yield this.request.post('/api/v2/paymentcards', payload, {
|
|
78
|
+
headers: {
|
|
79
|
+
// 'Content-Type': 'application/json',
|
|
80
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
81
|
+
// Accept: 'application/json'
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return paylink.data;
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
throw new Error(`Error tryng to get the access token`);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get all deposits in this account.
|
|
93
|
+
* @returns A Promise of an Array of AccountDeposits or throws an Exception
|
|
94
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6OTgyOTQ1Mg-get-deposit-accounts-list
|
|
95
|
+
*/
|
|
96
|
+
getDepositAccounts() {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
if (!this.access_token) {
|
|
99
|
+
yield this.login();
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const deposits = yield this.request.get('/api/v2/deposit_accounts', {});
|
|
103
|
+
return deposits.data;
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
throw new Error(`Could not retrieve the account deposits ${error}`);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get the list of all supported countries by Tropipay.
|
|
112
|
+
* @returns Array of Countries
|
|
113
|
+
* @see
|
|
114
|
+
*/
|
|
115
|
+
countries() {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
if (!this.access_token) {
|
|
118
|
+
yield this.login();
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
const countries = yield this.request.get('/api/countries');
|
|
122
|
+
return countries.data;
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
throw new Error(`Could not retrieve the countries list`);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get list of all the favorites accounts.
|
|
131
|
+
* @returns
|
|
132
|
+
* @see
|
|
133
|
+
*/
|
|
134
|
+
favorites() {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
if (!this.access_token) {
|
|
137
|
+
yield this.login();
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
const favorites = yield this.request.get('/api/v2/paymentcards/favorites');
|
|
141
|
+
return favorites.data;
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
throw new Error(`Could not retrieve favorites list`);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* List all movements in current account. You can optionaly specify
|
|
150
|
+
* offset and limit params for pagination.
|
|
151
|
+
* @returns
|
|
152
|
+
*/
|
|
153
|
+
movements(offset = 0, limit = 10) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
if (!this.access_token) {
|
|
156
|
+
yield this.login();
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
const movements = yield this.request.get('/api/v2/movements', { params: { limit: limit, offset: offset },
|
|
160
|
+
headers: {
|
|
161
|
+
'Content-Type': 'application/json',
|
|
162
|
+
Accept: 'application/json',
|
|
163
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
164
|
+
} });
|
|
165
|
+
return movements.data;
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
throw new Error(`Could not retrieve movements list`);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Return profile data for this account.
|
|
174
|
+
* @returns
|
|
175
|
+
*/
|
|
176
|
+
profile() {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
if (!this.access_token) {
|
|
179
|
+
yield this.login();
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
const profile = yield this.request.get('/api/users/profile');
|
|
183
|
+
return profile.data;
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
throw new Error(`Could not retrieve movements list ${error}`);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
getRates(payload = { currencyFrom: "EUR" }) {
|
|
191
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
console.log(payload);
|
|
193
|
+
if (!this.access_token) {
|
|
194
|
+
yield this.login();
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
const rates = yield this.request.post('/api/v2/movements/get_rate', { payload,
|
|
198
|
+
headers: {
|
|
199
|
+
'Content-Type': 'application/json',
|
|
200
|
+
Accept: 'application/json',
|
|
201
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
202
|
+
} });
|
|
203
|
+
return rates.data;
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
throw new Error(`Could not retrieve rates ${error}`);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
exports.default = Tropipay;
|
package/index.ts
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tropipayjs is a wrapper for the Tropipay API. It was made in
|
|
3
|
+
* typescript but you can use Javascript.
|
|
4
|
+
* @author Yosleivy baez Acosta
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import axios, { Axios } from "axios";
|
|
9
|
+
import { PaymentLink, PaymentLinkPayload } from './interfaces/paymentlink'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
type ServerMode = 'Development' | 'Production'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Tropipay {
|
|
16
|
+
readonly client_id: string;
|
|
17
|
+
readonly client_secret: string;
|
|
18
|
+
public request: Axios;
|
|
19
|
+
public access_token: string | undefined;
|
|
20
|
+
public refresh_token: string | undefined;
|
|
21
|
+
public server_mode: ServerMode;
|
|
22
|
+
|
|
23
|
+
constructor(
|
|
24
|
+
client_id: string,
|
|
25
|
+
client_secret: string,
|
|
26
|
+
server_mode: ServerMode = 'Development') {
|
|
27
|
+
this.client_id = client_id;
|
|
28
|
+
this.client_secret = client_secret
|
|
29
|
+
this.server_mode = server_mode
|
|
30
|
+
|
|
31
|
+
this.request = axios.create({
|
|
32
|
+
baseURL: this.server_mode === 'Production'
|
|
33
|
+
? 'https://www.tropipay.com'
|
|
34
|
+
: 'https://tropipay-dev.herokuapp.com',
|
|
35
|
+
headers: {
|
|
36
|
+
'Content-Type': 'application/json',
|
|
37
|
+
Accept: 'application/json',
|
|
38
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
async login() {
|
|
46
|
+
try {
|
|
47
|
+
const { data } = await this.request.post<LoginResponse>('/api/v2/access/token', {
|
|
48
|
+
client_id: this.client_id,
|
|
49
|
+
client_secret: this.client_secret,
|
|
50
|
+
grant_type: "client_credentials",
|
|
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
|
+
}, {
|
|
53
|
+
// headers: {
|
|
54
|
+
// 'Content-Type': 'application/json',
|
|
55
|
+
// Accept: 'application/json',
|
|
56
|
+
// }
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
this.access_token = data.access_token
|
|
60
|
+
this.refresh_token = data.refresh_token
|
|
61
|
+
return data
|
|
62
|
+
} catch (error) {
|
|
63
|
+
if (axios.isAxiosError(error)) {
|
|
64
|
+
// 👇️ error: AxiosError<any, any>
|
|
65
|
+
throw new Error("Conection error: " + error.message);
|
|
66
|
+
}
|
|
67
|
+
throw new Error("Could not obtain the access token from credentials ");
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Create a paymentLink width the specifued payload
|
|
74
|
+
* @param payload Object of PaymentLinkPayload type with paylink payload
|
|
75
|
+
* @returns Promise<PaymentLink> or Error
|
|
76
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
77
|
+
*/
|
|
78
|
+
async createPayLink(payload: PaymentLinkPayload): Promise<PaymentLink> {
|
|
79
|
+
if (!this.access_token) {
|
|
80
|
+
await this.login()
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
const paylink = await this.request.post('/api/v2/paymentcards', payload, {
|
|
84
|
+
headers: {
|
|
85
|
+
// 'Content-Type': 'application/json',
|
|
86
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
87
|
+
// Accept: 'application/json'
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
return paylink.data as PaymentLink
|
|
91
|
+
} catch (error) {
|
|
92
|
+
throw new Error(`Error tryng to get the access token`);
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
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
|
+
async getDepositAccounts(): Promise<AccountDeposits[] | Error>{
|
|
103
|
+
if (!this.access_token) {
|
|
104
|
+
await this.login()
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
const deposits = await this.request.get('/api/v2/deposit_accounts',{ })
|
|
108
|
+
return deposits.data
|
|
109
|
+
} catch (error) {
|
|
110
|
+
throw new Error(`Could not retrieve the account deposits ${error}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Get the list of all supported countries by Tropipay.
|
|
116
|
+
* @returns Array of Countries
|
|
117
|
+
* @see
|
|
118
|
+
*/
|
|
119
|
+
async countries(): Promise<Country[] | Error>{
|
|
120
|
+
if (!this.access_token) {
|
|
121
|
+
await this.login()
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
const countries = await this.request.get('/api/countries')
|
|
125
|
+
return countries.data
|
|
126
|
+
} catch (error) {
|
|
127
|
+
throw new Error(`Could not retrieve the countries list`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Get list of all the favorites accounts.
|
|
133
|
+
* @returns
|
|
134
|
+
* @see
|
|
135
|
+
*/
|
|
136
|
+
async favorites(){
|
|
137
|
+
if (!this.access_token) {
|
|
138
|
+
await this.login()
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
const favorites = await this.request.get('/api/v2/paymentcards/favorites')
|
|
142
|
+
return favorites.data
|
|
143
|
+
} catch (error) {
|
|
144
|
+
throw new Error(`Could not retrieve favorites list`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* List all movements in current account. You can optionaly specify
|
|
150
|
+
* offset and limit params for pagination.
|
|
151
|
+
* @returns
|
|
152
|
+
*/
|
|
153
|
+
async movements(offset = 0 , limit = 10){
|
|
154
|
+
if (!this.access_token) {
|
|
155
|
+
await this.login()
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
const movements = await this.request.get('/api/v2/movements',
|
|
159
|
+
{params: {limit: limit, offset: offset},
|
|
160
|
+
headers: {
|
|
161
|
+
'Content-Type': 'application/json',
|
|
162
|
+
Accept: 'application/json',
|
|
163
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
164
|
+
|
|
165
|
+
} })
|
|
166
|
+
return movements.data
|
|
167
|
+
} catch (error) {
|
|
168
|
+
throw new Error(`Could not retrieve movements list`);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Return profile data for this account.
|
|
175
|
+
* @returns
|
|
176
|
+
*/
|
|
177
|
+
async profile(){
|
|
178
|
+
if (!this.access_token) {
|
|
179
|
+
await this.login()
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
const profile = await this.request.get('/api/users/profile')
|
|
183
|
+
return profile.data
|
|
184
|
+
} catch (error) {
|
|
185
|
+
throw new Error(`Could not retrieve movements list ${error}`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async getRates(payload = {currencyFrom: "EUR"}) {
|
|
190
|
+
console.log(payload)
|
|
191
|
+
if (!this.access_token) {
|
|
192
|
+
await this.login()
|
|
193
|
+
}
|
|
194
|
+
try {
|
|
195
|
+
const rates = await this.request.post('/api/v2/movements/get_rate',{payload,
|
|
196
|
+
headers: {
|
|
197
|
+
'Content-Type': 'application/json',
|
|
198
|
+
Accept: 'application/json',
|
|
199
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
200
|
+
|
|
201
|
+
} })
|
|
202
|
+
return rates.data
|
|
203
|
+
} catch (error) {
|
|
204
|
+
throw new Error(`Could not retrieve rates ${error}`);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
export default Tropipay
|
|
213
|
+
|
|
214
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
File without changes
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
|
|
2
|
+
export interface PaymentLinkPayload {
|
|
3
|
+
reference: string,
|
|
4
|
+
concept: string,
|
|
5
|
+
favorite: boolean,
|
|
6
|
+
amount: number,
|
|
7
|
+
currency: string,
|
|
8
|
+
description : string,
|
|
9
|
+
singleUse: boolean,
|
|
10
|
+
reasonId: number,
|
|
11
|
+
expirationDays: number,
|
|
12
|
+
lang:string,
|
|
13
|
+
urlSuccess: string,
|
|
14
|
+
urlFailed: string,
|
|
15
|
+
urlNotification: string,
|
|
16
|
+
serviceDate: string,
|
|
17
|
+
client: {
|
|
18
|
+
name: string,
|
|
19
|
+
lastName: string,
|
|
20
|
+
address: string,
|
|
21
|
+
phone: string,
|
|
22
|
+
email:string,
|
|
23
|
+
countryId: number,
|
|
24
|
+
termsAndConditions: boolean
|
|
25
|
+
},
|
|
26
|
+
directPayment: boolean
|
|
27
|
+
paymentMethods?:string[]
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface PaymentLink extends PaymentLinkPayload {
|
|
32
|
+
expirationDate: string,
|
|
33
|
+
hasClient:boolean,
|
|
34
|
+
updatedAt:string,
|
|
35
|
+
createdAt: string,
|
|
36
|
+
qrImage: string,
|
|
37
|
+
shortUrl: string,
|
|
38
|
+
paymentUrl: string
|
|
39
|
+
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yosle/tropipayjs",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": " Javascript / Typescript SDK for Tropipay API",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"build": "tsc"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/yosle/tropipayjs"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"Javascript",
|
|
16
|
+
"Typescript",
|
|
17
|
+
"Tropipay",
|
|
18
|
+
"payments",
|
|
19
|
+
"gateway",
|
|
20
|
+
"API"
|
|
21
|
+
],
|
|
22
|
+
"author": "Yosleivy Baez Acosta <yosle007@gmail.com>",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"axios": "^0.27.2"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
4
|
+
|
|
5
|
+
/* Projects */
|
|
6
|
+
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
7
|
+
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
8
|
+
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
9
|
+
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
10
|
+
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
11
|
+
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
|
+
|
|
13
|
+
/* Language and Environment */
|
|
14
|
+
"target": "es2015", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
15
|
+
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
16
|
+
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
17
|
+
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
|
|
18
|
+
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
19
|
+
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
20
|
+
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
21
|
+
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
22
|
+
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
23
|
+
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
24
|
+
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
25
|
+
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
26
|
+
|
|
27
|
+
/* Modules */
|
|
28
|
+
"module": "commonjs", /* Specify what module code is generated. */
|
|
29
|
+
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
30
|
+
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
31
|
+
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
32
|
+
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
33
|
+
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
34
|
+
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
35
|
+
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
36
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
37
|
+
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
38
|
+
// "resolveJsonModule": true, /* Enable importing .json files. */
|
|
39
|
+
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
40
|
+
|
|
41
|
+
/* JavaScript Support */
|
|
42
|
+
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
43
|
+
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
44
|
+
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
45
|
+
|
|
46
|
+
/* Emit */
|
|
47
|
+
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
48
|
+
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
49
|
+
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
50
|
+
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
51
|
+
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
52
|
+
// "outDir": "./", /* Specify an output folder for all emitted files. */
|
|
53
|
+
// "removeComments": true, /* Disable emitting comments. */
|
|
54
|
+
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
55
|
+
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
56
|
+
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
|
57
|
+
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
58
|
+
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
59
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
60
|
+
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
61
|
+
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
62
|
+
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
63
|
+
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
64
|
+
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
65
|
+
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
66
|
+
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
67
|
+
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
68
|
+
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
69
|
+
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
|
70
|
+
|
|
71
|
+
/* Interop Constraints */
|
|
72
|
+
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
73
|
+
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
74
|
+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
|
75
|
+
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
76
|
+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
77
|
+
|
|
78
|
+
/* Type Checking */
|
|
79
|
+
"strict": true, /* Enable all strict type-checking options. */
|
|
80
|
+
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
81
|
+
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
82
|
+
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
83
|
+
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
84
|
+
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
85
|
+
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
86
|
+
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
87
|
+
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
88
|
+
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
89
|
+
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
90
|
+
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
91
|
+
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
92
|
+
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
93
|
+
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
94
|
+
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
95
|
+
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
96
|
+
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
97
|
+
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
98
|
+
|
|
99
|
+
/* Completeness */
|
|
100
|
+
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
101
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
102
|
+
}
|
|
103
|
+
}
|