@delopay/sdk 0.51.0 → 0.52.0

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
@@ -324,6 +324,8 @@ tier unchanged.
324
324
 
325
325
  Delopay signs each outgoing webhook with HMAC-SHA512 over the raw request body and delivers the hex-encoded digest in the `X-Webhook-Signature-512` header. Use `express.raw()` (not `express.json()`) so the bytes reach the verifier unchanged.
326
326
 
327
+ The verified event matches the wire body: `{ merchant_id, event_id, event_type, content: { type, object }, timestamp }`. `event_type` says what happened (e.g. `'payment_succeeded'`); `content.type` tags the payload kind (e.g. `'payment_details'`) — narrow on it to get a typed `content.object` (the payment/refund/dispute, with `payment_id` etc.).
328
+
327
329
  ```typescript
328
330
  import express from 'express';
329
331
  import { Delopay } from '@delopay/sdk';
@@ -339,16 +341,16 @@ app.post('/webhooks/delopay', express.raw({ type: 'application/json' }), async (
339
341
  return res.status(400).send('Invalid signature');
340
342
  }
341
343
 
342
- switch (event.type) {
343
- case 'payment_succeeded':
344
- // fulfil order
345
- break;
346
- case 'payment_failed':
347
- // notify customer
348
- break;
349
- case 'refund_succeeded':
350
- // update records
351
- break;
344
+ if (event.content.type === 'payment_details') {
345
+ const payment = event.content.object; // typed: PaymentResponse
346
+ switch (event.event_type) {
347
+ case 'payment_succeeded':
348
+ // fulfil order — payment.payment_id, payment.amount, payment.currency
349
+ break;
350
+ case 'payment_failed':
351
+ // notify customer — payment.error_message
352
+ break;
353
+ }
352
354
  }
353
355
 
354
356
  res.json({ received: true });
@@ -2434,7 +2434,7 @@ var Webhooks = {
2434
2434
  * req.header('x-webhook-signature-512') ?? '',
2435
2435
  * process.env.DELOPAY_WEBHOOK_SECRET!,
2436
2436
  * );
2437
- * console.log(event.type, event.data);
2437
+ * console.log(event.event_type, event.content.object);
2438
2438
  * res.sendStatus(200);
2439
2439
  * } catch {
2440
2440
  * res.status(400).send('Invalid signature');
@@ -4055,4 +4055,4 @@ export {
4055
4055
  applyBrandingVariables,
4056
4056
  shadowFor
4057
4057
  };
4058
- //# sourceMappingURL=chunk-P45MMRTD.js.map
4058
+ //# sourceMappingURL=chunk-7EHSQIPR.js.map