payx-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 ADDED
@@ -0,0 +1,59 @@
1
+ # PayX Node.js SDK
2
+
3
+ The official Node.js SDK for the PayX Payment Gateway.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install payx-node
9
+ # or
10
+ yarn add payx-node
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### Initialize the Client
16
+
17
+ ```javascript
18
+ const { PayX } = require('payx-node');
19
+
20
+ const payx = new PayX({
21
+ apiKey: 'your_payx_api_key'
22
+ });
23
+ ```
24
+
25
+ ### Initiate a Mobile Money Charge
26
+
27
+ ```javascript
28
+ async function chargeCustomer() {
29
+ try {
30
+ const response = await payx.charge.create({
31
+ amount: 10.0,
32
+ currency: 'GHS',
33
+ phoneNumber: '0551234987',
34
+ network: 'MTN',
35
+ payerMessage: 'Order #1234',
36
+ payeeNote: 'SaaS Subscription'
37
+ });
38
+
39
+ console.log('Transaction ID:', response.transactionId);
40
+ console.log('Status:', response.status);
41
+ } catch (error) {
42
+ console.error('Charge failed:', error.message);
43
+ }
44
+ }
45
+ ```
46
+
47
+ ### Verify Webhook Signatures
48
+
49
+ ```javascript
50
+ const isValid = payx.webhooks.verifySignature(
51
+ req.rawBody,
52
+ req.headers['x-payx-signature'],
53
+ 'your_webhook_secret'
54
+ );
55
+ ```
56
+
57
+ ## Documentation
58
+
59
+ For full documentation, visit [docs.payx.app](https://docs.payx.app).
@@ -0,0 +1,91 @@
1
+ import { AxiosInstance } from 'axios';
2
+
3
+ interface PayXConfig {
4
+ /**
5
+ * Your PayX API Key (Test or Live)
6
+ */
7
+ apiKey: string;
8
+ /**
9
+ * Optional base URL for the API (defaults to https://api.payx.app/v1)
10
+ */
11
+ baseURL?: string;
12
+ }
13
+ type Network = 'MTN' | 'TELECEL' | 'AIRTELTIGO';
14
+ interface ChargeParams {
15
+ amount: number | string;
16
+ phoneNumber: string;
17
+ network: Network;
18
+ currency?: string;
19
+ payerMessage?: string;
20
+ payeeNote?: string;
21
+ }
22
+ interface PayoutParams {
23
+ amount: number | string;
24
+ phoneNumber: string;
25
+ network: Network;
26
+ currency?: string;
27
+ payerMessage?: string;
28
+ payeeNote?: string;
29
+ }
30
+ interface TransactionResponse {
31
+ message: string;
32
+ transactionId: string;
33
+ status: 'PENDING' | 'SUCCESSFUL' | 'FAILED';
34
+ mode?: 'test' | 'live';
35
+ }
36
+ interface WebhookEvent {
37
+ event: string;
38
+ data: {
39
+ id: string;
40
+ amount: number;
41
+ currency: string;
42
+ status: string;
43
+ reference: string;
44
+ customer: {
45
+ phone: string;
46
+ network: string;
47
+ };
48
+ };
49
+ }
50
+
51
+ declare class ChargeResource {
52
+ private client;
53
+ constructor(client: AxiosInstance);
54
+ /**
55
+ * Initiate a Mobile Money Collection
56
+ * @param params Charge parameters
57
+ * @returns Transaction status
58
+ */
59
+ create(params: ChargeParams): Promise<TransactionResponse>;
60
+ }
61
+
62
+ declare class PayoutResource {
63
+ private client;
64
+ constructor(client: AxiosInstance);
65
+ /**
66
+ * Initiate a Mobile Money Disbursement
67
+ * @param params Payout parameters
68
+ * @returns Transaction status
69
+ */
70
+ create(params: PayoutParams): Promise<TransactionResponse>;
71
+ }
72
+
73
+ declare class WebhookResource {
74
+ /**
75
+ * Verify the signature of a PayX webhook request
76
+ * @param payload The raw body of the request
77
+ * @param signature The x-payx-signature header
78
+ * @param secret Your PayX Webhook Secret (found in Developer Dashboard)
79
+ */
80
+ verifySignature(payload: string, signature: string, secret: string): boolean;
81
+ }
82
+
83
+ declare class PayX {
84
+ private client;
85
+ charge: ChargeResource;
86
+ payout: PayoutResource;
87
+ webhooks: WebhookResource;
88
+ constructor(config: PayXConfig);
89
+ }
90
+
91
+ export { type ChargeParams, type Network, PayX, type PayXConfig, type PayoutParams, type TransactionResponse, type WebhookEvent };
@@ -0,0 +1,91 @@
1
+ import { AxiosInstance } from 'axios';
2
+
3
+ interface PayXConfig {
4
+ /**
5
+ * Your PayX API Key (Test or Live)
6
+ */
7
+ apiKey: string;
8
+ /**
9
+ * Optional base URL for the API (defaults to https://api.payx.app/v1)
10
+ */
11
+ baseURL?: string;
12
+ }
13
+ type Network = 'MTN' | 'TELECEL' | 'AIRTELTIGO';
14
+ interface ChargeParams {
15
+ amount: number | string;
16
+ phoneNumber: string;
17
+ network: Network;
18
+ currency?: string;
19
+ payerMessage?: string;
20
+ payeeNote?: string;
21
+ }
22
+ interface PayoutParams {
23
+ amount: number | string;
24
+ phoneNumber: string;
25
+ network: Network;
26
+ currency?: string;
27
+ payerMessage?: string;
28
+ payeeNote?: string;
29
+ }
30
+ interface TransactionResponse {
31
+ message: string;
32
+ transactionId: string;
33
+ status: 'PENDING' | 'SUCCESSFUL' | 'FAILED';
34
+ mode?: 'test' | 'live';
35
+ }
36
+ interface WebhookEvent {
37
+ event: string;
38
+ data: {
39
+ id: string;
40
+ amount: number;
41
+ currency: string;
42
+ status: string;
43
+ reference: string;
44
+ customer: {
45
+ phone: string;
46
+ network: string;
47
+ };
48
+ };
49
+ }
50
+
51
+ declare class ChargeResource {
52
+ private client;
53
+ constructor(client: AxiosInstance);
54
+ /**
55
+ * Initiate a Mobile Money Collection
56
+ * @param params Charge parameters
57
+ * @returns Transaction status
58
+ */
59
+ create(params: ChargeParams): Promise<TransactionResponse>;
60
+ }
61
+
62
+ declare class PayoutResource {
63
+ private client;
64
+ constructor(client: AxiosInstance);
65
+ /**
66
+ * Initiate a Mobile Money Disbursement
67
+ * @param params Payout parameters
68
+ * @returns Transaction status
69
+ */
70
+ create(params: PayoutParams): Promise<TransactionResponse>;
71
+ }
72
+
73
+ declare class WebhookResource {
74
+ /**
75
+ * Verify the signature of a PayX webhook request
76
+ * @param payload The raw body of the request
77
+ * @param signature The x-payx-signature header
78
+ * @param secret Your PayX Webhook Secret (found in Developer Dashboard)
79
+ */
80
+ verifySignature(payload: string, signature: string, secret: string): boolean;
81
+ }
82
+
83
+ declare class PayX {
84
+ private client;
85
+ charge: ChargeResource;
86
+ payout: PayoutResource;
87
+ webhooks: WebhookResource;
88
+ constructor(config: PayXConfig);
89
+ }
90
+
91
+ export { type ChargeParams, type Network, PayX, type PayXConfig, type PayoutParams, type TransactionResponse, type WebhookEvent };
package/dist/index.js ADDED
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ PayX: () => PayX
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+
37
+ // src/client.ts
38
+ var import_axios3 = __toESM(require("axios"));
39
+
40
+ // src/resources/charge.ts
41
+ var import_axios = __toESM(require("axios"));
42
+ var ChargeResource = class {
43
+ client;
44
+ constructor(client) {
45
+ this.client = client;
46
+ }
47
+ /**
48
+ * Initiate a Mobile Money Collection
49
+ * @param params Charge parameters
50
+ * @returns Transaction status
51
+ */
52
+ async create(params) {
53
+ try {
54
+ const response = await this.client.post("/charge", params);
55
+ return response.data;
56
+ } catch (error) {
57
+ if (import_axios.default.isAxiosError(error) && error.response) {
58
+ throw new Error(`PayX Charge Error: ${JSON.stringify(error.response.data)}`);
59
+ }
60
+ throw error;
61
+ }
62
+ }
63
+ };
64
+
65
+ // src/resources/payout.ts
66
+ var import_axios2 = __toESM(require("axios"));
67
+ var PayoutResource = class {
68
+ client;
69
+ constructor(client) {
70
+ this.client = client;
71
+ }
72
+ /**
73
+ * Initiate a Mobile Money Disbursement
74
+ * @param params Payout parameters
75
+ * @returns Transaction status
76
+ */
77
+ async create(params) {
78
+ try {
79
+ const response = await this.client.post("/payout", params);
80
+ return response.data;
81
+ } catch (error) {
82
+ if (import_axios2.default.isAxiosError(error) && error.response) {
83
+ throw new Error(`PayX Payout Error: ${JSON.stringify(error.response.data)}`);
84
+ }
85
+ throw error;
86
+ }
87
+ }
88
+ };
89
+
90
+ // src/resources/webhooks.ts
91
+ var import_crypto = __toESM(require("crypto"));
92
+ var WebhookResource = class {
93
+ /**
94
+ * Verify the signature of a PayX webhook request
95
+ * @param payload The raw body of the request
96
+ * @param signature The x-payx-signature header
97
+ * @param secret Your PayX Webhook Secret (found in Developer Dashboard)
98
+ */
99
+ verifySignature(payload, signature, secret) {
100
+ if (!payload || !signature || !secret) return false;
101
+ const hash = import_crypto.default.createHmac("sha256", secret).update(payload).digest("hex");
102
+ return hash === signature;
103
+ }
104
+ };
105
+
106
+ // src/client.ts
107
+ var PayX = class {
108
+ client;
109
+ charge;
110
+ payout;
111
+ webhooks;
112
+ constructor(config) {
113
+ if (!config.apiKey) {
114
+ throw new Error("PayX API Key is required");
115
+ }
116
+ this.client = import_axios3.default.create({
117
+ baseURL: config.baseURL || "https://api.payx.app/v1",
118
+ headers: {
119
+ "x-api-key": config.apiKey,
120
+ "Content-Type": "application/json"
121
+ }
122
+ });
123
+ this.charge = new ChargeResource(this.client);
124
+ this.payout = new PayoutResource(this.client);
125
+ this.webhooks = new WebhookResource();
126
+ }
127
+ };
128
+ // Annotate the CommonJS export names for ESM import in node:
129
+ 0 && (module.exports = {
130
+ PayX
131
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,94 @@
1
+ // src/client.ts
2
+ import axios3 from "axios";
3
+
4
+ // src/resources/charge.ts
5
+ import axios from "axios";
6
+ var ChargeResource = class {
7
+ client;
8
+ constructor(client) {
9
+ this.client = client;
10
+ }
11
+ /**
12
+ * Initiate a Mobile Money Collection
13
+ * @param params Charge parameters
14
+ * @returns Transaction status
15
+ */
16
+ async create(params) {
17
+ try {
18
+ const response = await this.client.post("/charge", params);
19
+ return response.data;
20
+ } catch (error) {
21
+ if (axios.isAxiosError(error) && error.response) {
22
+ throw new Error(`PayX Charge Error: ${JSON.stringify(error.response.data)}`);
23
+ }
24
+ throw error;
25
+ }
26
+ }
27
+ };
28
+
29
+ // src/resources/payout.ts
30
+ import axios2 from "axios";
31
+ var PayoutResource = class {
32
+ client;
33
+ constructor(client) {
34
+ this.client = client;
35
+ }
36
+ /**
37
+ * Initiate a Mobile Money Disbursement
38
+ * @param params Payout parameters
39
+ * @returns Transaction status
40
+ */
41
+ async create(params) {
42
+ try {
43
+ const response = await this.client.post("/payout", params);
44
+ return response.data;
45
+ } catch (error) {
46
+ if (axios2.isAxiosError(error) && error.response) {
47
+ throw new Error(`PayX Payout Error: ${JSON.stringify(error.response.data)}`);
48
+ }
49
+ throw error;
50
+ }
51
+ }
52
+ };
53
+
54
+ // src/resources/webhooks.ts
55
+ import crypto from "crypto";
56
+ var WebhookResource = class {
57
+ /**
58
+ * Verify the signature of a PayX webhook request
59
+ * @param payload The raw body of the request
60
+ * @param signature The x-payx-signature header
61
+ * @param secret Your PayX Webhook Secret (found in Developer Dashboard)
62
+ */
63
+ verifySignature(payload, signature, secret) {
64
+ if (!payload || !signature || !secret) return false;
65
+ const hash = crypto.createHmac("sha256", secret).update(payload).digest("hex");
66
+ return hash === signature;
67
+ }
68
+ };
69
+
70
+ // src/client.ts
71
+ var PayX = class {
72
+ client;
73
+ charge;
74
+ payout;
75
+ webhooks;
76
+ constructor(config) {
77
+ if (!config.apiKey) {
78
+ throw new Error("PayX API Key is required");
79
+ }
80
+ this.client = axios3.create({
81
+ baseURL: config.baseURL || "https://api.payx.app/v1",
82
+ headers: {
83
+ "x-api-key": config.apiKey,
84
+ "Content-Type": "application/json"
85
+ }
86
+ });
87
+ this.charge = new ChargeResource(this.client);
88
+ this.payout = new PayoutResource(this.client);
89
+ this.webhooks = new WebhookResource();
90
+ }
91
+ };
92
+ export {
93
+ PayX
94
+ };
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "payx-node",
3
+ "version": "1.0.0",
4
+ "description": "The official Node.js SDK for PayX",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "require": "./dist/index.js",
12
+ "import": "./dist/index.mjs"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsup src/index.ts --format cjs,esm --dts",
20
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
21
+ "test": "vitest run"
22
+ },
23
+ "keywords": [
24
+ "payx",
25
+ "payments",
26
+ "ghana",
27
+ "mobile-money"
28
+ ],
29
+ "author": "PayX",
30
+ "license": "MIT",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/payx-app/payx-node.git"
34
+ },
35
+ "bugs": {
36
+ "url": "https://github.com/payx-app/payx-node/issues"
37
+ },
38
+ "homepage": "https://github.com/payx-app/payx-node#readme",
39
+ "engines": {
40
+ "node": ">=16.0.0"
41
+ },
42
+ "dependencies": {
43
+ "axios": "^1.6.0"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^20.19.41",
47
+ "tsup": "^8.5.1",
48
+ "typescript": "^5.9.3",
49
+ "vitest": "^3.2.4"
50
+ }
51
+ }