gembapay 1.2.0 → 1.3.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.
package/README.md CHANGED
@@ -13,7 +13,7 @@ Accept credit cards (via Stripe) and PayPal through a single API. Funds settle d
13
13
 
14
14
  - **One API, two payment methods** — Stripe (cards/Apple Pay/Google Pay) and PayPal
15
15
  - **Direct settlement** — Payments route straight into your own Stripe or PayPal account
16
- - **86+ currencies** — Price in any supported currency
16
+ - **51+ currencies** — Price in any supported currency
17
17
  - **Test mode built-in** — Stripe and PayPal sandbox environments for development
18
18
  - **TypeScript support** — Full type definitions included
19
19
  - **Zero dependencies** — Uses only Node.js built-in modules
@@ -71,23 +71,25 @@ res.redirect(payment.paymentUrl);
71
71
  const status = await gembapay.getPaymentStatus('ORDER-456');
72
72
 
73
73
  console.log(status.status); // 'completed'
74
- console.log(status.network); // 'bsc', 'stripe', 'paypal', etc.
74
+ console.log(status.network); // 'stripe', 'paypal'
75
75
  ```
76
76
 
77
77
  ### Webhook Verification
78
78
 
79
- > **⚠️ SDK update required.** The live GembaPay backend signs webhooks as **bare hex** (no
80
- > `sha256=` prefix) over the **raw request body**. The current `verifyWebhook`/`webhookHandler`
81
- > in this SDK build expect a `sha256=` prefix and hash the parsed body, so they reject genuine
82
- > webhooks until the SDK is updated. Until then, verify manually against the raw body per
83
- > [docs/webhooks.md](../../docs/webhooks.md#signature-verification). Subscription cycles arrive as
84
- > `subscription.payment` (flat payload, no `orderId`), not `payment.completed`.
79
+ GembaPay signs every webhook with HMAC-SHA256 over the **raw request body** and sends the
80
+ signature as **bare hex** (no `sha256=` prefix) in the `X-GembaPay-Signature` header.
81
+ `verifyWebhook`, `parseWebhook` and `webhookHandler` check exactly that. Mount the webhook route
82
+ with `express.raw({ type: 'application/json' })` so the SDK sees the exact bytes that were signed
83
+ (a parsed `express.json()` body is re-serialized as a fallback, which is less reliable).
84
+ Subscription cycles arrive as `subscription.payment` (flat payload, no `orderId`), not
85
+ `payment.completed`. Each `payment.completed` also carries `payment.paymentMethod`
86
+ (`card`, `apple_pay`, `google_pay`, `link`, or `null` for PayPal).
85
87
 
86
88
  ```javascript
87
89
  const express = require('express');
88
90
  const app = express();
89
91
 
90
- app.post('/webhooks/gembapay', express.json(),
92
+ app.post('/webhooks/gembapay', express.raw({ type: 'application/json' }),
91
93
  gembapay.webhookHandler(async (event) => {
92
94
  if (event.event === 'payment.completed') {
93
95
  console.log(`✓ Order ${event.payment.orderId} paid`);
@@ -101,14 +103,15 @@ app.post('/webhooks/gembapay', express.json(),
101
103
  Or verify manually:
102
104
 
103
105
  ```javascript
104
- app.post('/webhooks/gembapay', express.json(), (req, res) => {
106
+ app.post('/webhooks/gembapay', express.raw({ type: 'application/json' }), (req, res) => {
105
107
  const signature = req.headers['x-gembapay-signature'];
106
-
108
+
109
+ // req.body is the raw Buffer here - verify first, parse after
107
110
  if (!gembapay.verifyWebhook(req.body, signature)) {
108
111
  return res.status(401).send('Invalid signature');
109
112
  }
110
-
111
- const { event, payment, testMode } = req.body;
113
+
114
+ const { event, payment } = JSON.parse(req.body.toString('utf8'));
112
115
  // Process event...
113
116
 
114
117
  res.json({ received: true });
@@ -144,7 +147,6 @@ const gembapay = new GembaPay({
144
147
  console.log(gembapay.isTestMode); // true
145
148
  ```
146
149
 
147
- Claim free test tokens at [Developer Resources](https://gembapay.com/developers).
148
150
 
149
151
  ## Express.js Example
150
152
 
@@ -170,8 +172,8 @@ app.post('/api/checkout', express.json(), async (req, res) => {
170
172
  }
171
173
  });
172
174
 
173
- // Webhook endpoint
174
- app.post('/webhooks/gembapay', express.json(),
175
+ // Webhook endpoint - raw body, so the signature is checked on the exact bytes GembaPay signed
176
+ app.post('/webhooks/gembapay', express.raw({ type: 'application/json' }),
175
177
  gembapay.webhookHandler(async (event) => {
176
178
  if (event.event === 'payment.completed') {
177
179
  await fulfillOrder(event.payment.orderId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gembapay",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "GembaPay \u2014 unified payment gateway for Stripe card payments and PayPal. Funds settle directly to the merchant.",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
package/src/index.d.ts CHANGED
@@ -15,7 +15,7 @@ declare module 'gembapay' {
15
15
  orderId: string;
16
16
  /** Payment amount */
17
17
  amount: number;
18
- /** Currency code — 86+ supported (default: 'USD') */
18
+ /** Currency code — 51+ supported (default: 'USD') */
19
19
  currency?: string;
20
20
  /** Payment description */
21
21
  description?: string;
@@ -39,22 +39,27 @@ declare module 'gembapay' {
39
39
  network: 'stripe' | 'paypal';
40
40
  paymentProvider: 'stripe' | 'paypal';
41
41
  payment?: {
42
- txHash?: string;
42
+ reference?: string;
43
43
  tokenSymbol?: string;
44
44
  tokenAmount?: string;
45
45
  };
46
46
  }
47
47
 
48
+ /** Stripe may add other values over time - treat unknown ones like 'card'. */
49
+ export type PaymentMethod = 'card' | 'apple_pay' | 'google_pay' | 'link' | (string & {});
50
+
48
51
  export interface WebhookEvent {
49
52
  event: 'payment.completed' | 'payment.failed';
50
53
  testMode?: boolean;
51
54
  payment: {
52
55
  orderId: string;
53
- txHash?: string;
56
+ reference?: string;
54
57
  network: string;
55
58
  usdAmount: number;
56
59
  tokenAmount?: string;
57
60
  paymentProvider?: string;
61
+ /** How the customer paid. null for PayPal and payments recorded before 2026-10-21. */
62
+ paymentMethod?: PaymentMethod | null;
58
63
  };
59
64
  timestamp: string;
60
65
  }
package/src/index.js CHANGED
@@ -43,7 +43,7 @@ class GembaPay {
43
43
  * @param {Object} params
44
44
  * @param {string} params.orderId - Your unique order identifier
45
45
  * @param {number} params.amount - Payment amount
46
- * @param {string} [params.currency='USD'] - Currency code (86+ supported)
46
+ * @param {string} [params.currency='USD'] - Currency code (51+ supported)
47
47
  * @param {string} [params.description] - Payment description
48
48
  * @returns {Promise<Object>} Payment request with paymentUrl
49
49
  */