@kuvarpay/sdk 1.3.0 → 1.3.15

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 (2) hide show
  1. package/README.md +98 -129
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,162 +1,131 @@
1
1
  # KuvarPay Server SDK
2
2
 
3
- Backend-focused SDK for creating and verifying checkout sessions, subscription sessions, invoices, and transactions using your Business SECRET API key.
3
+ Official Node.js SDK for integrating **KuvarPay**, the ultimate fiat gateway for the crypto economy. This SDK allows you to handle checkout sessions, direct crypto-to-fiat transactions, recurring subscriptions, and split payments with ease.
4
4
 
5
- Works with Node 18+ (global `fetch`) or any environment where you can supply a `fetch` implementation. Also includes quick PHP cURL examples.
5
+ Detailed documentation is available at [developers.kuvarpay.com](https://developers.kuvarpay.com).
6
6
 
7
- ## Installation
7
+ [![npm version](https://badge.fury.io/js/@kuvarpay%2Fsdk.svg)](https://badge.fury.io/js/@kuvarpay%2Fsdk)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
9
 
9
- This repository includes the SDK source files. You can copy `server-sdk/index.js` (CommonJS) or `server-sdk/index.mjs` (ESM) into your backend project, or import them via your build tooling.
10
+ ## 🚀 Installation
10
11
 
11
- > Requirements:
12
- > - Business ID
13
- > - SECRET API Key (server-only)
14
- > - Payment API Base URL (e.g., `https://pay.kuvarpay.com` or your payment host)
12
+ ```bash
13
+ npm install @kuvarpay/sdk
14
+ ```
15
+
16
+ ## 🛠️ Quick Start (Speed Mode)
15
17
 
16
- ## Node (CommonJS) Usage
18
+ Initiate a payment and get a crypto deposit address in one line of code:
17
19
 
18
- ```js
19
- // index.js (Node 18+)
20
- const { KuvarPayServer } = require('./server-sdk/index.js');
20
+ ```javascript
21
+ const { KuvarPayServer } = require('@kuvarpay/sdk');
21
22
 
22
23
  const kv = new KuvarPayServer({
23
- baseUrl: process.env.PAYMENT_API_BASE_URL, // e.g., https://pay.kuvarpay.com
24
- businessId: process.env.KUVARPAY_BUSINESS_ID,
25
- secretApiKey: process.env.KUVARPAY_SECRET_API_KEY,
24
+ businessId: 'your_business_id',
25
+ secretApiKey: 'rsp_secret_...' // Starts with rsp_secret_
26
26
  });
27
27
 
28
- async function verify(sessionId) {
29
- const result = await kv.verifyPayment(sessionId);
30
- console.log('Verified?', result.verified, 'status:', result.status);
28
+ async function startPayment() {
29
+ const payment = await kv.createDirectPayment({
30
+ amount: 5000,
31
+ currency: 'NGN',
32
+ fromCurrency: 'USDT',
33
+ fromNetwork: 'BSC',
34
+ customerEmail: 'customer@example.com'
35
+ });
36
+
37
+ console.log('Send USDT to:', payment.depositAddress);
38
+ console.log('Exact amount:', payment.fromAmount); // e.g. 3.76 USDT
31
39
  }
40
+ ```
32
41
 
33
- async function session(sessionId) {
34
- const s = await kv.getSessionStatus(sessionId);
35
- console.log('Session:', s);
36
- }
42
+ ---
37
43
 
38
- async function txn(transactionId) {
39
- const t = await kv.getTransactionStatus(transactionId);
40
- console.log('Transaction:', t);
41
- }
42
- ```
44
+ ## ⚙️ Configuration
43
45
 
44
- ## Node (ESM) Usage
46
+ The SDK defaults to the KuvarPay Production API (`https://payment.kuvarpay.com`).
45
47
 
46
- ```js
47
- // index.mjs (Node 18+)
48
- import { KuvarPayServer } from './server-sdk/index.mjs';
48
+ | Option | Description | Env Fallback |
49
+ | :--- | :--- | :--- |
50
+ | `businessId` | Your KuvarPay Business ID | - |
51
+ | `secretApiKey` | Your Production Secret Key | - |
52
+ | `baseUrl` | Overrides the API endpoint | `KUVARPAY_API_BASE_URL` |
53
+ | `timeoutMs` | Request timeout (default 60s) | - |
49
54
 
50
- const kv = new KuvarPayServer({
51
- baseUrl: process.env.PAYMENT_API_BASE_URL,
52
- businessId: process.env.KUVARPAY_BUSINESS_ID,
53
- secretApiKey: process.env.KUVARPAY_SECRET_API_KEY,
54
- });
55
+ ---
55
56
 
56
- const result = await kv.verifyPayment('sess_123');
57
- console.log(result);
58
- ```
57
+ ## 📖 API Reference
59
58
 
60
- ### Node < 18
59
+ ### 💳 Payments & Transactions
61
60
 
62
- Provide your own `fetchImpl` (e.g., from `node-fetch`) when constructing:
61
+ | Method | Description |
62
+ | :--- | :--- |
63
+ | `createDirectPayment(data)` | **Recommended**. Creates a session & transaction in one call. |
64
+ | `createCheckoutSession(data)` | Creates a checkout session (returns `approvalUrl`). |
65
+ | `createTransaction(data)` | Manually initiates a crypto transaction for an existing session. |
66
+ | `verifyPayment(sessionId)` | Convenience method to check if a payment is confirmed. |
67
+ | `getSessionStatus(sessionId)`| Fetches full session/transaction status. |
63
68
 
64
- ```js
65
- const fetch = (...args) => import('node-fetch').then(mod => mod.default(...args));
66
- const kv = new KuvarPayServer({ baseUrl, businessId, secretApiKey, fetchImpl: fetch });
67
- ```
69
+ ### 📈 Subaccounts & Split Payments
68
70
 
69
- ## PHP cURL Examples
70
-
71
- Replace `PAYMENT_API_BASE_URL`, `BUSINESS_ID`, and `SECRET_API_KEY` with your values.
72
-
73
- ### Verify Payment (Checkout Session)
74
-
75
- ```php
76
- $base = getenv('PAYMENT_API_BASE_URL');
77
- $businessId = getenv('KUVARPAY_BUSINESS_ID');
78
- $secret = getenv('KUVARPAY_SECRET_API_KEY');
79
- $sessionId = 'sess_123';
80
-
81
- $ch = curl_init("$base/api/v1/checkout-sessions/" . urlencode($sessionId));
82
- curl_setopt($ch, CURLOPT_HTTPHEADER, [
83
- "Accept: application/json",
84
- "X-API-Key: $secret",
85
- "X-Business-ID: $businessId"
86
- ]);
87
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
88
- $resp = curl_exec($ch);
89
- $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
90
- curl_close($ch);
91
-
92
- if ($statusCode >= 200 && $statusCode < 300) {
93
- $data = json_decode($resp, true);
94
- $status = $data['status'] ?? ($data['data']['status'] ?? null);
95
- $verified = ($status === 'COMPLETED');
96
- // handle $verified
97
- } else {
98
- // handle error
99
- }
100
- ```
71
+ | Method | Description |
72
+ | :--- | :--- |
73
+ | `createSubaccount(data)` | Create a vendor subaccount for split settlements. |
74
+ | `listSubaccounts()` | Fetch all subaccounts for your business. |
75
+ | `createSplitGroup(data)` | Define percentage-based distribution between subaccounts. |
101
76
 
102
- ### Transaction Status
103
-
104
- ```php
105
- $transactionId = 'tx_123';
106
- $ch = curl_init("$base/api/v1/transactions/" . urlencode($transactionId));
107
- curl_setopt($ch, CURLOPT_HTTPHEADER, [
108
- "Accept: application/json",
109
- "X-API-Key: $secret",
110
- "X-Business-ID: $businessId"
111
- ]);
112
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
113
- $resp = curl_exec($ch);
114
- $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
115
- curl_close($ch);
116
-
117
- if ($statusCode >= 200 && $statusCode < 300) {
118
- $data = json_decode($resp, true);
119
- $status = $data['status'] ?? null;
120
- // handle $status
121
- } else {
122
- // handle error
123
- }
124
- ```
77
+ ### 🔄 Subscriptions
78
+
79
+ | Method | Description |
80
+ | :--- | :--- |
81
+ | `createDirectSubscription(data)` | Initiates a subscription setup and returns an approval URL. |
82
+ | `renewSubscription(subId)` | Manually trigger a renewal for an active allowance. |
83
+ | `cancelSubscription(subId)` | Hard-cancel a customer subscription. |
84
+ | `createMeteredInvoice(subId, data)`| Charge a customer based on usage (Metered billing). |
85
+
86
+ ### 🏦 Banks & Verification
87
+
88
+ | Method | Description |
89
+ | :--- | :--- |
90
+ | `getBanks(currency)` | List supported settlement banks for a specific currency. |
91
+ | `resolveBankAccount(data)` | Verify bank account names before creating subaccounts. |
92
+
93
+ ---
94
+
95
+ ## 🔒 Security: Webhook Verification
125
96
 
126
- ## API Reference
97
+ Verify that incoming webhooks are genuinely from KuvarPay using HMAC-SHA256:
127
98
 
128
- Payments:
129
- - `createCheckoutSession(data)` → `{ sessionId, authToken?, approvalUrl?, raw }`
130
- - `getSessionStatus(sessionId)` → `{ sessionId, status, transactionId?, raw }`
131
- - `getTransactionStatus(transactionId)` → `{ transactionId, status, raw }`
132
- - `verifyPayment(sessionId)` → `{ verified: boolean, status, sessionId, transactionId?, raw }`
99
+ ```javascript
100
+ app.post('/webhooks/kuvarpay', (req, res) => {
101
+ const signature = req.headers['x-kuvarpay-signature'];
102
+ const payload = req.body; // Raw body object
133
103
 
134
- Subscriptions:
135
- - `createSubscriptionCheckoutSession(data)` → `{ sessionId, approvalUrl?, raw }`
136
- - `getSubscriptionCheckoutSession(id)` → full session details
137
- - `confirmSubscriptionCheckoutSession(id, body?)` → confirmation response
138
- - `getSubscription(subscriptionId)` → full subscription details
139
- - `cancelSubscription(subscriptionId, body?)` → cancellation response
140
- - `createMeteredInvoice(subscriptionId, invoiceData)` → invoice response
141
- - `createSubscriptionInvoice(subscriptionId, invoiceData)` → alias to metered invoice
142
- - `scheduleSubscriptionInvoice(subscriptionId, invoiceData)` → enforces `chargeSchedule: 'SCHEDULED'`
143
- - `createRenewalCheckoutSession(body)` → renewal checkout creation
144
- - `renewSubscription(subscriptionId, body?)` → direct renew trigger
104
+ const isValid = kv.verifyWebhookSignature(payload, signature);
145
105
 
146
- Relay Authorization (metered):
147
- - `createRelayAuthorization(body)`
148
- - `getRelayAuthorizationStatus(body)`
149
- - `revokeRelayAuthorization(body)` (supports legacy path via `{ useLegacyPath: true }`)
106
+ if (isValid) {
107
+ // Process payment (e.g. status === 'completed')
108
+ res.status(200).send();
109
+ } else {
110
+ res.status(401).send('Invalid signature');
111
+ }
112
+ });
113
+ ```
114
+
115
+ ---
150
116
 
151
- Notes:
152
- - Status values commonly include `PENDING`, `ARMED`, `PROCESSING`, `COMPLETED`, `FAILED`, `EXPIRED`, `CANCELLED`, etc.
153
- - `verifyPayment` returns `verified = true` when `status === 'COMPLETED'`.
117
+ ## 🧩 TypeScript Support
154
118
 
155
- ## Security
119
+ This SDK includes a full `index.d.ts` definition file. You get auto-completion and type checking out of the box.
120
+
121
+ ```typescript
122
+ import { KuvarPayServer } from '@kuvarpay/sdk';
123
+
124
+ const kv = new KuvarPayServer({ ... });
125
+ ```
156
126
 
157
- - Always keep your SECRET API key in server-side environment variables. Never expose it to the browser.
158
- - Use HTTPS for all API calls.
127
+ ---
159
128
 
160
- ## Parity with Client SDK
129
+ ## 📄 License
161
130
 
162
- The Server SDK provides server-side equivalents of the Client SDK’s network operations (creating sessions, fetching statuses, managing subscriptions, and invoices). It does not implement browser UI features like `openPayment(...)` / `openSubscription(...)` modals, postMessage callbacks, or iframe overlays. Use the Client SDK in the browser for UI, and the Server SDK on your backend for secure API operations.
131
+ MIT © KuvarPay Development Team
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kuvarpay/sdk",
3
- "version": "1.3.0",
3
+ "version": "1.3.15",
4
4
  "description": "Official KuvarPay Server SDK for Node.js",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",