@dunbackmeadow/commerce-sdk 0.7.0 → 0.9.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 +256 -256
- package/dist/index.d.ts +34 -5
- package/dist/index.js +49 -4
- package/dist/{luma-D0rL0u8I.d.ts → luma-D2AucdDY.d.ts} +243 -8
- package/dist/react/index.d.ts +27 -4
- package/dist/react/index.js +108 -9
- package/docs/API_REFERENCE.md +72 -9
- package/docs/LUMA_INTEGRATION_GUIDE.md +45 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,256 +1,256 @@
|
|
|
1
|
-
# Dunback Meadow Commerce SDK
|
|
2
|
-
|
|
3
|
-
`@dunbackmeadow/commerce-sdk` lets your app or agent order **event catering**
|
|
4
|
-
from restaurants on Dunback Meadow. More product types will follow. Buyers pay
|
|
5
|
-
**by card (Stripe)** or in **USDC on Polygon** (a wallet transfer or x402).
|
|
6
|
-
|
|
7
|
-
Dunback handles three things:
|
|
8
|
-
|
|
9
|
-
- **Restaurant selection.** Its catering agent finds restaurants that serve
|
|
10
|
-
the chosen cuisine, deliver to the venue, and can make the event time.
|
|
11
|
-
- **Allergy-aware menus.** Each guest gets a dish that is safe for their
|
|
12
|
-
allergies and diet, according to the restaurant's allergen data.
|
|
13
|
-
- **Payment and placement.** Dunback verifies the buyer's payment, pays the
|
|
14
|
-
restaurant, and confirms the order back to you.
|
|
15
|
-
|
|
16
|
-
```
|
|
17
|
-
Your app Dunback Meadow Restaurant agent
|
|
18
|
-
──────── ────────────── ────────────────
|
|
19
|
-
catering.create(guests) ───────▶ catering agent composes 3 options ───▶ quote_cart (prices)
|
|
20
|
-
◀── webhook catering.options_ready (price + fee breakdowns)
|
|
21
|
-
catering.select(option) ───────▶ order + payment links
|
|
22
|
-
payer pays (card / USDC / x402) ▶ verifies payment (Stripe API / on-chain)
|
|
23
|
-
pays restaurant in USDC via x402 ─────▶ books the order
|
|
24
|
-
◀── webhook order.confirmed
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Install
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
npm install @dunbackmeadow/commerce-sdk
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
You need Node 18 or later. React is optional and only needed for `@dunbackmeadow/commerce-sdk/react`.
|
|
34
|
-
|
|
35
|
-
## Credentials
|
|
36
|
-
|
|
37
|
-
Get your credentials in the **Dunback Developer Dashboard**
|
|
38
|
-
(<https://dunbackmeadow.com/developer>, or Menu → More… → Developer Dashboard
|
|
39
|
-
in the Dunback app):
|
|
40
|
-
|
|
41
|
-
1. Apply for developer access (individual or business). Dunback reviews it,
|
|
42
|
-
usually within 2 business days.
|
|
43
|
-
2. Create an **app**. Each app has a **sandbox** and a **production** environment.
|
|
44
|
-
3. In each environment, create the **API key** and set your **webhook URL**
|
|
45
|
-
and **allowed return hosts**.
|
|
46
|
-
|
|
47
|
-
| What | Example | Where it lives |
|
|
48
|
-
| --- | --- | --- |
|
|
49
|
-
| API key | `dbk_test_app-k3m9x2q7w4ze_…` / `dbk_live_app-k3m9x2q7w4ze_…` | Your servers only. Never put it in a browser or a mobile app. Shown once when created. |
|
|
50
|
-
| Webhook signing secret | `whsec_…` | Your servers; used to verify `Dunback-Signature`. One per environment. |
|
|
51
|
-
| Allowed return hosts | `lu.ma` | Set in the dashboard; Stripe success and cancel URLs must be on these hosts. |
|
|
52
|
-
|
|
53
|
-
One key per app and environment at a time: to rotate, delete the key in the
|
|
54
|
-
dashboard and create a new one. A deleted key stops working within a minute.
|
|
55
|
-
|
|
56
|
-
The client picks the environment from the key:
|
|
57
|
-
|
|
58
|
-
| Key | Base URL |
|
|
59
|
-
| --- | --- |
|
|
60
|
-
| `dbk_test_…` | `https://sandbox.dunbackmeadow.com/api/partner/v1` |
|
|
61
|
-
| `dbk_live_…` | `https://dunbackmeadow.com/api/partner/v1` |
|
|
62
|
-
|
|
63
|
-
In the sandbox:
|
|
64
|
-
|
|
65
|
-
- Stripe runs in test mode.
|
|
66
|
-
- Orders go to Dunback's test restaurants.
|
|
67
|
-
- USDC payments use small real amounts on Polygon. There is no testnet USDC support yet.
|
|
68
|
-
|
|
69
|
-
Check a key with `await dunback.me()`: it returns the app and environment.
|
|
70
|
-
|
|
71
|
-
## Quick start
|
|
72
|
-
|
|
73
|
-
```ts
|
|
74
|
-
import { DunbackClient } from "@dunbackmeadow/commerce-sdk";
|
|
75
|
-
|
|
76
|
-
const dunback = new DunbackClient({ apiKey: process.env.DUNBACK_API_KEY! });
|
|
77
|
-
|
|
78
|
-
// 1. Send the event and guest list
|
|
79
|
-
const request = await dunback.catering.create({
|
|
80
|
-
partnerReference: "luma:evt-AbC123",
|
|
81
|
-
event: { name: "Founders Dinner", startsAt: "2026-11-14T02:00:00Z", timeZone: "America/Los_Angeles" },
|
|
82
|
-
cuisine: "mexican",
|
|
83
|
-
deliveryAddress: { address1: "100 University Ave", city: "Palo Alto", state: "CA", zip: "94301" },
|
|
84
|
-
onsiteContact: { name: "Sam Host", phone: "+14155550100" },
|
|
85
|
-
host: { name: "Sam Host", email: "sam@example.com" },
|
|
86
|
-
attendees: [
|
|
87
|
-
{ name: "Ana", email: "ana@example.com", allergies: "peanuts", allergyConsent: true },
|
|
88
|
-
{ name: "Ben", phone: "+14155550101", allergies: "" },
|
|
89
|
-
{ name: "Cleo", dietaryPreferences: "vegetarian", allergyConsent: true },
|
|
90
|
-
],
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// 2. Options are ready in seconds. Use the webhook in production; polling works too.
|
|
94
|
-
const ready = await dunback.catering.waitForOptions(request.id);
|
|
95
|
-
for (const o of ready.options) {
|
|
96
|
-
console.log(o.title, o.price.totals.card, o.price.lines, o.allergyCoverage, o.unfedGuests);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// 3. The host picks one, and you get payment links
|
|
100
|
-
const order = await dunback.catering.select(ready.id, { optionId: ready.options[0].id });
|
|
101
|
-
order.payment.stripe?.checkoutUrl; // card: Stripe Checkout
|
|
102
|
-
order.payment.usdc; // USDC: amount, address, EIP-681 link, x402Url
|
|
103
|
-
order.payment.hostedPaymentUrl; // Dunback page offering both
|
|
104
|
-
|
|
105
|
-
// 4. Wait for the order.confirmed webhook, or poll
|
|
106
|
-
const final = await dunback.orders.waitForSettlement(order.id);
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
## Paying
|
|
110
|
-
|
|
111
|
-
| Method | Who it suits | How Dunback verifies |
|
|
112
|
-
| --- | --- | --- |
|
|
113
|
-
| **Card** (`payment.stripe.checkoutUrl`) | People | Signed Stripe webhook, plus a re-read of the Checkout Session: paid, USD, exact amount, this order |
|
|
114
|
-
| **USDC transfer** (`payment.usdc`) | People with a wallet, treasury tools | Polygon logs: a transfer of the exact tagged amount to the receiver is matched automatically. You can also call `orders.confirmUsdcPayment(id, txHash)` with any amount ≥ the total. |
|
|
115
|
-
| **x402** (`payOrderWithX402`) | Agents | EIP-3009 authorization, verified and settled on-chain by Dunback's x402 facilitator |
|
|
116
|
-
|
|
117
|
-
The **card total** includes card processing, so it is a little higher than
|
|
118
|
-
the **USDC total**. Both are shown in `price.totals`, and the line items are in
|
|
119
|
-
`price.lines`.
|
|
120
|
-
|
|
121
|
-
Payment links expire at `payment.expiresAt`. That is usually 60 minutes, and
|
|
122
|
-
always before the restaurant's order deadline. When a link expires, the host
|
|
123
|
-
can select an option again to get new links.
|
|
124
|
-
|
|
125
|
-
### Agent payment with x402
|
|
126
|
-
|
|
127
|
-
```ts
|
|
128
|
-
import { payOrderWithX402 } from "@dunbackmeadow/commerce-sdk";
|
|
129
|
-
|
|
130
|
-
const paid = await payOrderWithX402(order, {
|
|
131
|
-
address: account.address,
|
|
132
|
-
signTypedData: (td) => account.signTypedData(td), // viem
|
|
133
|
-
// signTypedData: (td) => wallet.signTypedData(td.domain, td.types, td.message), // ethers v6
|
|
134
|
-
}, { maxAmountUsdc: 500 });
|
|
135
|
-
// paid.status === "CONFIRMED"
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
### Payment errors
|
|
139
|
-
|
|
140
|
-
Payment problems come back as `DunbackApiError` with a `code` you can show to the payer:
|
|
141
|
-
|
|
142
|
-
| code | Meaning |
|
|
143
|
-
| --- | --- |
|
|
144
|
-
| `payment_pending` | The transaction isn't confirmed yet. Retry in a few seconds. |
|
|
145
|
-
| `payment_not_found` | That transaction didn't send USDC to Dunback. |
|
|
146
|
-
| `payment_amount_short` | Less than the order total arrived. |
|
|
147
|
-
| `payment_already_used` | That transaction already paid another order. |
|
|
148
|
-
| `invalid_payment_signature`, `invalid_payment`, `insufficient_funds`, `settlement_failed` | The x402 authorization was rejected. |
|
|
149
|
-
| `order_deadline_passed` | It's too late for the restaurant to make the event time. |
|
|
150
|
-
|
|
151
|
-
`isPaymentError(e)` tells you whether an error is one of these.
|
|
152
|
-
|
|
153
|
-
Asynchronous card failures, such as a declined bank debit, arrive as the
|
|
154
|
-
`order.payment_failed` webhook. `order.payment.lastError` holds the message.
|
|
155
|
-
|
|
156
|
-
## Correcting the delivery address
|
|
157
|
-
|
|
158
|
-
Until an order is paid, you (or the payer, on the hosted payment page) can
|
|
159
|
-
correct the delivery address, on-site contact and note:
|
|
160
|
-
|
|
161
|
-
```ts
|
|
162
|
-
const updated = await dunback.orders.updateDelivery(order.id, {
|
|
163
|
-
deliveryAddress: { address1: "120 University Ave", address2: "Suite 300", city: "Palo Alto", state: "CA", zip: "94301" },
|
|
164
|
-
onsiteContact: { name: "Sam Lee", phone: "+15550000000" },
|
|
165
|
-
deliveryNotes: "Loading dock on Bryant St.", // replaces the current note
|
|
166
|
-
});
|
|
167
|
-
// updated.delivery shows the corrected details
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
The price stays as quoted, so the new address must stay within about a mile
|
|
171
|
-
of the original and inside the restaurant's delivery area. Otherwise the call
|
|
172
|
-
fails with `422 address_moved` or `outside_delivery_area`; create a new
|
|
173
|
-
catering request instead. Addresses where Dunback hasn't launched delivery
|
|
174
|
-
fail with `422 delivery_area_not_launched`, both here and when you create a
|
|
175
|
-
catering request.
|
|
176
|
-
|
|
177
|
-
## Order lifecycle
|
|
178
|
-
|
|
179
|
-
```
|
|
180
|
-
AWAITING_PAYMENT ─▶ PAID ─▶ FULFILLING ─▶ CONFIRMED ─▶ (CANCELLED | REFUNDED when every delivery failed)
|
|
181
|
-
│ ├─▶ REFUNDED / REFUND_PENDING restaurant couldn't take it; buyer refunded
|
|
182
|
-
│ └─▶ NEEDS_ATTENTION Dunback support finishes it by hand
|
|
183
|
-
└─▶ EXPIRED / CANCELLED
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
## Webhooks
|
|
187
|
-
|
|
188
|
-
```ts
|
|
189
|
-
import express from "express";
|
|
190
|
-
import { verifyWebhook } from "@dunbackmeadow/commerce-sdk";
|
|
191
|
-
|
|
192
|
-
app.post("/webhooks/dunback", express.raw({ type: "application/json" }), (req, res) => {
|
|
193
|
-
const event = verifyWebhook(req.body, req.header("Dunback-Signature"), process.env.DUNBACK_WEBHOOK_SECRET!);
|
|
194
|
-
// event.type, event.data (CateringRequest or Order)
|
|
195
|
-
res.sendStatus(200);
|
|
196
|
-
});
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
| Event | `data` |
|
|
200
|
-
| --- | --- |
|
|
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.refunded`, `order.delivery_updated` | Order |
|
|
203
|
-
| `ping` | `{ object: "ping", appId, message }`: sent by **Send test event** in the dashboard |
|
|
204
|
-
|
|
205
|
-
Each webhook is signed as `t=<unix>,v1=<HMAC-SHA256(secret, "<t>.<body>")>`.
|
|
206
|
-
A non-2xx answer is retried after 1 s, 5 s and 25 s. Handle events
|
|
207
|
-
idempotently by `event.id`.
|
|
208
|
-
|
|
209
|
-
## Reliability
|
|
210
|
-
|
|
211
|
-
- POST helpers send an `Idempotency-Key`. Pass your own (for example, per button
|
|
212
|
-
click) to make retries safe across processes. Dunback keeps keys for 24 h.
|
|
213
|
-
- The client retries network errors and 5xx responses for GETs and for POSTs
|
|
214
|
-
that carry an idempotency key.
|
|
215
|
-
- `orders.get()` also re-checks Stripe, so it is safe to call right after a
|
|
216
|
-
Checkout redirect.
|
|
217
|
-
|
|
218
|
-
## Allergies
|
|
219
|
-
|
|
220
|
-
Guests write allergy notes in their own words. Dunback turns them into
|
|
221
|
-
allergens (the US "Big 9" plus a few more) and diets. A dish is offered to a
|
|
222
|
-
guest with an allergy only when the restaurant has **declared** that dish's
|
|
223
|
-
allergens and none of them match. If no dish is known to be safe for a guest,
|
|
224
|
-
the option lists that guest in `unfedGuests` rather than guessing. Show those
|
|
225
|
-
warnings to the host. Allergy-labelled portions are requested from the
|
|
226
|
-
restaurant in the delivery note.
|
|
227
|
-
|
|
228
|
-
**Consent.** Allergy and diet notes are health information, so each guest
|
|
229
|
-
must agree to share theirs. Send `allergyConsent: true` for every guest whose
|
|
230
|
-
`allergies` or `dietaryPreferences` says more than "none". Without it, the
|
|
231
|
-
request fails with `400 allergy_consent_required`, and `details.guests` lists
|
|
232
|
-
the guests concerned. `toDunbackAttendees()` sets `allergyConsent` for answers
|
|
233
|
-
to `DUNBACK_REGISTRATION_QUESTION`, whose wording asks for that consent.
|
|
234
|
-
|
|
235
|
-
**Retention.** Dunback deletes guest data 30 days after the event. Orders are
|
|
236
|
-
kept longer for accounting, without guest names.
|
|
237
|
-
|
|
238
|
-
## React components (optional)
|
|
239
|
-
|
|
240
|
-
```tsx
|
|
241
|
-
import { DunbackCateringSettings, CateringOptionsPicker, DunbackOrderStatus } from "@dunbackmeadow/commerce-sdk/react";
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
These components only render data. Your backend makes every Dunback call.
|
|
245
|
-
|
|
246
|
-
## More
|
|
247
|
-
|
|
248
|
-
- Developer Dashboard and documentation: <https://dunbackmeadow.com/developer>
|
|
249
|
-
- [Luma integration guide](docs/LUMA_INTEGRATION_GUIDE.md)
|
|
250
|
-
- [API reference](docs/API_REFERENCE.md)
|
|
251
|
-
- [examples/luma-integration](examples/luma-integration): Express backend and host panel
|
|
252
|
-
- [examples/agent-x402-payment.ts](examples/agent-x402-payment.ts): an agent ordering and paying with x402
|
|
253
|
-
|
|
254
|
-
## License
|
|
255
|
-
|
|
256
|
-
MIT
|
|
1
|
+
# Dunback Meadow Commerce SDK
|
|
2
|
+
|
|
3
|
+
`@dunbackmeadow/commerce-sdk` lets your app or agent order **event catering**
|
|
4
|
+
from restaurants on Dunback Meadow. More product types will follow. Buyers pay
|
|
5
|
+
**by card (Stripe)** or in **USDC on Polygon** (a wallet transfer or x402).
|
|
6
|
+
|
|
7
|
+
Dunback handles three things:
|
|
8
|
+
|
|
9
|
+
- **Restaurant selection.** Its catering agent finds restaurants that serve
|
|
10
|
+
the chosen cuisine, deliver to the venue, and can make the event time.
|
|
11
|
+
- **Allergy-aware menus.** Each guest gets a dish that is safe for their
|
|
12
|
+
allergies and diet, according to the restaurant's allergen data.
|
|
13
|
+
- **Payment and placement.** Dunback verifies the buyer's payment, pays the
|
|
14
|
+
restaurant, and confirms the order back to you.
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
Your app Dunback Meadow Restaurant agent
|
|
18
|
+
──────── ────────────── ────────────────
|
|
19
|
+
catering.create(guests) ───────▶ catering agent composes 3 options ───▶ quote_cart (prices)
|
|
20
|
+
◀── webhook catering.options_ready (price + fee breakdowns)
|
|
21
|
+
catering.select(option) ───────▶ order + payment links
|
|
22
|
+
payer pays (card / USDC / x402) ▶ verifies payment (Stripe API / on-chain)
|
|
23
|
+
pays restaurant in USDC via x402 ─────▶ books the order
|
|
24
|
+
◀── webhook order.confirmed
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install @dunbackmeadow/commerce-sdk
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
You need Node 18 or later. React is optional and only needed for `@dunbackmeadow/commerce-sdk/react`.
|
|
34
|
+
|
|
35
|
+
## Credentials
|
|
36
|
+
|
|
37
|
+
Get your credentials in the **Dunback Developer Dashboard**
|
|
38
|
+
(<https://dunbackmeadow.com/developer>, or Menu → More… → Developer Dashboard
|
|
39
|
+
in the Dunback app):
|
|
40
|
+
|
|
41
|
+
1. Apply for developer access (individual or business). Dunback reviews it,
|
|
42
|
+
usually within 2 business days.
|
|
43
|
+
2. Create an **app**. Each app has a **sandbox** and a **production** environment.
|
|
44
|
+
3. In each environment, create the **API key** and set your **webhook URL**
|
|
45
|
+
and **allowed return hosts**.
|
|
46
|
+
|
|
47
|
+
| What | Example | Where it lives |
|
|
48
|
+
| --- | --- | --- |
|
|
49
|
+
| API key | `dbk_test_app-k3m9x2q7w4ze_…` / `dbk_live_app-k3m9x2q7w4ze_…` | Your servers only. Never put it in a browser or a mobile app. Shown once when created. |
|
|
50
|
+
| Webhook signing secret | `whsec_…` | Your servers; used to verify `Dunback-Signature`. One per environment. |
|
|
51
|
+
| Allowed return hosts | `lu.ma` | Set in the dashboard; Stripe success and cancel URLs must be on these hosts. |
|
|
52
|
+
|
|
53
|
+
One key per app and environment at a time: to rotate, delete the key in the
|
|
54
|
+
dashboard and create a new one. A deleted key stops working within a minute.
|
|
55
|
+
|
|
56
|
+
The client picks the environment from the key:
|
|
57
|
+
|
|
58
|
+
| Key | Base URL |
|
|
59
|
+
| --- | --- |
|
|
60
|
+
| `dbk_test_…` | `https://sandbox.dunbackmeadow.com/api/partner/v1` |
|
|
61
|
+
| `dbk_live_…` | `https://dunbackmeadow.com/api/partner/v1` |
|
|
62
|
+
|
|
63
|
+
In the sandbox:
|
|
64
|
+
|
|
65
|
+
- Stripe runs in test mode.
|
|
66
|
+
- Orders go to Dunback's test restaurants.
|
|
67
|
+
- USDC payments use small real amounts on Polygon. There is no testnet USDC support yet.
|
|
68
|
+
|
|
69
|
+
Check a key with `await dunback.me()`: it returns the app and environment.
|
|
70
|
+
|
|
71
|
+
## Quick start
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { DunbackClient } from "@dunbackmeadow/commerce-sdk";
|
|
75
|
+
|
|
76
|
+
const dunback = new DunbackClient({ apiKey: process.env.DUNBACK_API_KEY! });
|
|
77
|
+
|
|
78
|
+
// 1. Send the event and guest list
|
|
79
|
+
const request = await dunback.catering.create({
|
|
80
|
+
partnerReference: "luma:evt-AbC123",
|
|
81
|
+
event: { name: "Founders Dinner", startsAt: "2026-11-14T02:00:00Z", timeZone: "America/Los_Angeles" },
|
|
82
|
+
cuisine: "mexican",
|
|
83
|
+
deliveryAddress: { address1: "100 University Ave", city: "Palo Alto", state: "CA", zip: "94301" },
|
|
84
|
+
onsiteContact: { name: "Sam Host", phone: "+14155550100" },
|
|
85
|
+
host: { name: "Sam Host", email: "sam@example.com" },
|
|
86
|
+
attendees: [
|
|
87
|
+
{ name: "Ana", email: "ana@example.com", allergies: "peanuts", allergyConsent: true },
|
|
88
|
+
{ name: "Ben", phone: "+14155550101", allergies: "" },
|
|
89
|
+
{ name: "Cleo", dietaryPreferences: "vegetarian", allergyConsent: true },
|
|
90
|
+
],
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// 2. Options are ready in seconds. Use the webhook in production; polling works too.
|
|
94
|
+
const ready = await dunback.catering.waitForOptions(request.id);
|
|
95
|
+
for (const o of ready.options) {
|
|
96
|
+
console.log(o.title, o.price.totals.card, o.price.lines, o.allergyCoverage, o.unfedGuests);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 3. The host picks one, and you get payment links
|
|
100
|
+
const order = await dunback.catering.select(ready.id, { optionId: ready.options[0].id });
|
|
101
|
+
order.payment.stripe?.checkoutUrl; // card: Stripe Checkout
|
|
102
|
+
order.payment.usdc; // USDC: amount, address, EIP-681 link, x402Url
|
|
103
|
+
order.payment.hostedPaymentUrl; // Dunback page offering both
|
|
104
|
+
|
|
105
|
+
// 4. Wait for the order.confirmed webhook, or poll
|
|
106
|
+
const final = await dunback.orders.waitForSettlement(order.id);
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Paying
|
|
110
|
+
|
|
111
|
+
| Method | Who it suits | How Dunback verifies |
|
|
112
|
+
| --- | --- | --- |
|
|
113
|
+
| **Card** (`payment.stripe.checkoutUrl`) | People | Signed Stripe webhook, plus a re-read of the Checkout Session: paid, USD, exact amount, this order |
|
|
114
|
+
| **USDC transfer** (`payment.usdc`) | People with a wallet, treasury tools | Polygon logs: a transfer of the exact tagged amount to the receiver is matched automatically. You can also call `orders.confirmUsdcPayment(id, txHash)` with any amount ≥ the total. |
|
|
115
|
+
| **x402** (`payOrderWithX402`) | Agents | EIP-3009 authorization, verified and settled on-chain by Dunback's x402 facilitator |
|
|
116
|
+
|
|
117
|
+
The **card total** includes card processing, so it is a little higher than
|
|
118
|
+
the **USDC total**. Both are shown in `price.totals`, and the line items are in
|
|
119
|
+
`price.lines`.
|
|
120
|
+
|
|
121
|
+
Payment links expire at `payment.expiresAt`. That is usually 60 minutes, and
|
|
122
|
+
always before the restaurant's order deadline. When a link expires, the host
|
|
123
|
+
can select an option again to get new links.
|
|
124
|
+
|
|
125
|
+
### Agent payment with x402
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import { payOrderWithX402 } from "@dunbackmeadow/commerce-sdk";
|
|
129
|
+
|
|
130
|
+
const paid = await payOrderWithX402(order, {
|
|
131
|
+
address: account.address,
|
|
132
|
+
signTypedData: (td) => account.signTypedData(td), // viem
|
|
133
|
+
// signTypedData: (td) => wallet.signTypedData(td.domain, td.types, td.message), // ethers v6
|
|
134
|
+
}, { maxAmountUsdc: 500 });
|
|
135
|
+
// paid.status === "CONFIRMED"
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Payment errors
|
|
139
|
+
|
|
140
|
+
Payment problems come back as `DunbackApiError` with a `code` you can show to the payer:
|
|
141
|
+
|
|
142
|
+
| code | Meaning |
|
|
143
|
+
| --- | --- |
|
|
144
|
+
| `payment_pending` | The transaction isn't confirmed yet. Retry in a few seconds. |
|
|
145
|
+
| `payment_not_found` | That transaction didn't send USDC to Dunback. |
|
|
146
|
+
| `payment_amount_short` | Less than the order total arrived. |
|
|
147
|
+
| `payment_already_used` | That transaction already paid another order. |
|
|
148
|
+
| `invalid_payment_signature`, `invalid_payment`, `insufficient_funds`, `settlement_failed` | The x402 authorization was rejected. |
|
|
149
|
+
| `order_deadline_passed` | It's too late for the restaurant to make the event time. |
|
|
150
|
+
|
|
151
|
+
`isPaymentError(e)` tells you whether an error is one of these.
|
|
152
|
+
|
|
153
|
+
Asynchronous card failures, such as a declined bank debit, arrive as the
|
|
154
|
+
`order.payment_failed` webhook. `order.payment.lastError` holds the message.
|
|
155
|
+
|
|
156
|
+
## Correcting the delivery address
|
|
157
|
+
|
|
158
|
+
Until an order is paid, you (or the payer, on the hosted payment page) can
|
|
159
|
+
correct the delivery address, on-site contact and note:
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
const updated = await dunback.orders.updateDelivery(order.id, {
|
|
163
|
+
deliveryAddress: { address1: "120 University Ave", address2: "Suite 300", city: "Palo Alto", state: "CA", zip: "94301" },
|
|
164
|
+
onsiteContact: { name: "Sam Lee", phone: "+15550000000" },
|
|
165
|
+
deliveryNotes: "Loading dock on Bryant St.", // replaces the current note
|
|
166
|
+
});
|
|
167
|
+
// updated.delivery shows the corrected details
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
The price stays as quoted, so the new address must stay within about a mile
|
|
171
|
+
of the original and inside the restaurant's delivery area. Otherwise the call
|
|
172
|
+
fails with `422 address_moved` or `outside_delivery_area`; create a new
|
|
173
|
+
catering request instead. Addresses where Dunback hasn't launched delivery
|
|
174
|
+
fail with `422 delivery_area_not_launched`, both here and when you create a
|
|
175
|
+
catering request.
|
|
176
|
+
|
|
177
|
+
## Order lifecycle
|
|
178
|
+
|
|
179
|
+
```
|
|
180
|
+
AWAITING_PAYMENT ─▶ PAID ─▶ FULFILLING ─▶ CONFIRMED ─▶ (CANCELLED | REFUNDED when every delivery failed)
|
|
181
|
+
│ ├─▶ REFUNDED / REFUND_PENDING restaurant couldn't take it; buyer refunded
|
|
182
|
+
│ └─▶ NEEDS_ATTENTION Dunback support finishes it by hand
|
|
183
|
+
└─▶ EXPIRED / CANCELLED
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Webhooks
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
import express from "express";
|
|
190
|
+
import { verifyWebhook } from "@dunbackmeadow/commerce-sdk";
|
|
191
|
+
|
|
192
|
+
app.post("/webhooks/dunback", express.raw({ type: "application/json" }), (req, res) => {
|
|
193
|
+
const event = verifyWebhook(req.body, req.header("Dunback-Signature"), process.env.DUNBACK_WEBHOOK_SECRET!);
|
|
194
|
+
// event.type, event.data (CateringRequest or Order)
|
|
195
|
+
res.sendStatus(200);
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
| Event | `data` |
|
|
200
|
+
| --- | --- |
|
|
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.refunded`, `order.delivery_updated`, `order.revised` | Order |
|
|
203
|
+
| `ping` | `{ object: "ping", appId, message }`: sent by **Send test event** in the dashboard |
|
|
204
|
+
|
|
205
|
+
Each webhook is signed as `t=<unix>,v1=<HMAC-SHA256(secret, "<t>.<body>")>`.
|
|
206
|
+
A non-2xx answer is retried after 1 s, 5 s and 25 s. Handle events
|
|
207
|
+
idempotently by `event.id`.
|
|
208
|
+
|
|
209
|
+
## Reliability
|
|
210
|
+
|
|
211
|
+
- POST helpers send an `Idempotency-Key`. Pass your own (for example, per button
|
|
212
|
+
click) to make retries safe across processes. Dunback keeps keys for 24 h.
|
|
213
|
+
- The client retries network errors and 5xx responses for GETs and for POSTs
|
|
214
|
+
that carry an idempotency key.
|
|
215
|
+
- `orders.get()` also re-checks Stripe, so it is safe to call right after a
|
|
216
|
+
Checkout redirect.
|
|
217
|
+
|
|
218
|
+
## Allergies
|
|
219
|
+
|
|
220
|
+
Guests write allergy notes in their own words. Dunback turns them into
|
|
221
|
+
allergens (the US "Big 9" plus a few more) and diets. A dish is offered to a
|
|
222
|
+
guest with an allergy only when the restaurant has **declared** that dish's
|
|
223
|
+
allergens and none of them match. If no dish is known to be safe for a guest,
|
|
224
|
+
the option lists that guest in `unfedGuests` rather than guessing. Show those
|
|
225
|
+
warnings to the host. Allergy-labelled portions are requested from the
|
|
226
|
+
restaurant in the delivery note.
|
|
227
|
+
|
|
228
|
+
**Consent.** Allergy and diet notes are health information, so each guest
|
|
229
|
+
must agree to share theirs. Send `allergyConsent: true` for every guest whose
|
|
230
|
+
`allergies` or `dietaryPreferences` says more than "none". Without it, the
|
|
231
|
+
request fails with `400 allergy_consent_required`, and `details.guests` lists
|
|
232
|
+
the guests concerned. `toDunbackAttendees()` sets `allergyConsent` for answers
|
|
233
|
+
to `DUNBACK_REGISTRATION_QUESTION`, whose wording asks for that consent.
|
|
234
|
+
|
|
235
|
+
**Retention.** Dunback deletes guest data 30 days after the event. Orders are
|
|
236
|
+
kept longer for accounting, without guest names.
|
|
237
|
+
|
|
238
|
+
## React components (optional)
|
|
239
|
+
|
|
240
|
+
```tsx
|
|
241
|
+
import { DunbackCateringSettings, CateringOptionsPicker, DunbackOrderStatus } from "@dunbackmeadow/commerce-sdk/react";
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
These components only render data. Your backend makes every Dunback call.
|
|
245
|
+
|
|
246
|
+
## More
|
|
247
|
+
|
|
248
|
+
- Developer Dashboard and documentation: <https://dunbackmeadow.com/developer>
|
|
249
|
+
- [Luma integration guide](docs/LUMA_INTEGRATION_GUIDE.md)
|
|
250
|
+
- [API reference](docs/API_REFERENCE.md)
|
|
251
|
+
- [examples/luma-integration](examples/luma-integration): Express backend and host panel
|
|
252
|
+
- [examples/agent-x402-payment.ts](examples/agent-x402-payment.ts): an agent ordering and paying with x402
|
|
253
|
+
|
|
254
|
+
## License
|
|
255
|
+
|
|
256
|
+
MIT
|
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-
|
|
2
|
-
export {
|
|
1
|
+
import { A as AppInfo, V as VenueLocation, C as CuisineQuery, a as Cuisine, R as RestaurantSummary, D as DrinkType, b as CuisineCatalog, c as CateringRequestInput, d as CateringRequest, S as SelectOptionInput, O as Order, U as UpdateDeliveryInput, e as CancelOrderOptions, L as LateRefundRequestInput, f as LateRefundRequest, W as WebhookEvent } from './luma-D2AucdDY.js';
|
|
2
|
+
export { g as ATTENDING_STATUSES, h as Address, i as AllergyCoverage, j as Attendee, B as BuildCateringRequestArgs, k as CateringItem, l as CateringOption, m as CateringPolicies, n as CateringRequestStatus, o as CateringServiceStyle, p as CuisineId, q as CustomCuisineId, r as DUNBACK_REGISTRATION_QUESTION, s as DeliveredLateData, t as DrinkTypeId, u as DunbackEventSettings, v as LumaEventLike, w as LumaGuestLike, x as OrderCancellation, y as OrderDelivery, z as OrderRevision, E as OrderStatus, P as PingData, F as Price, G as PriceLine, H as RefundDecidedData, I as StandardCuisineId, J as UnavailableReason, K as UnavailableReasonCode, M as UnfedGuests, N as UsdcPaymentInstructions, Q as WebhookEventType, T as buildCateringRequest, X as canOrderFood, Y as guestsWithUnsharedAllergies, Z as toDunbackAddress, _ as toDunbackAttendees, $ as toVenueLocation } from './luma-D2AucdDY.js';
|
|
3
3
|
|
|
4
4
|
/** Any non-2xx answer from the Partner API. */
|
|
5
5
|
declare class DunbackApiError extends Error {
|
|
@@ -64,6 +64,18 @@ declare class DunbackClient {
|
|
|
64
64
|
* cuisineCatalog().
|
|
65
65
|
*/
|
|
66
66
|
listCuisines(venue?: VenueLocation | null, query?: CuisineQuery): Promise<Cuisine[]>;
|
|
67
|
+
/**
|
|
68
|
+
* Restaurants a host can name (`restaurantName` on a catering request)
|
|
69
|
+
* instead of choosing a cuisine. With a venue, only restaurants in its metro
|
|
70
|
+
* area; `q` filters by name (for a search box).
|
|
71
|
+
*/
|
|
72
|
+
listRestaurants(venue?: VenueLocation | null, q?: string): Promise<RestaurantSummary[]>;
|
|
73
|
+
/**
|
|
74
|
+
* Drink types a host can ask for (`drinkTypes` on a catering request), for
|
|
75
|
+
* drinks-only catering or the drinks with food. Any other short word works
|
|
76
|
+
* too and is matched against the restaurants' drink names.
|
|
77
|
+
*/
|
|
78
|
+
listDrinkTypes(): Promise<DrinkType[]>;
|
|
67
79
|
/** listCuisines() plus which metro area the counts are for (`metro` is null when Dunback doesn't serve the venue's area). */
|
|
68
80
|
cuisineCatalog(venue?: VenueLocation | null, query?: CuisineQuery): Promise<CuisineCatalog>;
|
|
69
81
|
readonly catering: {
|
|
@@ -102,8 +114,25 @@ declare class DunbackClient {
|
|
|
102
114
|
* (create a new catering request instead). Sends `order.delivery_updated`.
|
|
103
115
|
*/
|
|
104
116
|
updateDelivery: (orderId: string, input: UpdateDeliveryInput) => Promise<Order>;
|
|
105
|
-
/**
|
|
106
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Unpaid orders: cancels the payment links. Confirmed orders: cancels at
|
|
119
|
+
* the restaurant. Before the commitment deadline the restaurant's full
|
|
120
|
+
* refund is sent; after it (until delivery) pass
|
|
121
|
+
* `{ acceptPostCommitment: true }` once the host has seen
|
|
122
|
+
* `order.cancellation.notice`, and Dunback decides the refund with the
|
|
123
|
+
* restaurant (webhook `order.refund_decided`). Without it, that call fails
|
|
124
|
+
* with 409 `post_commitment_confirmation_required`.
|
|
125
|
+
*/
|
|
126
|
+
cancel: (orderId: string, reason?: string, options?: CancelOrderOptions) => Promise<Order>;
|
|
127
|
+
/**
|
|
128
|
+
* Asks for a refund of a catering delivery made at or after the catering
|
|
129
|
+
* late-delivery threshold (webhook `order.delivered_late`). The host
|
|
130
|
+
* gives the reason and how the delay affected the event; Dunback decides
|
|
131
|
+
* the refund (0 up to the restaurant's part; Dunback's fees aren't
|
|
132
|
+
* refunded) and sends `order.refund_decided`. Errors: 409 `not_late`,
|
|
133
|
+
* `already_requested`, `request_window_closed`.
|
|
134
|
+
*/
|
|
135
|
+
requestRefund: (orderId: string, input: LateRefundRequestInput) => Promise<LateRefundRequest>;
|
|
107
136
|
/** Polls until the order leaves AWAITING_PAYMENT/PAID/FULFILLING. */
|
|
108
137
|
waitForSettlement: (orderId: string, { timeoutMs, intervalMs }?: {
|
|
109
138
|
timeoutMs?: number | undefined;
|
|
@@ -183,4 +212,4 @@ declare function payOrderWithX402(order: Pick<Order, "id" | "payment">, signer:
|
|
|
183
212
|
maxAmountUsdc?: number;
|
|
184
213
|
}): Promise<Order>;
|
|
185
214
|
|
|
186
|
-
export { AppInfo, CateringRequest, CateringRequestInput, Cuisine, CuisineCatalog, CuisineQuery, DEFAULT_BASE_URL, DunbackApiError, DunbackClient, type DunbackClientOptions, Order, PAYMENT_ERROR_CODES, SANDBOX_BASE_URL, SelectOptionInput, type TypedDataToSign, UpdateDeliveryInput, VenueLocation, WebhookEvent, type X402Signer, isPaymentError, payOrderWithX402, signWebhookPayload, verifyWebhook };
|
|
215
|
+
export { AppInfo, CancelOrderOptions, CateringRequest, CateringRequestInput, Cuisine, CuisineCatalog, CuisineQuery, DEFAULT_BASE_URL, DrinkType, DunbackApiError, DunbackClient, type DunbackClientOptions, LateRefundRequest, LateRefundRequestInput, Order, PAYMENT_ERROR_CODES, RestaurantSummary, SANDBOX_BASE_URL, SelectOptionInput, type TypedDataToSign, UpdateDeliveryInput, VenueLocation, WebhookEvent, type X402Signer, isPaymentError, payOrderWithX402, signWebhookPayload, verifyWebhook };
|