@snexon/payoniq-lite 1.0.0 → 1.0.1

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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +191 -0
  3. package/package.json +12 -2
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Snexon. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,191 @@
1
+ # @snexon/payoniq-lite
2
+
3
+ Official Node.js & TypeScript SDK for the **Payoniq (Payonic)** payment gateway by [Snexon](https://snexon.com).
4
+
5
+ Integrate instant, peer-to-peer mobile payments (bKash, Nagad, Rocket, Upay) and crypto into your Node.js, Next.js, Express, or Remix applications with zero third-party gateway transaction cuts.
6
+
7
+ ---
8
+
9
+ ## Features
10
+
11
+ - 🚀 **Zero Boilerplate:** Initialize in seconds with typed methods for session creation and verification.
12
+ - 🔒 **Cryptographic Webhook Security:** Timing-safe HMAC-SHA256 signature verification with built-in replay-attack prevention.
13
+ - 📱 **Multi-Wallet Support:** Direct integration with bKash, Nagad, Rocket, Upay & crypto gateways.
14
+ - 📦 **Fully Typed:** 100% written in TypeScript with complete type definitions and JSDoc documentation.
15
+ - ⚡ **Lightweight & Dependency-Free:** Zero bloated dependencies, built directly on native Node.js crypto and modern fetch.
16
+
17
+ ---
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ # Using npm
23
+ npm install @snexon/payoniq-lite
24
+
25
+ # Using pnpm
26
+ pnpm add @snexon/payoniq-lite
27
+
28
+ # Using yarn
29
+ yarn add @snexon/payoniq-lite
30
+ ```
31
+
32
+ ---
33
+
34
+ ## Quick Start
35
+
36
+ ### 1. Initialize the Client
37
+
38
+ ```typescript
39
+ import { PayoniqClient } from "@snexon/payoniq-lite";
40
+
41
+ const payoniq = new PayoniqClient({
42
+ apiKey: process.env.PAYONIQ_API_KEY!,
43
+ apiSecret: process.env.PAYONIQ_API_SECRET!,
44
+ baseUrl: process.env.PAYONIQ_BASE_URL || "http://localhost:4000",
45
+ });
46
+ ```
47
+
48
+ ---
49
+
50
+ ### 2. Create a Checkout Session
51
+
52
+ #### Next.js App Router (`app/api/checkout/route.ts`)
53
+
54
+ ```typescript
55
+ import { NextResponse } from "next/server";
56
+ import { PayoniqClient } from "@snexon/payoniq-lite";
57
+
58
+ const payoniq = new PayoniqClient({
59
+ apiKey: process.env.PAYONIQ_API_KEY!,
60
+ apiSecret: process.env.PAYONIQ_API_SECRET!,
61
+ baseUrl: process.env.PAYONIQ_BASE_URL || "http://localhost:4000",
62
+ });
63
+
64
+ export async function POST(req: Request) {
65
+ const { amount, orderId, customerName, customerPhone } = await req.json();
66
+
67
+ const session = await payoniq.sessions.create({
68
+ orderId: orderId || `ORD-${Date.now()}`,
69
+ amount: amount,
70
+ currency: "BDT",
71
+ method: "ANY", // "BKASH" | "NAGAD" | "ROCKET" | "UPAY" | "USDT" | "ANY"
72
+ customerName,
73
+ customerPhone,
74
+ successUrl: "https://yourstore.com/order/success",
75
+ cancelUrl: "https://yourstore.com/cart",
76
+ expiryMinutes: 15,
77
+ });
78
+
79
+ return NextResponse.json({
80
+ checkoutUrl: session.checkoutUrl,
81
+ orderHash: session.orderHash,
82
+ });
83
+ }
84
+ ```
85
+
86
+ #### Node.js / Express (`server.js`)
87
+
88
+ ```javascript
89
+ const express = require("express");
90
+ const { PayoniqClient } = require("@snexon/payoniq-lite");
91
+
92
+ const app = express();
93
+ app.use(express.json());
94
+
95
+ const payoniq = new PayoniqClient({
96
+ apiKey: process.env.PAYONIQ_API_KEY,
97
+ apiSecret: process.env.PAYONIQ_API_SECRET,
98
+ baseUrl: process.env.PAYONIQ_BASE_URL || "http://localhost:4000",
99
+ });
100
+
101
+ app.post("/api/checkout", async (req, res) => {
102
+ try {
103
+ const session = await payoniq.sessions.create({
104
+ orderId: `ORD-${Date.now()}`,
105
+ amount: req.body.amount,
106
+ currency: "BDT",
107
+ });
108
+ res.json({ checkoutUrl: session.checkoutUrl });
109
+ } catch (error) {
110
+ res.status(500).json({ error: error.message });
111
+ }
112
+ });
113
+
114
+ app.listen(3000, () => console.log("Server running on port 3000"));
115
+ ```
116
+
117
+ ---
118
+
119
+ ### 3. Verify Webhooks & Process Payments
120
+
121
+ Protect your application against spoofing and replay attacks with timing-safe HMAC-SHA256 signature verification.
122
+
123
+ #### Next.js Route (`app/api/webhooks/payoniq/route.ts`)
124
+
125
+ ```typescript
126
+ import { NextResponse } from "next/server";
127
+ import { PayoniqClient } from "@snexon/payoniq-lite";
128
+
129
+ const payoniq = new PayoniqClient({
130
+ apiKey: process.env.PAYONIQ_API_KEY!,
131
+ apiSecret: process.env.PAYONIQ_API_SECRET!,
132
+ });
133
+
134
+ export async function POST(req: Request) {
135
+ const rawBody = await req.text();
136
+ const signature = req.headers.get("x-payoniq-signature") || "";
137
+
138
+ try {
139
+ // Validates signature and verifies timestamp (rejects if older than 300s)
140
+ const event = payoniq.webhooks.constructEvent(rawBody, signature);
141
+
142
+ if (event.event === "payment.settled") {
143
+ const { orderId, amount, trxId, method } = event.data;
144
+ console.log(`✅ Payment settled for ${orderId}: ${amount} BDT via ${method} (TrxID: ${trxId})`);
145
+
146
+ // Update order status in your database
147
+ // await markOrderAsPaid(orderId, trxId);
148
+ }
149
+
150
+ return NextResponse.json({ received: true });
151
+ } catch (err: any) {
152
+ return NextResponse.json(
153
+ { error: "Webhook verification failed", message: err.message },
154
+ { status: 400 }
155
+ );
156
+ }
157
+ }
158
+ ```
159
+
160
+ ---
161
+
162
+ ## API Reference
163
+
164
+ ### `PayoniqClient(options)`
165
+ - `apiKey` *(string, required)*: Merchant API key from dashboard.
166
+ - `apiSecret` *(string, optional)*: Required for cryptographic webhook verification.
167
+ - `baseUrl` *(string, optional)*: Payoniq daemon/server endpoint (defaults to `http://localhost:4000`).
168
+
169
+ ### `payoniq.sessions.create(options)`
170
+ Creates a non-custodial checkout session.
171
+ - `amount` *(number, required)*: Payment amount.
172
+ - `orderId` *(string, required)*: Unique merchant order reference.
173
+ - `currency` *(string)*: Currency code (default: `"BDT"`).
174
+ - `method` *(string)*: `"ANY"` | `"BKASH"` | `"NAGAD"` | `"ROCKET"` | `"UPAY"` | `"USDT"`.
175
+ - `customerName` *(string, optional)*: Customer full name.
176
+ - `customerPhone` *(string, optional)*: Customer phone number.
177
+ - `successUrl` *(string, optional)*: Redirect URL upon successful payment.
178
+ - `cancelUrl` *(string, optional)*: Redirect URL if cancelled.
179
+ - `expiryMinutes` *(number, optional)*: Session lifetime (default: 15).
180
+
181
+ ### `payoniq.sessions.get(orderHash)`
182
+ Retrieves an existing payment session and live reconciliation state.
183
+
184
+ ### `payoniq.webhooks.constructEvent(rawBody, signatureHeader)`
185
+ Validates the HMAC-SHA256 signature and returns typed event data. Throws `PayoniqError` if invalid or expired.
186
+
187
+ ---
188
+
189
+ ## License
190
+
191
+ MIT © [Snexon](https://snexon.com)
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@snexon/payoniq-lite",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Official TypeScript & Node.js SDK for Payoniq Gateway by Snexon",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
8
- "dist"
8
+ "dist",
9
+ "README.md",
10
+ "LICENSE"
9
11
  ],
10
12
  "publishConfig": {
11
13
  "access": "public"
@@ -14,6 +16,14 @@
14
16
  "build": "tsc",
15
17
  "prepublishOnly": "npm run build"
16
18
  },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/snexon/payoniq"
22
+ },
23
+ "homepage": "https://snexon.com",
24
+ "bugs": {
25
+ "url": "https://github.com/snexon/payoniq/issues"
26
+ },
17
27
  "keywords": [
18
28
  "payoniq",
19
29
  "payonic",