@dunbackmeadow/commerce-sdk 0.5.0 → 0.7.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
@@ -177,7 +177,7 @@ catering request.
177
177
  ## Order lifecycle
178
178
 
179
179
  ```
180
- AWAITING_PAYMENT ─▶ PAID ─▶ FULFILLING ─▶ CONFIRMED ─▶ (CANCELLED)
180
+ AWAITING_PAYMENT ─▶ PAID ─▶ FULFILLING ─▶ CONFIRMED ─▶ (CANCELLED | REFUNDED when every delivery failed)
181
181
  │ ├─▶ REFUNDED / REFUND_PENDING restaurant couldn't take it; buyer refunded
182
182
  │ └─▶ NEEDS_ATTENTION Dunback support finishes it by hand
183
183
  └─▶ EXPIRED / CANCELLED
@@ -199,7 +199,7 @@ app.post("/webhooks/dunback", express.raw({ type: "application/json" }), (req, r
199
199
  | Event | `data` |
200
200
  | --- | --- |
201
201
  | `catering.options_ready`, `catering.no_options`, `catering.failed` | CateringRequest |
202
- | `order.created`, `order.confirmed`, `order.payment_failed`, `order.expired`, `order.failed`, `order.needs_attention`, `order.cancelled`, `order.delivery_updated` | Order |
202
+ | `order.created`, `order.confirmed`, `order.payment_failed`, `order.expired`, `order.failed`, `order.needs_attention`, `order.cancelled`, `order.refunded`, `order.delivery_updated` | Order |
203
203
  | `ping` | `{ object: "ping", appId, message }`: sent by **Send test event** in the dashboard |
204
204
 
205
205
  Each webhook is signed as `t=<unix>,v1=<HMAC-SHA256(secret, "<t>.<body>")>`.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { A as AppInfo, V as VenueLocation, C as CuisineQuery, a as Cuisine, b as CuisineCatalog, c as CateringRequestInput, d as CateringRequest, S as SelectOptionInput, O as Order, U as UpdateDeliveryInput, W as WebhookEvent } from './luma-Cza_vuOB.js';
2
- export { e as ATTENDING_STATUSES, f as Address, g as AllergyCoverage, h as Attendee, B as BuildCateringRequestArgs, i as CateringItem, j as CateringOption, k as CateringPolicies, l as CateringRequestStatus, m as CateringServiceStyle, n as CuisineId, o as CustomCuisineId, D as DUNBACK_REGISTRATION_QUESTION, p as DunbackEventSettings, L as LumaEventLike, q as LumaGuestLike, r as OrderDelivery, s as OrderStatus, P as PingData, t as Price, u as PriceLine, v as StandardCuisineId, w as UnavailableReason, x as UnavailableReasonCode, y as UnfedGuests, z as UsdcPaymentInstructions, E as WebhookEventType, F as buildCateringRequest, G as canOrderFood, H as guestsWithUnsharedAllergies, I as toDunbackAddress, J as toDunbackAttendees, K as toVenueLocation } from './luma-Cza_vuOB.js';
1
+ import { A as AppInfo, V as VenueLocation, C as CuisineQuery, a as Cuisine, b as CuisineCatalog, c as CateringRequestInput, d as CateringRequest, S as SelectOptionInput, O as Order, U as UpdateDeliveryInput, W as WebhookEvent } from './luma-D0rL0u8I.js';
2
+ export { e as ATTENDING_STATUSES, f as Address, g as AllergyCoverage, h as Attendee, B as BuildCateringRequestArgs, i as CateringItem, j as CateringOption, k as CateringPolicies, l as CateringRequestStatus, m as CateringServiceStyle, n as CuisineId, o as CustomCuisineId, D as DUNBACK_REGISTRATION_QUESTION, p as DunbackEventSettings, L as LumaEventLike, q as LumaGuestLike, r as OrderDelivery, s as OrderStatus, P as PingData, t as Price, u as PriceLine, v as StandardCuisineId, w as UnavailableReason, x as UnavailableReasonCode, y as UnfedGuests, z as UsdcPaymentInstructions, E as WebhookEventType, F as buildCateringRequest, G as canOrderFood, H as guestsWithUnsharedAllergies, I as toDunbackAddress, J as toDunbackAttendees, K as toVenueLocation } from './luma-D0rL0u8I.js';
3
3
 
4
4
  /** Any non-2xx answer from the Partner API. */
5
5
  declare class DunbackApiError extends Error {
@@ -161,9 +161,10 @@ interface PriceLine {
161
161
  interface Price {
162
162
  currency: "USD";
163
163
  lines: PriceLine[];
164
- restaurantAmount: number;
165
- dunbackCommission: number;
164
+ /** The host's service fee: serviceFeeRate x food and drinks (the `service_fee` line). */
166
165
  dunbackServiceFee: number;
166
+ /** Dunback's service fee rate on catering orders (0.05 = 5%). */
167
+ serviceFeeRate: number;
167
168
  totals: {
168
169
  /** What a USDC payment must be. */
169
170
  usdc: number;
@@ -175,7 +176,6 @@ interface Price {
175
176
  usdc: number;
176
177
  card: number;
177
178
  };
178
- commissionRate: number;
179
179
  }
180
180
  interface CateringItem {
181
181
  name: string;
@@ -381,12 +381,28 @@ interface Order {
381
381
  };
382
382
  confirmedAt: string;
383
383
  } | null;
384
+ /** The latest refund. */
384
385
  refund: {
385
386
  status: "SUCCEEDED" | "PENDING";
386
387
  method: "stripe" | "usdc";
387
388
  amount: number;
388
389
  note?: string;
389
390
  } | null;
391
+ /**
392
+ * Every refund of the order. `reason`: "cancel" (the host cancelled: the
393
+ * restaurant's part), "failed" (the restaurant couldn't take it), or, for one
394
+ * delivery the host isn't at fault for (refunded in full), "cancelled" (by the
395
+ * restaurant), "late" or "not_delivered".
396
+ */
397
+ refunds?: Array<{
398
+ amount: number;
399
+ method: "stripe" | "usdc";
400
+ status: "SUCCEEDED" | "PENDING";
401
+ reason: string;
402
+ detail: string | null;
403
+ at: string;
404
+ restaurantOrderId?: string;
405
+ }>;
390
406
  error: {
391
407
  code: string;
392
408
  message: string;
@@ -394,7 +410,7 @@ interface Order {
394
410
  createdAt: string;
395
411
  updatedAt: string;
396
412
  }
397
- type WebhookEventType = "catering.options_ready" | "catering.no_options" | "catering.failed" | "order.created" | "order.confirmed" | "order.payment_failed" | "order.expired" | "order.failed" | "order.needs_attention" | "order.cancelled" | "order.delivery_updated" | "ping";
413
+ type WebhookEventType = "catering.options_ready" | "catering.no_options" | "catering.failed" | "order.created" | "order.confirmed" | "order.payment_failed" | "order.expired" | "order.failed" | "order.needs_attention" | "order.cancelled" | "order.refunded" | "order.delivery_updated" | "ping";
398
414
  /** `data` of a `ping` event, sent by "Send test event" in the Developer Dashboard. */
399
415
  interface PingData {
400
416
  object: "ping";
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { j as CateringOption, a as Cuisine, p as DunbackEventSettings, O as Order, t as Price } from '../luma-Cza_vuOB.js';
2
+ import { j as CateringOption, a as Cuisine, p as DunbackEventSettings, O as Order, t as Price } from '../luma-D0rL0u8I.js';
3
3
 
4
4
  /**
5
5
  * Optional, unstyled-by-default React building blocks for the three Luma
@@ -196,12 +196,10 @@ per tray, so 2 trays with `serves: 8` feed 16 guests.
196
196
  | --- | --- |
197
197
  | `currency` | `"USD"` |
198
198
  | `lines[]` | `{ code, label, amount }`. `code` is `food`, `delivery`, `restaurant_fee`, `tax`, `platform_fee` or `service_fee`. |
199
- | `restaurantAmount` | What Dunback pays the restaurant |
200
- | `dunbackCommission` | |
201
- | `dunbackServiceFee` | |
199
+ | `dunbackServiceFee` | The host's service fee: `serviceFeeRate` × food and drinks |
200
+ | `serviceFeeRate` | Dunback's service fee rate on catering orders (`0.05` = 5%) |
202
201
  | `totals` | `{ usdc, card, cardProcessingFee }` |
203
202
  | `perGuest` | `{ usdc, card }` |
204
- | `commissionRate` | |
205
203
 
206
204
  The card total is the USDC total grossed up for card processing.
207
205
 
@@ -232,13 +230,14 @@ Errors:
232
230
  | --- | --- |
233
231
  | `id` | `ord_…` |
234
232
  | `object` | `"order"` |
235
- | `status` | `AWAITING_PAYMENT`, `PAID`, `FULFILLING`, `CONFIRMED`, `EXPIRED`, `CANCELLED`, `REFUNDED`, `REFUND_PENDING` or `NEEDS_ATTENTION` |
233
+ | `status` | `AWAITING_PAYMENT`, `PAID`, `FULFILLING`, `CONFIRMED`, `EXPIRED`, `CANCELLED`, `REFUNDED`, `REFUND_PENDING` or `NEEDS_ATTENTION`. A `CONFIRMED` order becomes `REFUNDED` / `REFUND_PENDING` when all its deliveries failed (see Refunds) |
236
234
  | `title`, `summary`, `restaurant`, `deliveryDeadlineLocal`, `timeZone`, `guestCount` | |
237
235
  | `delivery` | `{ address: {address1, address2, city, state, zip, country}, onsiteContact: {name, phone}, deliveryNotes, editable }`. `deliveryNotes` is your note only. `editable` is true while the order is `AWAITING_PAYMENT`. |
238
236
  | `items`, `allergyCoverage`, `unfedGuests`, `price` | Same shapes as the option |
239
237
  | `payment` | See below |
240
238
  | `fulfillment` | `{ restaurantOrderIds, providerPayment: { amount, payTo, txHash, verifiedOnChain, network }, confirmedAt }` |
241
- | `refund` | `{ status: "SUCCEEDED"\|"PENDING", method, amount, note? }` |
239
+ | `refund` | The latest refund: `{ status: "SUCCEEDED"\|"PENDING", method, amount, note? }` |
240
+ | `refunds` | Every refund: `[{ amount, method, status, reason, detail, at, restaurantOrderId? }]`. `reason` is `cancel`, `failed`, `cancelled` (by the restaurant), `late` or `not_delivered` |
242
241
  | `error` | `{ code, message }` |
243
242
 
244
243
  `payment` holds:
@@ -306,9 +305,23 @@ On success you also receive the `order.delivery_updated` webhook.
306
305
  | Order status | Result |
307
306
  | --- | --- |
308
307
  | `AWAITING_PAYMENT` | Cancels the payment links |
309
- | `CONFIRMED`, before the restaurant's deadline | Cancels at the restaurant and refunds |
308
+ | `CONFIRMED`, before the restaurant's deadline | Cancels at the restaurant and refunds the restaurant's part (see Refunds) |
310
309
  | Otherwise | `409 cancel_refused` or `409 invalid_state` |
311
310
 
311
+ ### Refunds
312
+
313
+ | What happened | Refund | Webhook |
314
+ | --- | --- | --- |
315
+ | The host cancels before the restaurant's deadline (`POST /orders/:id/cancel`) | The restaurant's part of the order. Dunback's commission and service fee are kept. A card payment's processing fee is not refunded (Stripe keeps it). | `order.cancelled` |
316
+ | The restaurant couldn't take the order after payment | Everything the host paid | `order.failed` |
317
+ | A delivery was late, failed, or was cancelled by the restaurant | Everything the host paid for that delivery, card processing fee included | `order.refunded` |
318
+
319
+ Card payments are always refunded to the card; USDC refunds are sent to the
320
+ paying address after review. `refunds` lists every refund of the order;
321
+ `refund` is the latest one. When every delivery of an order failed, the order
322
+ becomes `REFUNDED` (or `REFUND_PENDING` while a refund is still due); when only
323
+ some did, it stays `CONFIRMED` and `order.refunded` tells you about each refund.
324
+
312
325
  ### `POST /orders/:id/pay/x402?t=<token>` (x402 resource; no API key, the URL is `payment.usdc.x402Url`)
313
326
 
314
327
  1. Without `PAYMENT-SIGNATURE`, the endpoint returns
@@ -338,7 +351,7 @@ The `Dunback-Signature: t=<unix>,v1=<hex>` header is
338
351
  | Event | `data` |
339
352
  | --- | --- |
340
353
  | `catering.options_ready`, `catering.no_options`, `catering.failed` | CateringRequest |
341
- | `order.created`, `order.confirmed`, `order.payment_failed`, `order.expired`, `order.failed`, `order.needs_attention`, `order.cancelled`, `order.delivery_updated` | Order |
354
+ | `order.created`, `order.confirmed`, `order.payment_failed`, `order.expired`, `order.failed`, `order.needs_attention`, `order.cancelled`, `order.refunded`, `order.delivery_updated` | Order |
342
355
  | `ping` | `{ object: "ping", appId, message }`, plus top-level `livemode`. Sent by **Send test event** in the Developer Dashboard. |
343
356
 
344
357
  The webhook URL, its signing secret (reveal or roll) and the allowed return
@@ -18,7 +18,9 @@ implementation is in [`examples/luma-integration`](../examples/luma-integration)
18
18
 
19
19
  If a payment fails, Luma receives `order.payment_failed` with a message to show
20
20
  the host. If the restaurant can't take the order after payment, the host is
21
- refunded automatically and Luma receives `order.failed`.
21
+ refunded automatically and Luma receives `order.failed`. If a delivery is
22
+ late, fails or is cancelled by the restaurant, the host is refunded in full
23
+ automatically and Luma receives `order.refunded`.
22
24
 
23
25
  ## 1. Setup
24
26
 
@@ -128,8 +130,9 @@ the question.
128
130
  `allergyConsent: true`. If a host asks about allergies in their own question
129
131
  instead, that answer is **not** sent, because the guest didn't see Dunback's
130
132
  consent wording. Before ordering, call `guestsWithUnsharedAllergies(guests)`
131
- and show the host those names, for example: _"Ana and Ben noted allergies
132
- that Dunback can't check. Confirm their meals with them."_ If the host's own
133
+ and show the host those names in plain words, for example: _"These guests'
134
+ allergy notes weren't shared with the restaurant based on their choice: Ana,
135
+ Ben. Please check their meals."_ If the host's own
133
136
  question has the consent wording too, pass `{ otherQuestionsHaveConsent: true }`
134
137
  to both helpers.
135
138
 
@@ -252,6 +255,7 @@ app.post("/webhooks/dunback", express.raw({ type: "application/json" }), (req, r
252
255
  | `order.failed` | Show the message. The host was refunded (`refund`). |
253
256
  | `order.needs_attention` | Show "Dunback support is finishing your order". Dunback contacts the host. |
254
257
  | `order.cancelled` | Show the cancellation and the refund |
258
+ | `order.refunded` | A delivery was late, failed or was cancelled by the restaurant: show the refund (`refunds`) |
255
259
 
256
260
  ## 8. Cancellation
257
261
 
@@ -259,8 +263,13 @@ app.post("/webhooks/dunback", express.raw({ type: "application/json" }), (req, r
259
263
 
260
264
  - **Before payment:** the payment links are cancelled.
261
265
  - **After confirmation, before the restaurant's order deadline:** the order is
262
- cancelled at the restaurant and the host is refunded. Card refunds are
263
- automatic; USDC refunds are sent after review.
266
+ cancelled at the restaurant and the host is refunded the restaurant's part
267
+ of the order. Dunback's commission and service fee are kept, and so is the
268
+ card processing fee (Stripe keeps it). Card refunds are automatic; USDC
269
+ refunds are sent after review.
270
+
271
+ If the host isn't at fault (a late or failed delivery, or the restaurant
272
+ cancelled), everything they paid is refunded, card processing fee included.
264
273
 
265
274
  After the deadline, the call fails with `cancel_refused`.
266
275
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dunbackmeadow/commerce-sdk",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Official Node.js/TypeScript SDK for the Dunback Meadow commerce API. Order from your app or agent and pay by card (Stripe) or USDC. Event catering is available now; more product types are coming.",
5
5
  "repository": {
6
6
  "type": "git",