@delopay/sdk 0.51.0 → 0.53.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 });
@@ -450,10 +450,17 @@ var Customers = class {
450
450
  return this.request("DELETE", `/customers/${encodeURIComponent(customerId)}`);
451
451
  }
452
452
  /**
453
- * List customers, optionally filtered by email.
453
+ * List customers, optionally filtered by email, shop (`profile_id`), or
454
+ * project (`project_id`).
454
455
  *
455
456
  * @param params - Optional filter and pagination parameters.
456
457
  * @returns Array of customer objects.
458
+ *
459
+ * @example
460
+ * ```typescript
461
+ * // Customers who have transacted in a specific shop.
462
+ * const customers = await delopay.customers.list({ profile_id: 'pro_abc123' });
463
+ * ```
457
464
  */
458
465
  async list(params) {
459
466
  return this.request("GET", "/customers/list", {
@@ -461,12 +468,38 @@ var Customers = class {
461
468
  });
462
469
  }
463
470
  // --- OLAP extensions (Task 4.6) ---
464
- /** List customers with count. `GET /customers/list-with-count` */
471
+ /**
472
+ * List customers with count. Supports the same `profile_id` / `project_id`
473
+ * shop filters as {@link list}. `GET /customers/list-with-count`
474
+ */
465
475
  async listWithCount(params) {
466
476
  return this.request("GET", "/customers/list-with-count", {
467
477
  query: params
468
478
  });
469
479
  }
480
+ /**
481
+ * List customers scoped to the authenticated dashboard user's shop
482
+ * (business profile). The JWT auto-scopes to its own `profile`; an explicit
483
+ * `profile_id` / `project_id` outside that scope is rejected with
484
+ * `AccessForbidden`. `GET /customers/profile/list`
485
+ *
486
+ * @param params - Optional filter and pagination parameters.
487
+ * @returns Array of customer objects.
488
+ */
489
+ async listByProfile(params) {
490
+ return this.request("GET", "/customers/profile/list", {
491
+ query: params
492
+ });
493
+ }
494
+ /**
495
+ * Profile-scoped variant of {@link listWithCount}.
496
+ * `GET /customers/profile/list-with-count`
497
+ */
498
+ async listByProfileWithCount(params) {
499
+ return this.request("GET", "/customers/profile/list-with-count", {
500
+ query: params
501
+ });
502
+ }
470
503
  /** List mandates for a customer. `GET /customers/{customerId}/mandates` */
471
504
  async listMandates(customerId) {
472
505
  return this.request("GET", `/customers/${encodeURIComponent(customerId)}/mandates`);
@@ -1085,11 +1118,7 @@ var Payments = class {
1085
1118
  * ```
1086
1119
  */
1087
1120
  async listAttempts(paymentId, options) {
1088
- return this.request(
1089
- "GET",
1090
- `/payments/${encodeURIComponent(paymentId)}/attempts`,
1091
- options
1092
- );
1121
+ return this.request("GET", `/payments/${encodeURIComponent(paymentId)}/attempts`, options);
1093
1122
  }
1094
1123
  /**
1095
1124
  * Update an existing payment intent before it is confirmed.
@@ -2434,7 +2463,7 @@ var Webhooks = {
2434
2463
  * req.header('x-webhook-signature-512') ?? '',
2435
2464
  * process.env.DELOPAY_WEBHOOK_SECRET!,
2436
2465
  * );
2437
- * console.log(event.type, event.data);
2466
+ * console.log(event.event_type, event.content.object);
2438
2467
  * res.sendStatus(200);
2439
2468
  * } catch {
2440
2469
  * res.status(400).send('Invalid signature');
@@ -4055,4 +4084,4 @@ export {
4055
4084
  applyBrandingVariables,
4056
4085
  shadowFor
4057
4086
  };
4058
- //# sourceMappingURL=chunk-P45MMRTD.js.map
4087
+ //# sourceMappingURL=chunk-QH5ESES3.js.map