gembapay 1.3.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 +16 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -76,18 +76,20 @@ console.log(status.network); // 'stripe', 'paypal'
|
|
|
76
76
|
|
|
77
77
|
### Webhook Verification
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
|
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
|
|
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