@yosle/tropipayjs 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -10
- package/globals.d.ts +18 -17
- package/index.d.ts +10 -0
- package/index.js +23 -0
- package/package.json +1 -1
- package/src/index.ts +27 -0
package/README.md
CHANGED
|
@@ -60,24 +60,32 @@ import { Tropipay } from '@yosle/tropipayjs'
|
|
|
60
60
|
You can instantiate the Tropipay class passing the client Id ,client secret and optionally the serverMode parameter, if no serverMode is provided, `Development` will be used as default. Make sure you use the [test environment](https://tropipay-dev.herokuapp.com) credentials when serverMode is on `Development`.
|
|
61
61
|
|
|
62
62
|
```javascript
|
|
63
|
-
// test environment server
|
|
64
|
-
const
|
|
65
|
-
|
|
63
|
+
// test environment server tropipay-dev.herokuapp.com
|
|
64
|
+
const config = {
|
|
65
|
+
clientId: process.env.TROPIPAY_CLIENT_ID,
|
|
66
|
+
clientSecret: process.env.TROPIPAY_CLIENT_SECRET
|
|
67
|
+
serverMode: 'Development' // it will be used as default if omited
|
|
68
|
+
}
|
|
69
|
+
const tpp = new Tropipay(config)
|
|
66
70
|
```
|
|
67
71
|
|
|
68
72
|
To use your live credentials (real account) you must explicity set serverMode to `Production`.
|
|
69
73
|
|
|
70
74
|
```javascript
|
|
71
75
|
//real account credentials
|
|
72
|
-
const
|
|
73
|
-
|
|
76
|
+
const config = {
|
|
77
|
+
clientId: process.env.TROPIPAY_CLIENT_ID,
|
|
78
|
+
clientSecret: process.env.TROPIPAY_CLIENT_SECRET,
|
|
79
|
+
serverMode: 'Production' //live account
|
|
80
|
+
}
|
|
81
|
+
const tpp = new Tropipay(config)
|
|
74
82
|
```
|
|
75
83
|
### Generating a Payment Link
|
|
76
84
|
```javascript
|
|
77
85
|
/*
|
|
78
86
|
* Example Payload
|
|
79
87
|
*/
|
|
80
|
-
const payload =
|
|
88
|
+
const payload = {
|
|
81
89
|
reference: "my-paylink-1",
|
|
82
90
|
concept: "Bicycle",
|
|
83
91
|
favorite: "true",
|
|
@@ -102,11 +110,10 @@ const payload = await tpp.createPayLink({
|
|
|
102
110
|
termsAndConditions: "true"
|
|
103
111
|
},
|
|
104
112
|
directPayment: "true"
|
|
105
|
-
}
|
|
106
|
-
|
|
113
|
+
}
|
|
107
114
|
// Use inside an async function
|
|
108
|
-
const paylink = await tpp.
|
|
109
|
-
console.log(paylink.shortUrl)
|
|
115
|
+
const paylink = await tpp.createPaymentCard(payload);
|
|
116
|
+
console.log(paylink.shortUrl);
|
|
110
117
|
```
|
|
111
118
|
|
|
112
119
|
For more examples, please refer to the [Documentation](https://github.com/yosle/tropipayjs/blob/master/docs/)
|
package/globals.d.ts
CHANGED
|
@@ -11,20 +11,20 @@ type LoginError = {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
type Country = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
id: number,
|
|
15
|
+
name: string,
|
|
16
|
+
sepaZone: boolean,
|
|
17
|
+
state: number,
|
|
18
|
+
slug: string,
|
|
19
|
+
slugn: number,
|
|
20
|
+
callingCode: number,
|
|
21
|
+
isDestination: boolean,
|
|
22
|
+
isRisky: boolean,
|
|
23
|
+
currentCurrency: string | null,
|
|
24
|
+
createdAt: string,
|
|
25
|
+
updatedAt: string,
|
|
26
|
+
isFavorite: boolean,
|
|
27
|
+
position: any
|
|
28
28
|
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -69,6 +69,7 @@ type Deposit = {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
type AccountDeposits = {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
72
|
+
count: number,
|
|
73
|
+
rows: Deposit[]
|
|
74
|
+
}
|
|
75
|
+
|
package/index.d.ts
CHANGED
|
@@ -73,6 +73,11 @@ interface TropipayConfig {
|
|
|
73
73
|
clientSecret: string;
|
|
74
74
|
serverMode?: ServerMode;
|
|
75
75
|
}
|
|
76
|
+
type AccountBalance = {
|
|
77
|
+
balance: number;
|
|
78
|
+
pendingIn: number;
|
|
79
|
+
pendingOut: number;
|
|
80
|
+
};
|
|
76
81
|
declare class Tropipay {
|
|
77
82
|
protected clientId: string;
|
|
78
83
|
protected clientSecret: string;
|
|
@@ -101,6 +106,11 @@ declare class Tropipay {
|
|
|
101
106
|
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/bfac21259e2ff-getting-users-countries-list
|
|
102
107
|
*/
|
|
103
108
|
countries(): Promise<Country[]>;
|
|
109
|
+
/**
|
|
110
|
+
* Get user balance
|
|
111
|
+
* @returns balance object
|
|
112
|
+
*/
|
|
113
|
+
getBalance(): Promise<AccountBalance>;
|
|
104
114
|
/**
|
|
105
115
|
* Get the list of all detination countries supported by Tropipay.
|
|
106
116
|
* Obtaining the list of valid countries to send funds to. Useful
|
package/index.js
CHANGED
|
@@ -121,6 +121,29 @@ class Tropipay {
|
|
|
121
121
|
throw new Error(`TropipayJS Error - Could not retrieve the countries list`);
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Get user balance
|
|
126
|
+
* @returns balance object
|
|
127
|
+
*/
|
|
128
|
+
async getBalance() {
|
|
129
|
+
if (!Tropipay.accessToken) {
|
|
130
|
+
await this.login();
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
const balance = await this.request.get('/api/v2/users/balance', {
|
|
134
|
+
headers: {
|
|
135
|
+
'Content-Type': 'application/json',
|
|
136
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
137
|
+
Accept: 'application/json'
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
return balance.data;
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
console.log("el error es ", error);
|
|
144
|
+
throw new Error(`TropipayJS Error - Could not retrieve the user's balance`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
124
147
|
/**
|
|
125
148
|
* Get the list of all detination countries supported by Tropipay.
|
|
126
149
|
* Obtaining the list of valid countries to send funds to. Useful
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -17,6 +17,12 @@ interface TropipayConfig {
|
|
|
17
17
|
serverMode?: ServerMode;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
type AccountBalance = {
|
|
21
|
+
balance: number,
|
|
22
|
+
pendingIn: number,
|
|
23
|
+
pendingOut: number
|
|
24
|
+
}
|
|
25
|
+
|
|
20
26
|
export class Tropipay {
|
|
21
27
|
protected clientId: string;
|
|
22
28
|
protected clientSecret: string;
|
|
@@ -128,6 +134,27 @@ export class Tropipay {
|
|
|
128
134
|
throw new Error(`TropipayJS Error - Could not retrieve the countries list`);
|
|
129
135
|
}
|
|
130
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Get user balance
|
|
139
|
+
* @returns balance Object { balance: number, pendingIn: number, pendingOut: number }
|
|
140
|
+
*/
|
|
141
|
+
async getBalance(): Promise<AccountBalance> {
|
|
142
|
+
if (!Tropipay.accessToken) {
|
|
143
|
+
await this.login()
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
const balance = await this.request.get('/api/v2/users/balance', {
|
|
147
|
+
headers: {
|
|
148
|
+
'Content-Type': 'application/json',
|
|
149
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
150
|
+
Accept: 'application/json'
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
return balance.data
|
|
154
|
+
} catch (error) {
|
|
155
|
+
throw new Error(`TropipayJS Error - Could not retrieve the user's balance`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
131
158
|
|
|
132
159
|
/**
|
|
133
160
|
* Get the list of all detination countries supported by Tropipay.
|