@yosle/tropipayjs 0.1.2 → 0.1.5

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 CHANGED
@@ -1,28 +1,68 @@
1
- TropipayJS - A typed SDK for Tropipay Payments API
1
+ TropipayJS -Typescript/Javascript SDK for Tropipay Payments API
2
2
  ===========
3
+ ![TypeScript](https://img.shields.io/badge/typescript-%23007ACC.svg?style=for-the-badge&logo=typescript&logoColor=white)
4
+ ![JavaScript](https://img.shields.io/badge/javascript-%23323330.svg?style=for-the-badge&logo=javascript&logoColor=%23F7DF1E)
5
+ ![Next JS](https://img.shields.io/badge/Next-black?style=for-the-badge&logo=next.js&logoColor=white)
6
+ ![NodeJS](https://img.shields.io/badge/node.js-6DA55F?style=for-the-badge&logo=node.js&logoColor=white)
3
7
 
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.
8
+ TropiPay is an electronic wallet that allows you to execute the most common financial operations of the day to day. This is an SDK for Typescript and Javacript that helps you build integrations with the Tropipay platform in an easier way. Can save you a lot of time and effort implementing all the API features. You can use this library with CommonJS system (like node + express) or ES6 module system (NextJS).
5
9
 
6
- # Instalation
10
+ ## Project status
11
+ This library is still under development so using it in the live (real account) isn't recommended yet.
12
+
13
+ # Table of Contents
14
+ * [Getting started](#getting-started)
15
+ * [Setting up your credentials](#setting-up-your-app-credentials)
16
+ * [Documentation](#documentation)
17
+ * [Examples](#examples)
18
+ * [Contribute and Help](#contributing-and-help)
19
+
20
+ # Getting started
7
21
  You can use npm or yarn to install this package:
8
22
 
9
- `npm install tropipayjs` or
10
- `yarn add tropipayjs`
23
+ ```npm install @yosle/tropipayjs```
11
24
 
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*. Do not use the Tropipay object on the client side (browser). This would expose your app credentials (the client secret of your account). You can create an endpoint at your back-end using express and consume it in your front-end, or use SSR if you're using NextJS.
25
+ or
14
26
 
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.
27
+ ```yarn add @yosle/tropipayjs```
28
+
29
+ ## Setting up your app credentials
30
+ ![alt](/docs/images/app-credentials-menu.png)
31
+ ![alt](/docs/images/confirmation-code-screen.png)
32
+ In order to use the Tropipay API you'll need a client ID and a client secret. Sign up with your [Tropipay](www.tropipay.com) account, go to the App Menu->Applications and credentials. You'll be asked to enter a confirmation code (use 123456 in the test enviroment). _Make sure you test everything in the [test enviroment](https://tropipay-dev.herokuapp.com) first before using your real account._ Create an app and configure the client id an client secret for the app.
33
+
34
+ ## How to use
35
+ 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*. Do not use the Tropipay object on the client side (browser). This would expose your app credentials (the client secret of your account). You can create an endpoint at your back-end using express and consume it in your front-end, or use SSR if you're using NextJS.
17
36
 
18
- # Examples
37
+ ### CommonJS
38
+ ```javascript
39
+ const { Tropipay } = require('@yosle/tropipayjs')
40
+ ```
41
+ ### ES6
42
+ ```javascript
43
+ import { Tropipay } from '@yosle/tropipayjs'
44
+ ```
45
+ ### Initialize the Tropipay class
46
+ ```javascript
47
+ const tpp = new Tropipay("yourclientidhere",
48
+ "yourclientsecrethere")
49
+ ```
50
+ ## Generating a Payment Link
51
+ ```javascript
52
+ const paylink = await tpp.createPayLink(payload)
53
+ ```
19
54
 
20
- # Using Typescript
55
+ # Documentation
56
+ Examples using express + nodejs and NextJS will be added soon.
21
57
 
22
- # Contributing and Help
23
- Having problems? want to contribute? join our community slack.
58
+ # Contributing
59
+ Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
24
60
 
61
+ Please make sure to update tests as appropriate.
25
62
 
63
+ You can also make a small [donation to the author](https://tppay.me/l94qaa3h).
64
+ ## License
65
+ [MIT License](https://choosealicense.com/licenses/mit/)
26
66
 
27
67
 
28
68
 
package/index.d.ts CHANGED
@@ -1,54 +1,101 @@
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
- * Tropipayjs is a wrapper for the Tropipay API. It was made in
3
- * typescript but you can use Javascript.
4
- * @author Yosleivy baez Acosta
41
+ * Tropipayjs is a Typescript/Javascript library for the Tropipay API. CommonJs and
42
+ * ES6 modules are supported.
43
+ * @author Yosleivy Baez Acosta
5
44
  *
6
45
  */
7
- import { Axios } from "axios";
8
- import { PaymentLink, PaymentLinkPayload } from './interfaces/paymentlink';
46
+
9
47
  declare type ServerMode = 'Development' | 'Production';
10
48
  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;
49
+ readonly clientId: string;
50
+ readonly clientSecret: string;
51
+ protected request: Axios;
52
+ protected accessToken: string | undefined;
53
+ protected refreshToken: string | undefined;
54
+ protected serverMode: ServerMode;
17
55
  constructor(client_id: string, client_secret: string, server_mode?: ServerMode);
18
56
  login(): Promise<LoginResponse>;
19
57
  /**
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
58
+ * Create a paymentLink with the specified options.
59
+ * @param payload PaymentLinkPayload Object.
60
+ * @returns Promise<PaymentLink> or throws an Exception.
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 Promise of AccountDeposits Object or Error
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
35
- * @see
71
+ * Get the list of all supported countries by Tropipay.
72
+ * @returns Array of Countries Data
73
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/bfac21259e2ff-getting-users-countries-list
36
74
  */
37
- countries(): Promise<Country[] | Error>;
75
+ countries(): Promise<Country[]>;
38
76
  /**
77
+ * Get the list of all detination countries supported by Tropipay.
78
+ * Obtaining the list of valid countries to send funds to. Useful
79
+ * when adding new beneficiaries to some user.
39
80
  *
81
+ * @returns Array of Country Objects
82
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/3cfe5504f0524-getting-list-of-beneficiary-countries
83
+ */
84
+ destinations(): Promise<Country[]>;
85
+ /**
86
+ * Get list of all the favorites accounts. This endpoint is not documented
87
+ * in the official Tropipay documentation.
40
88
  * @returns
41
- * @see
42
89
  */
43
90
  favorites(): Promise<any>;
44
91
  /**
45
- * List all movements in current account. You can optionaly specify
46
- * offset and limit params for pagination.
92
+ * List all account movements. You can optionaly specify
93
+ * offset and limit params for pagination.
47
94
  * @returns
48
95
  */
49
96
  movements(offset?: number, limit?: number): Promise<any>;
50
97
  /**
51
- * Return user profile
98
+ * Return profile data for this account.
52
99
  * @returns
53
100
  */
54
101
  profile(): Promise<any>;
@@ -56,4 +103,5 @@ declare class Tropipay {
56
103
  currencyFrom: string;
57
104
  }): Promise<any>;
58
105
  }
59
- export default Tropipay;
106
+
107
+ export { Tropipay };
package/index.js CHANGED
@@ -1,211 +1,213 @@
1
- "use strict";
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
- * Tropipayjs is a wrapper for the Tropipay API. It was made in
4
- * typescript but you can use Javascript.
5
- * @author Yosleivy baez Acosta
12
+ * Tropipayjs is a Typescript/Javascript library for the Tropipay API. CommonJs and
13
+ * ES6 modules are supported.
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
+ clientId;
19
+ clientSecret;
20
+ request;
21
+ accessToken;
22
+ refreshToken;
23
+ serverMode;
23
24
  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'
25
+ this.clientId = client_id;
26
+ this.clientSecret = client_secret;
27
+ this.serverMode = server_mode;
28
+ this.request = axios__default["default"].create({
29
+ baseURL: this.serverMode === 'Production'
29
30
  ? 'https://www.tropipay.com'
30
31
  : 'https://tropipay-dev.herokuapp.com',
31
32
  headers: {
32
33
  'Content-Type': 'application/json',
33
34
  Accept: 'application/json',
34
- Authorization: `Bearer ${this.access_token}`,
35
+ Authorization: `Bearer ${this.accessToken}`,
35
36
  }
36
37
  });
37
38
  }
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
- });
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
+ this.accessToken = data.access_token;
53
+ this.refreshToken = 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
- * Create a paymentLink width the specifued payload
67
- * @param payload Object of PaymentLinkPayload type with paylink payload
68
- * @returns Promise<PaymentLink> or Error
65
+ * Create a paymentLink with the specified options.
66
+ * @param payload PaymentLinkPayload Object.
67
+ * @returns Promise<PaymentLink> or throws an Exception.
69
68
  * @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
70
69
  */
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
- });
70
+ async createPayLink(payload) {
71
+ if (!this.accessToken) {
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.accessToken}`,
79
+ // Accept: 'application/json'
80
+ }
81
+ });
82
+ return paylink.data;
83
+ }
84
+ catch (error) {
85
+ throw new Error(`Could not obtain the access tokemn with the given credentials.`);
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
- 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
- });
93
+ async getDepositAccounts() {
94
+ if (!this.accessToken) {
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
- * @returns Array of Countries
113
- * @see
107
+ * @returns Array of Countries Data
108
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/bfac21259e2ff-getting-users-countries-list
114
109
  */
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
- });
110
+ async countries() {
111
+ try {
112
+ const countries = await this.request.get('/api/v2/countries');
113
+ return countries.data;
114
+ }
115
+ catch (error) {
116
+ throw new Error(`Could not retrieve the countries list`);
117
+ }
118
+ }
119
+ /**
120
+ * Get the list of all detination countries supported by Tropipay.
121
+ * Obtaining the list of valid countries to send funds to. Useful
122
+ * when adding new beneficiaries to some user.
123
+ *
124
+ * @returns Array of Country Objects
125
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/3cfe5504f0524-getting-list-of-beneficiary-countries
126
+ */
127
+ async destinations() {
128
+ try {
129
+ const countries = await this.request.get('/api/v2/countries/destinations');
130
+ return countries.data;
131
+ }
132
+ catch (error) {
133
+ throw new Error(`Could not retrieve the destination countries list`);
134
+ }
128
135
  }
129
136
  /**
130
- * Get list of all the favorites accounts.
137
+ * Get list of all the favorites accounts. This endpoint is not documented
138
+ * in the official Tropipay documentation.
131
139
  * @returns
132
- * @see
133
140
  */
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
- });
141
+ async favorites() {
142
+ if (!this.accessToken) {
143
+ await this.login();
144
+ }
145
+ try {
146
+ const favoritesList = await this.request.get('/api/v2/paymentcards/favorites');
147
+ console.log(favoritesList);
148
+ return favoritesList.data;
149
+ }
150
+ catch (error) {
151
+ throw new Error(`Could not retrieve favorites list ${error}`);
152
+ }
147
153
  }
148
154
  /**
149
- * List all movements in current account. You can optionaly specify
150
- * offset and limit params for pagination.
155
+ * List all account movements. You can optionaly specify
156
+ * offset and limit params for pagination.
151
157
  * @returns
152
158
  */
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
- });
159
+ async movements(offset = 0, limit = 10) {
160
+ if (!this.accessToken) {
161
+ await this.login();
162
+ }
163
+ try {
164
+ const movements = await this.request.get('/api/v2/movements', { params: { limit: limit, offset: offset },
165
+ headers: {
166
+ 'Content-Type': 'application/json',
167
+ Accept: 'application/json',
168
+ Authorization: `Bearer ${this.accessToken}`,
169
+ } });
170
+ return movements.data;
171
+ }
172
+ catch (error) {
173
+ throw new Error(`Could not retrieve movements list`);
174
+ }
171
175
  }
172
176
  /**
173
177
  * Return profile data for this account.
174
178
  * @returns
175
179
  */
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
- });
180
+ async profile() {
181
+ if (!this.accessToken) {
182
+ await this.login();
183
+ }
184
+ try {
185
+ const profile = await this.request.get('/api/users/profile');
186
+ return profile.data;
187
+ }
188
+ catch (error) {
189
+ throw new Error(`Could not retrieve movements list ${error}`);
190
+ }
189
191
  }
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
- });
192
+ async getRates(payload = { currencyFrom: "EUR" }) {
193
+ console.log(payload);
194
+ if (!this.accessToken) {
195
+ await this.login();
196
+ }
197
+ try {
198
+ const rates = await this.request.post('/api/v2/movements/get_rate', { payload,
199
+ headers: {
200
+ 'Content-Type': 'application/json',
201
+ Accept: 'application/json',
202
+ Authorization: `Bearer ${this.accessToken}`,
203
+ } });
204
+ return rates.data;
205
+ }
206
+ catch (error) {
207
+ throw new Error(`Could not retrieve rates ${error}`);
208
+ }
209
209
  }
210
210
  }
211
- exports.default = Tropipay;
211
+
212
+ exports.Tropipay = Tropipay;
213
+ //# sourceMappingURL=index.js.map
package/index.ts CHANGED
@@ -1,7 +1,7 @@
1
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
2
+ * Tropipayjs is a Typescript/Javascript library for the Tropipay API. CommonJs and
3
+ * ES6 modules are supported.
4
+ * @author Yosleivy Baez Acosta
5
5
  *
6
6
  */
7
7
 
@@ -12,30 +12,30 @@ import { PaymentLink, PaymentLinkPayload } from './interfaces/paymentlink'
12
12
  type ServerMode = 'Development' | 'Production'
13
13
 
14
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;
15
+ export class Tropipay {
16
+ readonly clientId: string;
17
+ readonly clientSecret: string;
18
+ protected request: Axios;
19
+ protected accessToken: string | undefined;
20
+ protected refreshToken: string | undefined;
21
+ protected serverMode: ServerMode;
22
22
 
23
23
  constructor(
24
24
  client_id: string,
25
25
  client_secret: string,
26
26
  server_mode: ServerMode = 'Development') {
27
- this.client_id = client_id;
28
- this.client_secret = client_secret
29
- this.server_mode = server_mode
27
+ this.clientId = client_id;
28
+ this.clientSecret = client_secret
29
+ this.serverMode = server_mode
30
30
 
31
31
  this.request = axios.create({
32
- baseURL: this.server_mode === 'Production'
32
+ baseURL: this.serverMode === 'Production'
33
33
  ? 'https://www.tropipay.com'
34
34
  : 'https://tropipay-dev.herokuapp.com',
35
35
  headers: {
36
36
  'Content-Type': 'application/json',
37
37
  Accept: 'application/json',
38
- Authorization: `Bearer ${this.access_token}`,
38
+ Authorization: `Bearer ${this.accessToken}`,
39
39
 
40
40
  }
41
41
  })
@@ -45,8 +45,8 @@ class Tropipay {
45
45
  async login() {
46
46
  try {
47
47
  const { data } = await this.request.post<LoginResponse>('/api/v2/access/token', {
48
- client_id: this.client_id,
49
- client_secret: this.client_secret,
48
+ client_id: this.clientId,
49
+ client_secret: this.clientSecret,
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
  }, {
@@ -56,8 +56,8 @@ class Tropipay {
56
56
  // }
57
57
  })
58
58
 
59
- this.access_token = data.access_token
60
- this.refresh_token = data.refresh_token
59
+ this.accessToken = data.access_token
60
+ this.refreshToken = data.refresh_token
61
61
  return data
62
62
  } catch (error) {
63
63
  if (axios.isAxiosError(error)) {
@@ -70,26 +70,26 @@ class Tropipay {
70
70
  }
71
71
 
72
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
73
+ * Create a paymentLink with the specified options.
74
+ * @param payload PaymentLinkPayload Object.
75
+ * @returns Promise<PaymentLink> or throws an Exception.
76
76
  * @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
77
77
  */
78
78
  async createPayLink(payload: PaymentLinkPayload): Promise<PaymentLink> {
79
- if (!this.access_token) {
79
+ if (!this.accessToken) {
80
80
  await this.login()
81
81
  }
82
82
  try {
83
83
  const paylink = await this.request.post('/api/v2/paymentcards', payload, {
84
84
  headers: {
85
85
  // 'Content-Type': 'application/json',
86
- Authorization: `Bearer ${this.access_token}`,
86
+ Authorization: `Bearer ${this.accessToken}`,
87
87
  // Accept: 'application/json'
88
88
  }
89
89
  })
90
90
  return paylink.data as PaymentLink
91
91
  } catch (error) {
92
- throw new Error(`Error tryng to get the access token`);
92
+ throw new Error(`Could not obtain the access tokemn with the given credentials.`);
93
93
 
94
94
  }
95
95
  }
@@ -100,7 +100,7 @@ class Tropipay {
100
100
  * @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6OTgyOTQ1Mg-get-deposit-accounts-list
101
101
  */
102
102
  async getDepositAccounts(): Promise<AccountDeposits[] | Error>{
103
- if (!this.access_token) {
103
+ if (!this.accessToken) {
104
104
  await this.login()
105
105
  }
106
106
  try {
@@ -113,45 +113,62 @@ class Tropipay {
113
113
 
114
114
  /**
115
115
  * Get the list of all supported countries by Tropipay.
116
- * @returns Array of Countries
117
- * @see
116
+ * @returns Array of Countries Data
117
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/bfac21259e2ff-getting-users-countries-list
118
118
  */
119
- async countries(): Promise<Country[] | Error>{
120
- if (!this.access_token) {
121
- await this.login()
122
- }
119
+ async countries(): Promise<Country[] > {
120
+
123
121
  try {
124
- const countries = await this.request.get('/api/countries')
125
- return countries.data
122
+ const countries = await this.request.get('/api/v2/countries')
123
+ return countries.data
126
124
  } catch (error) {
127
125
  throw new Error(`Could not retrieve the countries list`);
128
126
  }
129
127
  }
130
128
 
129
+
130
+ /**
131
+ * Get the list of all detination countries supported by Tropipay.
132
+ * Obtaining the list of valid countries to send funds to. Useful
133
+ * when adding new beneficiaries to some user.
134
+ *
135
+ * @returns Array of Country Objects
136
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/3cfe5504f0524-getting-list-of-beneficiary-countries
137
+ */
138
+ async destinations(): Promise<Country[]> {
139
+ try {
140
+ const countries = await this.request.get('/api/v2/countries/destinations')
141
+ return countries.data
142
+ } catch (error) {
143
+ throw new Error(`Could not retrieve the destination countries list`);
144
+ }
145
+ }
146
+
131
147
  /**
132
- * Get list of all the favorites accounts.
148
+ * Get list of all the favorites accounts. This endpoint is not documented
149
+ * in the official Tropipay documentation.
133
150
  * @returns
134
- * @see
135
151
  */
136
152
  async favorites(){
137
- if (!this.access_token) {
153
+ if (!this.accessToken) {
138
154
  await this.login()
139
155
  }
140
156
  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`);
157
+ const favoritesList = await this.request.get('/api/v2/paymentcards/favorites')
158
+ console.log(favoritesList)
159
+ return favoritesList.data
160
+ } catch (error) {
161
+ throw new Error(`Could not retrieve favorites list ${error}`);
145
162
  }
146
163
  }
147
164
 
148
165
  /**
149
- * List all movements in current account. You can optionaly specify
150
- * offset and limit params for pagination.
166
+ * List all account movements. You can optionaly specify
167
+ * offset and limit params for pagination.
151
168
  * @returns
152
169
  */
153
170
  async movements(offset = 0 , limit = 10){
154
- if (!this.access_token) {
171
+ if (!this.accessToken) {
155
172
  await this.login()
156
173
  }
157
174
  try {
@@ -160,7 +177,7 @@ class Tropipay {
160
177
  headers: {
161
178
  'Content-Type': 'application/json',
162
179
  Accept: 'application/json',
163
- Authorization: `Bearer ${this.access_token}`,
180
+ Authorization: `Bearer ${this.accessToken}`,
164
181
 
165
182
  } })
166
183
  return movements.data
@@ -175,7 +192,7 @@ class Tropipay {
175
192
  * @returns
176
193
  */
177
194
  async profile(){
178
- if (!this.access_token) {
195
+ if (!this.accessToken) {
179
196
  await this.login()
180
197
  }
181
198
  try {
@@ -188,7 +205,7 @@ class Tropipay {
188
205
 
189
206
  async getRates(payload = {currencyFrom: "EUR"}) {
190
207
  console.log(payload)
191
- if (!this.access_token) {
208
+ if (!this.accessToken) {
192
209
  await this.login()
193
210
  }
194
211
  try {
@@ -196,7 +213,7 @@ class Tropipay {
196
213
  headers: {
197
214
  'Content-Type': 'application/json',
198
215
  Accept: 'application/json',
199
- Authorization: `Bearer ${this.access_token}`,
216
+ Authorization: `Bearer ${this.accessToken}`,
200
217
 
201
218
  } })
202
219
  return rates.data
@@ -209,6 +226,5 @@ class Tropipay {
209
226
  }
210
227
 
211
228
 
212
- export default Tropipay
213
229
 
214
230
 
File without changes
@@ -1 +1,2 @@
1
1
  "use strict";
2
+ //# sourceMappingURL=index.js.map
File without changes
@@ -1 +1,2 @@
1
1
  "use strict";
2
+ //# sourceMappingURL=index.js.map
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "@yosle/tropipayjs",
3
- "version": "0.1.2",
4
- "description": " Javascript / Typescript SDK for Tropipay API",
3
+ "version": "0.1.5",
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
- "build": "tsc"
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,18 @@
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"
37
+ },
38
+ "funding": {
39
+ "type": "individual",
40
+ "url": "https://tppay.me/l94qaa3h"
26
41
  }
27
42
  }
@@ -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": "es2015", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
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": "commonjs", /* Specify what module code is generated. */
25
+ "module": "esnext", /* Specify what module code is generated. */
29
26
  // "rootDir": "./", /* Specify the root folder within your source files. */
30
- // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
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
- // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
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
- // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
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
- // "outDir": "./", /* Specify an output folder for all emitted files. */
53
- // "removeComments": true, /* Disable emitting comments. */
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, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
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, /* Ensure that casing is correct in imports. */
77
-
70
+ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
78
71
  /* Type Checking */
79
- "strict": true, /* Enable all strict type-checking options. */
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
- // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
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 /* Skip type checking all .d.ts files. */
93
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
102
94
  }
103
- }
95
+ }