@yosle/tropipayjs 0.1.2 → 0.1.4
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/dist/index.d.ts +59 -0
- package/dist/index.js +187 -0
- package/dist/interfaces/countries/index.d.ts +0 -0
- package/dist/interfaces/countries/index.js +2 -0
- package/dist/interfaces/index.d.ts +0 -0
- package/dist/interfaces/index.js +2 -0
- package/dist/interfaces/paymentlink/index.d.ts +36 -0
- package/dist/interfaces/paymentlink/index.js +2 -0
- package/index.d.ts +48 -9
- package/index.js +138 -151
- package/index.ts +1 -2
- package/interfaces/countries/index.d.ts +0 -0
- package/interfaces/countries/index.js +1 -0
- package/interfaces/index.d.ts +0 -0
- package/interfaces/index.js +1 -0
- package/interfaces/paymentlink/index.js +1 -0
- package/package.json +15 -4
- package/rollup.config.js +23 -0
- package/tsconfig.json +13 -21
package/dist/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
|
+
export 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 A Promise of an Array of AccountDeposits or throws an Exception
|
|
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 by Tropipay.
|
|
34
|
+
* @returns Array of Countries
|
|
35
|
+
* @see
|
|
36
|
+
*/
|
|
37
|
+
countries(): Promise<Country[] | Error>;
|
|
38
|
+
/**
|
|
39
|
+
* Get list of all the favorites accounts.
|
|
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 profile data for this account.
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
profile(): Promise<any>;
|
|
55
|
+
getRates(payload?: {
|
|
56
|
+
currencyFrom: string;
|
|
57
|
+
}): Promise<any>;
|
|
58
|
+
}
|
|
59
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
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
|
+
export class Tropipay {
|
|
9
|
+
client_id;
|
|
10
|
+
client_secret;
|
|
11
|
+
request;
|
|
12
|
+
access_token;
|
|
13
|
+
refresh_token;
|
|
14
|
+
server_mode;
|
|
15
|
+
constructor(client_id, client_secret, server_mode = 'Development') {
|
|
16
|
+
this.client_id = client_id;
|
|
17
|
+
this.client_secret = client_secret;
|
|
18
|
+
this.server_mode = server_mode;
|
|
19
|
+
this.request = axios.create({
|
|
20
|
+
baseURL: this.server_mode === 'Production'
|
|
21
|
+
? 'https://www.tropipay.com'
|
|
22
|
+
: 'https://tropipay-dev.herokuapp.com',
|
|
23
|
+
headers: {
|
|
24
|
+
'Content-Type': 'application/json',
|
|
25
|
+
Accept: 'application/json',
|
|
26
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async login() {
|
|
31
|
+
try {
|
|
32
|
+
const { data } = await this.request.post('/api/v2/access/token', {
|
|
33
|
+
client_id: this.client_id,
|
|
34
|
+
client_secret: this.client_secret,
|
|
35
|
+
grant_type: "client_credentials",
|
|
36
|
+
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 "
|
|
37
|
+
}, {
|
|
38
|
+
// headers: {
|
|
39
|
+
// 'Content-Type': 'application/json',
|
|
40
|
+
// Accept: 'application/json',
|
|
41
|
+
// }
|
|
42
|
+
});
|
|
43
|
+
this.access_token = data.access_token;
|
|
44
|
+
this.refresh_token = data.refresh_token;
|
|
45
|
+
return data;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (axios.isAxiosError(error)) {
|
|
49
|
+
// 👇️ error: AxiosError<any, any>
|
|
50
|
+
throw new Error("Conection error: " + error.message);
|
|
51
|
+
}
|
|
52
|
+
throw new Error("Could not obtain the access token from credentials ");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Create a paymentLink width the specifued payload
|
|
57
|
+
* @param payload Object of PaymentLinkPayload type with paylink payload
|
|
58
|
+
* @returns Promise<PaymentLink> or Error
|
|
59
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
60
|
+
*/
|
|
61
|
+
async createPayLink(payload) {
|
|
62
|
+
if (!this.access_token) {
|
|
63
|
+
await this.login();
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const paylink = await this.request.post('/api/v2/paymentcards', payload, {
|
|
67
|
+
headers: {
|
|
68
|
+
// 'Content-Type': 'application/json',
|
|
69
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
70
|
+
// Accept: 'application/json'
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return paylink.data;
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
throw new Error(`Error tryng to get the access token`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get all deposits in this account.
|
|
81
|
+
* @returns A Promise of an Array of AccountDeposits or throws an Exception
|
|
82
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6OTgyOTQ1Mg-get-deposit-accounts-list
|
|
83
|
+
*/
|
|
84
|
+
async getDepositAccounts() {
|
|
85
|
+
if (!this.access_token) {
|
|
86
|
+
await this.login();
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
const deposits = await this.request.get('/api/v2/deposit_accounts', {});
|
|
90
|
+
return deposits.data;
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
throw new Error(`Could not retrieve the account deposits ${error}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get the list of all supported countries by Tropipay.
|
|
98
|
+
* @returns Array of Countries
|
|
99
|
+
* @see
|
|
100
|
+
*/
|
|
101
|
+
async countries() {
|
|
102
|
+
if (!this.access_token) {
|
|
103
|
+
await this.login();
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const countries = await this.request.get('/api/countries');
|
|
107
|
+
return countries.data;
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
throw new Error(`Could not retrieve the countries list`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Get list of all the favorites accounts.
|
|
115
|
+
* @returns
|
|
116
|
+
* @see
|
|
117
|
+
*/
|
|
118
|
+
async favorites() {
|
|
119
|
+
if (!this.access_token) {
|
|
120
|
+
await this.login();
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
const favorites = await this.request.get('/api/v2/paymentcards/favorites');
|
|
124
|
+
return favorites.data;
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
throw new Error(`Could not retrieve favorites list`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* List all movements in current account. You can optionaly specify
|
|
132
|
+
* offset and limit params for pagination.
|
|
133
|
+
* @returns
|
|
134
|
+
*/
|
|
135
|
+
async movements(offset = 0, limit = 10) {
|
|
136
|
+
if (!this.access_token) {
|
|
137
|
+
await this.login();
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
const movements = await this.request.get('/api/v2/movements', { params: { limit: limit, offset: offset },
|
|
141
|
+
headers: {
|
|
142
|
+
'Content-Type': 'application/json',
|
|
143
|
+
Accept: 'application/json',
|
|
144
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
145
|
+
} });
|
|
146
|
+
return movements.data;
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
throw new Error(`Could not retrieve movements list`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Return profile data for this account.
|
|
154
|
+
* @returns
|
|
155
|
+
*/
|
|
156
|
+
async profile() {
|
|
157
|
+
if (!this.access_token) {
|
|
158
|
+
await this.login();
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
const profile = await this.request.get('/api/users/profile');
|
|
162
|
+
return profile.data;
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
throw new Error(`Could not retrieve movements list ${error}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async getRates(payload = { currencyFrom: "EUR" }) {
|
|
169
|
+
console.log(payload);
|
|
170
|
+
if (!this.access_token) {
|
|
171
|
+
await this.login();
|
|
172
|
+
}
|
|
173
|
+
try {
|
|
174
|
+
const rates = await this.request.post('/api/v2/movements/get_rate', { payload,
|
|
175
|
+
headers: {
|
|
176
|
+
'Content-Type': 'application/json',
|
|
177
|
+
Accept: 'application/json',
|
|
178
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
179
|
+
} });
|
|
180
|
+
return rates.data;
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
throw new Error(`Could not retrieve rates ${error}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=index.js.map
|
|
File without changes
|
|
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
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -1,11 +1,49 @@
|
|
|
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
|
+
|
|
1
40
|
/**
|
|
2
41
|
* Tropipayjs is a wrapper for the Tropipay API. It was made in
|
|
3
42
|
* typescript but you can use Javascript.
|
|
4
43
|
* @author Yosleivy baez Acosta
|
|
5
44
|
*
|
|
6
45
|
*/
|
|
7
|
-
|
|
8
|
-
import { PaymentLink, PaymentLinkPayload } from './interfaces/paymentlink';
|
|
46
|
+
|
|
9
47
|
declare type ServerMode = 'Development' | 'Production';
|
|
10
48
|
declare class Tropipay {
|
|
11
49
|
readonly client_id: string;
|
|
@@ -20,23 +58,23 @@ declare class Tropipay {
|
|
|
20
58
|
* Create a paymentLink width the specifued payload
|
|
21
59
|
* @param payload Object of PaymentLinkPayload type with paylink payload
|
|
22
60
|
* @returns Promise<PaymentLink> or Error
|
|
23
|
-
* @see
|
|
61
|
+
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
24
62
|
*/
|
|
25
63
|
createPayLink(payload: PaymentLinkPayload): Promise<PaymentLink>;
|
|
26
64
|
/**
|
|
27
65
|
* Get all deposits in this account.
|
|
28
|
-
* @returns
|
|
66
|
+
* @returns A Promise of an Array of AccountDeposits or throws an Exception
|
|
29
67
|
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6OTgyOTQ1Mg-get-deposit-accounts-list
|
|
30
68
|
*/
|
|
31
69
|
getDepositAccounts(): Promise<AccountDeposits[] | Error>;
|
|
32
70
|
/**
|
|
33
|
-
* Get the list of all supported countries.
|
|
34
|
-
* @returns
|
|
71
|
+
* Get the list of all supported countries by Tropipay.
|
|
72
|
+
* @returns Array of Countries
|
|
35
73
|
* @see
|
|
36
74
|
*/
|
|
37
75
|
countries(): Promise<Country[] | Error>;
|
|
38
76
|
/**
|
|
39
|
-
*
|
|
77
|
+
* Get list of all the favorites accounts.
|
|
40
78
|
* @returns
|
|
41
79
|
* @see
|
|
42
80
|
*/
|
|
@@ -48,7 +86,7 @@ declare class Tropipay {
|
|
|
48
86
|
*/
|
|
49
87
|
movements(offset?: number, limit?: number): Promise<any>;
|
|
50
88
|
/**
|
|
51
|
-
* Return
|
|
89
|
+
* Return profile data for this account.
|
|
52
90
|
* @returns
|
|
53
91
|
*/
|
|
54
92
|
profile(): Promise<any>;
|
|
@@ -56,4 +94,5 @@ declare class Tropipay {
|
|
|
56
94
|
currencyFrom: string;
|
|
57
95
|
}): Promise<any>;
|
|
58
96
|
}
|
|
59
|
-
|
|
97
|
+
|
|
98
|
+
export { Tropipay };
|
package/index.js
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
|
-
|
|
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
|
+
|
|
2
11
|
/**
|
|
3
12
|
* Tropipayjs is a wrapper for the Tropipay API. It was made in
|
|
4
13
|
* typescript but you can use Javascript.
|
|
5
14
|
* @author Yosleivy baez Acosta
|
|
6
15
|
*
|
|
7
16
|
*/
|
|
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
17
|
class Tropipay {
|
|
18
|
+
client_id;
|
|
19
|
+
client_secret;
|
|
20
|
+
request;
|
|
21
|
+
access_token;
|
|
22
|
+
refresh_token;
|
|
23
|
+
server_mode;
|
|
23
24
|
constructor(client_id, client_secret, server_mode = 'Development') {
|
|
24
25
|
this.client_id = client_id;
|
|
25
26
|
this.client_secret = client_secret;
|
|
26
27
|
this.server_mode = server_mode;
|
|
27
|
-
this.request =
|
|
28
|
+
this.request = axios__default["default"].create({
|
|
28
29
|
baseURL: this.server_mode === 'Production'
|
|
29
30
|
? 'https://www.tropipay.com'
|
|
30
31
|
: 'https://tropipay-dev.herokuapp.com',
|
|
@@ -35,32 +36,30 @@ class Tropipay {
|
|
|
35
36
|
}
|
|
36
37
|
});
|
|
37
38
|
}
|
|
38
|
-
login() {
|
|
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
|
-
});
|
|
39
|
+
async login() {
|
|
40
|
+
try {
|
|
41
|
+
const { data } = await 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__default["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
|
+
}
|
|
64
63
|
}
|
|
65
64
|
/**
|
|
66
65
|
* Create a paymentLink width the specifued payload
|
|
@@ -68,144 +67,132 @@ class Tropipay {
|
|
|
68
67
|
* @returns Promise<PaymentLink> or Error
|
|
69
68
|
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
|
|
70
69
|
*/
|
|
71
|
-
createPayLink(payload) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
});
|
|
70
|
+
async createPayLink(payload) {
|
|
71
|
+
if (!this.access_token) {
|
|
72
|
+
await this.login();
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const paylink = await this.request.post('/api/v2/paymentcards', payload, {
|
|
76
|
+
headers: {
|
|
77
|
+
// 'Content-Type': 'application/json',
|
|
78
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
79
|
+
// Accept: 'application/json'
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
return paylink.data;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
throw new Error(`Error tryng to get the access token`);
|
|
86
|
+
}
|
|
90
87
|
}
|
|
91
88
|
/**
|
|
92
89
|
* Get all deposits in this account.
|
|
93
90
|
* @returns A Promise of an Array of AccountDeposits or throws an Exception
|
|
94
91
|
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6OTgyOTQ1Mg-get-deposit-accounts-list
|
|
95
92
|
*/
|
|
96
|
-
getDepositAccounts() {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
});
|
|
93
|
+
async getDepositAccounts() {
|
|
94
|
+
if (!this.access_token) {
|
|
95
|
+
await this.login();
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const deposits = await this.request.get('/api/v2/deposit_accounts', {});
|
|
99
|
+
return deposits.data;
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
throw new Error(`Could not retrieve the account deposits ${error}`);
|
|
103
|
+
}
|
|
109
104
|
}
|
|
110
105
|
/**
|
|
111
106
|
* Get the list of all supported countries by Tropipay.
|
|
112
107
|
* @returns Array of Countries
|
|
113
108
|
* @see
|
|
114
109
|
*/
|
|
115
|
-
countries() {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
});
|
|
110
|
+
async countries() {
|
|
111
|
+
if (!this.access_token) {
|
|
112
|
+
await this.login();
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
const countries = await this.request.get('/api/countries');
|
|
116
|
+
return countries.data;
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
throw new Error(`Could not retrieve the countries list`);
|
|
120
|
+
}
|
|
128
121
|
}
|
|
129
122
|
/**
|
|
130
123
|
* Get list of all the favorites accounts.
|
|
131
124
|
* @returns
|
|
132
125
|
* @see
|
|
133
126
|
*/
|
|
134
|
-
favorites() {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
});
|
|
127
|
+
async favorites() {
|
|
128
|
+
if (!this.access_token) {
|
|
129
|
+
await this.login();
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
const favorites = await this.request.get('/api/v2/paymentcards/favorites');
|
|
133
|
+
return favorites.data;
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
throw new Error(`Could not retrieve favorites list`);
|
|
137
|
+
}
|
|
147
138
|
}
|
|
148
139
|
/**
|
|
149
140
|
* List all movements in current account. You can optionaly specify
|
|
150
141
|
* offset and limit params for pagination.
|
|
151
142
|
* @returns
|
|
152
143
|
*/
|
|
153
|
-
movements(offset = 0, limit = 10) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
});
|
|
144
|
+
async movements(offset = 0, limit = 10) {
|
|
145
|
+
if (!this.access_token) {
|
|
146
|
+
await this.login();
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
const movements = await this.request.get('/api/v2/movements', { params: { limit: limit, offset: offset },
|
|
150
|
+
headers: {
|
|
151
|
+
'Content-Type': 'application/json',
|
|
152
|
+
Accept: 'application/json',
|
|
153
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
154
|
+
} });
|
|
155
|
+
return movements.data;
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
throw new Error(`Could not retrieve movements list`);
|
|
159
|
+
}
|
|
171
160
|
}
|
|
172
161
|
/**
|
|
173
162
|
* Return profile data for this account.
|
|
174
163
|
* @returns
|
|
175
164
|
*/
|
|
176
|
-
profile() {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
});
|
|
165
|
+
async profile() {
|
|
166
|
+
if (!this.access_token) {
|
|
167
|
+
await this.login();
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
const profile = await this.request.get('/api/users/profile');
|
|
171
|
+
return profile.data;
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
throw new Error(`Could not retrieve movements list ${error}`);
|
|
175
|
+
}
|
|
189
176
|
}
|
|
190
|
-
getRates(payload = { currencyFrom: "EUR" }) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
});
|
|
177
|
+
async getRates(payload = { currencyFrom: "EUR" }) {
|
|
178
|
+
console.log(payload);
|
|
179
|
+
if (!this.access_token) {
|
|
180
|
+
await this.login();
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
const rates = await this.request.post('/api/v2/movements/get_rate', { payload,
|
|
184
|
+
headers: {
|
|
185
|
+
'Content-Type': 'application/json',
|
|
186
|
+
Accept: 'application/json',
|
|
187
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
188
|
+
} });
|
|
189
|
+
return rates.data;
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
throw new Error(`Could not retrieve rates ${error}`);
|
|
193
|
+
}
|
|
209
194
|
}
|
|
210
195
|
}
|
|
211
|
-
|
|
196
|
+
|
|
197
|
+
exports.Tropipay = Tropipay;
|
|
198
|
+
//# sourceMappingURL=index.js.map
|
package/index.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { PaymentLink, PaymentLinkPayload } from './interfaces/paymentlink'
|
|
|
12
12
|
type ServerMode = 'Development' | 'Production'
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
class Tropipay {
|
|
15
|
+
export class Tropipay {
|
|
16
16
|
readonly client_id: string;
|
|
17
17
|
readonly client_secret: string;
|
|
18
18
|
public request: Axios;
|
|
@@ -209,6 +209,5 @@ class Tropipay {
|
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
|
|
212
|
-
export default Tropipay
|
|
213
212
|
|
|
214
213
|
|
|
File without changes
|
|
File without changes
|
package/interfaces/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yosle/tropipayjs",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "Javascript / Typescript SDK for the Tropipay API",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
-
"
|
|
8
|
+
"_clear": "rimraf build/compiled/*",
|
|
9
|
+
"_tsc": "tsc",
|
|
10
|
+
"_make-bundle": "rollup --config",
|
|
11
|
+
"build": "run-s _clear _tsc _make-bundle"
|
|
9
12
|
},
|
|
10
13
|
"repository": {
|
|
11
14
|
"type": "git",
|
|
@@ -22,6 +25,14 @@
|
|
|
22
25
|
"author": "Yosleivy Baez Acosta <yosle007@gmail.com>",
|
|
23
26
|
"license": "MIT",
|
|
24
27
|
"dependencies": {
|
|
25
|
-
"axios": "^0.27.2"
|
|
28
|
+
"axios": "^0.27.2",
|
|
29
|
+
"tslib": "^2.4.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@rollup/plugin-typescript": "^8.5.0",
|
|
33
|
+
"rimraf": "^3.0.2",
|
|
34
|
+
"rollup": "^2.79.1",
|
|
35
|
+
"rollup-plugin-dts": "^4.2.2",
|
|
36
|
+
"run-s": "^0.0.0"
|
|
26
37
|
}
|
|
27
38
|
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Contents of the file /rollup.config.js
|
|
2
|
+
import typescript from '@rollup/plugin-typescript';
|
|
3
|
+
import dts from "rollup-plugin-dts";
|
|
4
|
+
const config = [
|
|
5
|
+
{
|
|
6
|
+
input: 'dist/index.js',
|
|
7
|
+
output: {
|
|
8
|
+
file: 'index.js',
|
|
9
|
+
format: 'cjs',
|
|
10
|
+
sourcemap: true,
|
|
11
|
+
},
|
|
12
|
+
external: ['axios'],
|
|
13
|
+
plugins: [typescript()]
|
|
14
|
+
}, {
|
|
15
|
+
input: 'dist/index.d.ts',
|
|
16
|
+
output: {
|
|
17
|
+
file: 'index.d.ts',
|
|
18
|
+
format: 'es'
|
|
19
|
+
},
|
|
20
|
+
plugins: [dts()]
|
|
21
|
+
}
|
|
22
|
+
];
|
|
23
|
+
export default config;
|
package/tsconfig.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
4
|
-
|
|
5
4
|
/* Projects */
|
|
6
5
|
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
7
6
|
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
@@ -9,9 +8,8 @@
|
|
|
9
8
|
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
10
9
|
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
11
10
|
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
|
-
|
|
13
11
|
/* Language and Environment */
|
|
14
|
-
"target": "
|
|
12
|
+
"target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
15
13
|
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
16
14
|
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
17
15
|
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
|
|
@@ -23,11 +21,10 @@
|
|
|
23
21
|
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
24
22
|
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
25
23
|
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
26
|
-
|
|
27
24
|
/* Modules */
|
|
28
|
-
"module": "
|
|
25
|
+
"module": "esnext", /* Specify what module code is generated. */
|
|
29
26
|
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
30
|
-
|
|
27
|
+
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
31
28
|
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
32
29
|
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
33
30
|
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
@@ -37,20 +34,18 @@
|
|
|
37
34
|
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
38
35
|
// "resolveJsonModule": true, /* Enable importing .json files. */
|
|
39
36
|
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
40
|
-
|
|
41
37
|
/* JavaScript Support */
|
|
42
38
|
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
43
39
|
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
44
40
|
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
45
|
-
|
|
46
41
|
/* Emit */
|
|
47
|
-
|
|
42
|
+
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
48
43
|
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
49
44
|
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
50
|
-
|
|
45
|
+
"sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
51
46
|
// "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
|
-
|
|
53
|
-
|
|
47
|
+
"outDir": "dist/", /* Specify an output folder for all emitted files. */
|
|
48
|
+
"removeComments": false, /* Disable emitting comments. */
|
|
54
49
|
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
55
50
|
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
56
51
|
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
|
@@ -67,16 +62,14 @@
|
|
|
67
62
|
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
68
63
|
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
69
64
|
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
|
70
|
-
|
|
71
65
|
/* Interop Constraints */
|
|
72
66
|
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
73
67
|
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
74
|
-
"esModuleInterop": true,
|
|
68
|
+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
|
75
69
|
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
76
|
-
"forceConsistentCasingInFileNames": true,
|
|
77
|
-
|
|
70
|
+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
78
71
|
/* Type Checking */
|
|
79
|
-
"strict": true,
|
|
72
|
+
"strict": true, /* Enable all strict type-checking options. */
|
|
80
73
|
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
81
74
|
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
82
75
|
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
@@ -94,10 +87,9 @@
|
|
|
94
87
|
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
95
88
|
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
96
89
|
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
97
|
-
|
|
98
|
-
|
|
90
|
+
"allowUnreachableCode": false, /* Disable error reporting for unreachable code. */
|
|
99
91
|
/* Completeness */
|
|
100
92
|
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
101
|
-
"skipLibCheck": true
|
|
93
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
102
94
|
}
|
|
103
|
-
}
|
|
95
|
+
}
|