hirallpay-node 1.0.0
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 +49 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +29 -0
- package/dist/resources/payments.d.ts +28 -0
- package/dist/resources/payments.js +25 -0
- package/dist/resources/webhooks.d.ts +9 -0
- package/dist/resources/webhooks.js +51 -0
- package/package.json +26 -0
- package/src/index.ts +37 -0
- package/src/resources/payments.ts +42 -0
- package/src/resources/webhooks.ts +15 -0
- package/tsconfig.json +19 -0
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# HirallPay Node.js SDK
|
|
2
|
+
|
|
3
|
+
The official Node.js library for the HirallPay API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install hirallpay-node
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
import HirallPay from 'hirallpay-node';
|
|
15
|
+
|
|
16
|
+
const client = new HirallPay({
|
|
17
|
+
apiKey: 'HirallPay_pk_sandbox_...',
|
|
18
|
+
environment: 'sandbox'
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Initiate Payment
|
|
22
|
+
const payment = await client.payments.initiate({
|
|
23
|
+
amount: 1000,
|
|
24
|
+
phone: '254712345678'
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
console.log(payment);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Publishing (For Maintainers)
|
|
31
|
+
|
|
32
|
+
To publish this package to npm:
|
|
33
|
+
|
|
34
|
+
1. **Build the project**:
|
|
35
|
+
```bash
|
|
36
|
+
npm run build
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
2. **Login to npm** (if not already logged in):
|
|
40
|
+
```bash
|
|
41
|
+
npm login
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
3. **Publish**:
|
|
45
|
+
```bash
|
|
46
|
+
npm publish --access public
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**Note:** Ensure you have updated the `version` in `package.json` before publishing a new release.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Payments } from './resources/payments';
|
|
2
|
+
export interface HirallPayConfig {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
environment?: 'sandbox' | 'live';
|
|
5
|
+
timeout?: number;
|
|
6
|
+
}
|
|
7
|
+
import { Webhooks } from './resources/webhooks';
|
|
8
|
+
export declare class HirallPay {
|
|
9
|
+
private client;
|
|
10
|
+
payments: Payments;
|
|
11
|
+
webhooks: Webhooks;
|
|
12
|
+
constructor(config: HirallPayConfig);
|
|
13
|
+
}
|
|
14
|
+
export default HirallPay;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HirallPay = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const payments_1 = require("./resources/payments");
|
|
9
|
+
const webhooks_1 = require("./resources/webhooks");
|
|
10
|
+
class HirallPay {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
const baseURL = config.environment === 'live'
|
|
13
|
+
? 'https://api.hirallpay.com/api/v1'
|
|
14
|
+
: 'https://hirallpay.allantoo.site/api/v1';
|
|
15
|
+
this.client = axios_1.default.create({
|
|
16
|
+
baseURL,
|
|
17
|
+
timeout: config.timeout || 10000,
|
|
18
|
+
headers: {
|
|
19
|
+
'Authorization': `Bearer ${config.apiKey}`,
|
|
20
|
+
'Content-Type': 'application/json',
|
|
21
|
+
'User-Agent': 'HirallPay-Node/1.0.0'
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
this.payments = new payments_1.Payments(this.client);
|
|
25
|
+
this.webhooks = new webhooks_1.Webhooks();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.HirallPay = HirallPay;
|
|
29
|
+
exports.default = HirallPay;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
export interface InitiatePaymentParams {
|
|
3
|
+
amount: number;
|
|
4
|
+
phone: string;
|
|
5
|
+
reference?: string;
|
|
6
|
+
callback_url?: string;
|
|
7
|
+
metadata?: Record<string, any>;
|
|
8
|
+
}
|
|
9
|
+
export interface InitiatePaymentResponse {
|
|
10
|
+
id: string;
|
|
11
|
+
status: string;
|
|
12
|
+
provider: string;
|
|
13
|
+
raw_response: any;
|
|
14
|
+
}
|
|
15
|
+
export declare class Payments {
|
|
16
|
+
private client;
|
|
17
|
+
constructor(client: AxiosInstance);
|
|
18
|
+
/**
|
|
19
|
+
* Initiate a payment (STK Push)
|
|
20
|
+
* @param params Payment parameters
|
|
21
|
+
*/
|
|
22
|
+
initiate(params: InitiatePaymentParams): Promise<InitiatePaymentResponse>;
|
|
23
|
+
/**
|
|
24
|
+
* Get payment details
|
|
25
|
+
* @param id Payment ID
|
|
26
|
+
*/
|
|
27
|
+
get(id: string): Promise<any>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Payments = void 0;
|
|
4
|
+
class Payments {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Initiate a payment (STK Push)
|
|
10
|
+
* @param params Payment parameters
|
|
11
|
+
*/
|
|
12
|
+
async initiate(params) {
|
|
13
|
+
const response = await this.client.post('/payments', params);
|
|
14
|
+
return response.data;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Get payment details
|
|
18
|
+
* @param id Payment ID
|
|
19
|
+
*/
|
|
20
|
+
async get(id) {
|
|
21
|
+
const response = await this.client.get(`/payments/${id}`);
|
|
22
|
+
return response.data;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.Payments = Payments;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class Webhooks {
|
|
2
|
+
/**
|
|
3
|
+
* Verify the webhook signature
|
|
4
|
+
* @param payload The raw request body
|
|
5
|
+
* @param signature The signature from the X-HirallPay-Signature header
|
|
6
|
+
* @param secret The webhook signing secret
|
|
7
|
+
*/
|
|
8
|
+
verifySignature(payload: string, signature: string, secret: string): boolean;
|
|
9
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.Webhooks = void 0;
|
|
37
|
+
const crypto = __importStar(require("crypto"));
|
|
38
|
+
class Webhooks {
|
|
39
|
+
/**
|
|
40
|
+
* Verify the webhook signature
|
|
41
|
+
* @param payload The raw request body
|
|
42
|
+
* @param signature The signature from the X-HirallPay-Signature header
|
|
43
|
+
* @param secret The webhook signing secret
|
|
44
|
+
*/
|
|
45
|
+
verifySignature(payload, signature, secret) {
|
|
46
|
+
const hmac = crypto.createHmac('sha256', secret);
|
|
47
|
+
const digest = hmac.update(payload).digest('hex');
|
|
48
|
+
return signature === digest;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.Webhooks = Webhooks;
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "hirallpay-node",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Official Node.js SDK for HirallPay Integration",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"prepublishOnly": "npm run build"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"hirallpay",
|
|
13
|
+
"payments",
|
|
14
|
+
"mpesa",
|
|
15
|
+
"sdk"
|
|
16
|
+
],
|
|
17
|
+
"author": "HirallPay Engineering",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"typescript": "^5.0.0",
|
|
21
|
+
"@types/node": "^20.0.0"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"axios": "^1.6.0"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import axios, { AxiosInstance } from 'axios';
|
|
2
|
+
import { Payments } from './resources/payments';
|
|
3
|
+
|
|
4
|
+
export interface HirallPayConfig {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
environment?: 'sandbox' | 'live';
|
|
7
|
+
timeout?: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
import { Webhooks } from './resources/webhooks';
|
|
11
|
+
|
|
12
|
+
export class HirallPay {
|
|
13
|
+
private client: AxiosInstance;
|
|
14
|
+
public payments: Payments;
|
|
15
|
+
public webhooks: Webhooks;
|
|
16
|
+
|
|
17
|
+
constructor(config: HirallPayConfig) {
|
|
18
|
+
const baseURL = config.environment === 'live'
|
|
19
|
+
? 'https://api.hirallpay.com/api/v1'
|
|
20
|
+
: 'https://hirallpay.allantoo.site/api/v1';
|
|
21
|
+
|
|
22
|
+
this.client = axios.create({
|
|
23
|
+
baseURL,
|
|
24
|
+
timeout: config.timeout || 10000,
|
|
25
|
+
headers: {
|
|
26
|
+
'Authorization': `Bearer ${config.apiKey}`,
|
|
27
|
+
'Content-Type': 'application/json',
|
|
28
|
+
'User-Agent': 'HirallPay-Node/1.0.0'
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
this.payments = new Payments(this.client);
|
|
33
|
+
this.webhooks = new Webhooks();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default HirallPay;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
|
|
3
|
+
export interface InitiatePaymentParams {
|
|
4
|
+
amount: number;
|
|
5
|
+
phone: string;
|
|
6
|
+
reference?: string;
|
|
7
|
+
callback_url?: string;
|
|
8
|
+
metadata?: Record<string, any>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface InitiatePaymentResponse {
|
|
12
|
+
id: string;
|
|
13
|
+
status: string;
|
|
14
|
+
provider: string;
|
|
15
|
+
raw_response: any;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class Payments {
|
|
19
|
+
private client: AxiosInstance;
|
|
20
|
+
|
|
21
|
+
constructor(client: AxiosInstance) {
|
|
22
|
+
this.client = client;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Initiate a payment (STK Push)
|
|
27
|
+
* @param params Payment parameters
|
|
28
|
+
*/
|
|
29
|
+
async initiate(params: InitiatePaymentParams): Promise<InitiatePaymentResponse> {
|
|
30
|
+
const response = await this.client.post('/payments', params);
|
|
31
|
+
return response.data;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Get payment details
|
|
36
|
+
* @param id Payment ID
|
|
37
|
+
*/
|
|
38
|
+
async get(id: string): Promise<any> {
|
|
39
|
+
const response = await this.client.get(`/payments/${id}`);
|
|
40
|
+
return response.data;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as crypto from 'crypto';
|
|
2
|
+
|
|
3
|
+
export class Webhooks {
|
|
4
|
+
/**
|
|
5
|
+
* Verify the webhook signature
|
|
6
|
+
* @param payload The raw request body
|
|
7
|
+
* @param signature The signature from the X-HirallPay-Signature header
|
|
8
|
+
* @param secret The webhook signing secret
|
|
9
|
+
*/
|
|
10
|
+
verifySignature(payload: string, signature: string, secret: string): boolean {
|
|
11
|
+
const hmac = crypto.createHmac('sha256', secret);
|
|
12
|
+
const digest = hmac.update(payload).digest('hex');
|
|
13
|
+
return signature === digest;
|
|
14
|
+
}
|
|
15
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true
|
|
11
|
+
},
|
|
12
|
+
"include": [
|
|
13
|
+
"src/**/*"
|
|
14
|
+
],
|
|
15
|
+
"exclude": [
|
|
16
|
+
"node_modules",
|
|
17
|
+
"**/*.test.ts"
|
|
18
|
+
]
|
|
19
|
+
}
|