pesapress-lookup 1.0.2 → 1.0.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/README.md +1 -32
- package/package.json +8 -1
- package/src/app.ts +3 -41
package/README.md
CHANGED
|
@@ -22,44 +22,13 @@ const { PesaPressLookup } = require('pesapress');
|
|
|
22
22
|
const pesapress = new PesaPressLookup();
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
###### Register email to get API key
|
|
26
|
-
Register a new API key using your email.
|
|
27
|
-
The API key will only be shown **once** and should be saved somewhere
|
|
28
|
-
|
|
29
|
-
```javascript
|
|
30
|
-
|
|
31
|
-
const resp = await pesapress.register('myemail@domain.com')
|
|
32
|
-
|
|
33
|
-
if ( resp ) {
|
|
34
|
-
resp.apikey; // api key
|
|
35
|
-
resp.dailyCredits; // daily credits
|
|
36
|
-
resp.remainingCredits; // remaining daily credits
|
|
37
|
-
} else {
|
|
38
|
-
// Error that email already exists
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
###### Check remaining credits
|
|
43
|
-
Check the remaining account credits
|
|
44
|
-
|
|
45
|
-
```javascript
|
|
46
|
-
|
|
47
|
-
const resp = await pesapress.status('YOURAPIKEY')
|
|
48
|
-
|
|
49
|
-
if ( resp ) {
|
|
50
|
-
resp.dailyCredits; // daily credits
|
|
51
|
-
resp.remainingCredits; // remaining daily credits
|
|
52
|
-
} else {
|
|
53
|
-
// Error that api key is invalid
|
|
54
|
-
}
|
|
55
|
-
```
|
|
56
25
|
|
|
57
26
|
###### Get mobile number from hash
|
|
58
27
|
Check for a mobile number from a hash.
|
|
59
28
|
|
|
60
29
|
```javascript
|
|
61
30
|
|
|
62
|
-
const resp = await pesapress.search('
|
|
31
|
+
const resp = await pesapress.search('MOBILENUMBER_HASH')
|
|
63
32
|
|
|
64
33
|
if ( resp ) {
|
|
65
34
|
resp.msisdn; // The decoded number
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pesapress-lookup",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Mpesa lookup API by PesaPress",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -8,6 +8,13 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "babel src --out-dir dist"
|
|
10
10
|
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/PesaPress/pesapress-lookup.git"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/PesaPress/pesapress-lookup/issues"
|
|
17
|
+
},
|
|
11
18
|
"keywords": ["mpesa","hashed","safaricom","decode","phone","pesapress"],
|
|
12
19
|
"author": "Paul Kevin <paultitude@gmail.com>",
|
|
13
20
|
"license": "ISC",
|
package/src/app.ts
CHANGED
|
@@ -8,60 +8,22 @@ export class PesaPressLookup {
|
|
|
8
8
|
this.apiClient = new ApiClient({ baseURL : 'https://api.pesapress.com'});
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* Register an email
|
|
13
|
-
* @param {string} email
|
|
14
|
-
* @returns
|
|
15
|
-
*/
|
|
16
|
-
async register( email : string ){
|
|
17
|
-
try {
|
|
18
|
-
const response = await this.apiClient.postForm<{ data: object }>('/api/numbers/lookup/register', {email : email},
|
|
19
|
-
{"Content-Type": "application/x-www-form-urlencoded"},
|
|
20
|
-
);
|
|
21
|
-
if ( response ) {
|
|
22
|
-
return response.data;
|
|
23
|
-
}
|
|
24
|
-
} catch (error) {
|
|
25
|
-
console.error("API Error:", error);
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Check the status on the account
|
|
32
|
-
* @param {string} apikey
|
|
33
|
-
* @returns
|
|
34
|
-
*/
|
|
35
|
-
async status( apikey : string) {
|
|
36
|
-
try {
|
|
37
|
-
const response = await this.apiClient.postForm<{ data: object }>('/api/numbers/lookup/status', {}, { apikey: apikey } );
|
|
38
|
-
if ( response ) {
|
|
39
|
-
return response.data;
|
|
40
|
-
}
|
|
41
|
-
} catch (error) {
|
|
42
|
-
console.error("API Error:", error);
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
11
|
/**
|
|
48
12
|
* Search by api key. Search for the hash
|
|
49
|
-
* @param {string} apikey The API key
|
|
50
13
|
* @param {string} hash The msisdn hashs
|
|
51
14
|
* @returns
|
|
52
15
|
*/
|
|
53
|
-
async search(
|
|
16
|
+
async search( hash : string ) {
|
|
54
17
|
try {
|
|
55
18
|
const response = await this.apiClient.postForm<{ data: object }>(
|
|
56
|
-
'/api/numbers/lookup/
|
|
19
|
+
'/api/numbers/lookup/query',
|
|
57
20
|
{ hash: hash },
|
|
58
|
-
{
|
|
21
|
+
{ "Content-Type": "application/x-www-form-urlencoded" }
|
|
59
22
|
);
|
|
60
23
|
if ( response ) {
|
|
61
24
|
return response.data;
|
|
62
25
|
}
|
|
63
26
|
} catch (error) {
|
|
64
|
-
console.error("API Error:", error);
|
|
65
27
|
return false;
|
|
66
28
|
}
|
|
67
29
|
}
|