gembapay 1.1.0 → 1.1.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/README.md +12 -1
  2. package/package.json +1 -1
  3. package/src/index.js +20 -11
package/README.md CHANGED
@@ -77,6 +77,13 @@ console.log(status.network); // 'bsc', 'stripe', 'paypal', etc.
77
77
 
78
78
  ### Webhook Verification
79
79
 
80
+ > **⚠️ SDK update required.** The live GembaPay backend signs webhooks as **bare hex** (no
81
+ > `sha256=` prefix) over the **raw request body**. The current `verifyWebhook`/`webhookHandler`
82
+ > in this SDK build expect a `sha256=` prefix and hash the parsed body, so they reject genuine
83
+ > webhooks until the SDK is updated. Until then, verify manually against the raw body per
84
+ > [docs/webhooks.md](../../docs/webhooks.md#signature-verification). Subscription cycles arrive as
85
+ > `subscription.payment` (flat payload, no `orderId`), not `payment.completed`.
86
+
80
87
  ```javascript
81
88
  const express = require('express');
82
89
  const app = express();
@@ -112,10 +119,14 @@ app.post('/webhooks/gembapay', express.json(), (req, res) => {
112
119
  ### Transactions & Stats
113
120
 
114
121
  ```javascript
115
- const transactions = await gembapay.listTransactions();
116
122
  const stats = await gembapay.getStats();
123
+ // const transactions = await gembapay.listTransactions(); // see note below
117
124
  ```
118
125
 
126
+ > **Note:** `listTransactions()` currently targets a **dashboard (JWT) endpoint** and returns
127
+ > `401` with an API key. Use `getStats()` / `getPaymentStatus()` programmatically, or view
128
+ > transactions in the dashboard, until the SDK/endpoint is aligned.
129
+
119
130
  ## Test Mode
120
131
 
121
132
  Use test API keys (`gembapay_test_...`) for development. Test mode automatically uses:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gembapay",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "GembaPay — Unified payment gateway for crypto (ETH, BNB, POL, USDC, USDT), Stripe, and PayPal. Non-custodial payments.",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
package/src/index.js CHANGED
@@ -4,7 +4,7 @@ const https = require('https');
4
4
  const crypto = require('crypto');
5
5
 
6
6
  const BASE_URL = 'https://api.gembapay.com';
7
- const VERSION = '1.1.0';
7
+ const VERSION = '1.1.1';
8
8
 
9
9
  class GembaPayError extends Error {
10
10
  constructor(message, statusCode, code) {
@@ -114,16 +114,21 @@ class GembaPay {
114
114
  throw new GembaPayError('webhookSecret is required for signature verification', null, 'missing_webhook_secret');
115
115
  }
116
116
 
117
- const body = typeof payload === 'string' ? payload : JSON.stringify(payload);
118
- const expected = 'sha256=' + crypto
117
+ // `payload` must be the RAW request body (string or Buffer) — the exact bytes GembaPay
118
+ // signed. If an already-parsed object is passed, we best-effort re-serialize (less reliable;
119
+ // mount the webhook route with express.raw and pass the raw body instead).
120
+ const body = Buffer.isBuffer(payload) || typeof payload === 'string'
121
+ ? payload
122
+ : JSON.stringify(payload);
123
+ const expected = crypto
119
124
  .createHmac('sha256', this.webhookSecret)
120
125
  .update(body)
121
- .digest('hex');
126
+ .digest('hex'); // bare hex — GembaPay does NOT prefix with "sha256="
122
127
 
123
- return crypto.timingSafeEqual(
124
- Buffer.from(signature || ''),
125
- Buffer.from(expected)
126
- );
128
+ const a = Buffer.from(signature || '', 'utf8');
129
+ const b = Buffer.from(expected, 'utf8');
130
+ // Length-guard first: timingSafeEqual throws on unequal-length buffers.
131
+ return a.length === b.length && crypto.timingSafeEqual(a, b);
127
132
  }
128
133
 
129
134
  /**
@@ -133,13 +138,17 @@ class GembaPay {
133
138
  */
134
139
  parseWebhook(req) {
135
140
  const signature = req.headers['x-gembapay-signature'];
136
- const body = req.body;
141
+ // Prefer the RAW body — mount the route with express.raw({ type: 'application/json' }).
142
+ // Falls back to req.rawBody, then a re-serialized parsed body (least reliable).
143
+ const raw = Buffer.isBuffer(req.body) ? req.body
144
+ : (req.rawBody != null ? req.rawBody
145
+ : (typeof req.body === 'string' ? req.body : JSON.stringify(req.body)));
137
146
 
138
- if (!this.verifyWebhook(body, signature)) {
147
+ if (!this.verifyWebhook(raw, signature)) {
139
148
  throw new GembaPayError('Invalid webhook signature', 401, 'invalid_signature');
140
149
  }
141
150
 
142
- return body;
151
+ return (Buffer.isBuffer(raw) || typeof raw === 'string') ? JSON.parse(raw.toString('utf8')) : raw;
143
152
  }
144
153
 
145
154
  // ── Express Middleware ────────────────────────────────