Owner Dashboard, Analytics & Payouts
Read-only KPIs, charts, per-resource drill-downs, and a weekly payouts view computed live from paid orders — there is no payouts table and nothing to "request".
This guide is for Flutter engineers building the owner dashboard, analytics, and payouts screens. Everything here lives under /api/v1/owner/* and is read-only — no endpoint in this domain creates, accepts, transitions, or settles anything. Every figure is hard-scoped to the caller's own trucks, so an owner can only ever see numbers for trucks they own.
All endpoints require a Bearer token: Authorization: Bearer <oat_...>. These are owner-account endpoints; results are scoped to your owner_id, so a token that owns no trucks gets all-zero / empty payloads (not an error). Send Accept-Language: ar for Arabic error copy and X-Timezone: Asia/Riyadh for any server-rendered display strings — wire timestamps stay UTC ISO-8601 with a Z suffix regardless. Missing/invalid token → 401 AUTH_REQUIRED.
A "payout" is not a stored, settleable entity. There is no payouts table, no payout status field, and no "request payout" / "withdraw" action anywhere in this API. A payout row is a read-only computed aggregate that buckets already-paid customer orders into (truck, ISO-week) groups, with the platform fee applied at read time. A payout only appears after the payment gateway webhook marks an order's payment paid — completing an order is not enough. Do not build UI that implies the owner can trigger, release, or withdraw a payout here.
Two different "revenue" numbers live in this domain and they legitimately diverge. Payouts and per-listing analytics count payment_orders with status=paid. Overview revenue and the /analytics/revenue series count orders with status=completed. A completed-but-not-yet-paid order shows up in analytics revenue but not in payouts. Do not expect payout gross to equal analytics revenue.
The flow at a glance
Step 1 — Authenticate and keep the Bearer token
Owner logs in/registers (see Authentication) and gets an oat_... access token. Every call below sends Authorization: Bearer <oat_...>.
Step 2 — Load headline KPIs for the home screen
GET /api/v1/owner/analytics/overview — trucks owned, trucks open now, 7-day orders + revenue, review count + average, complaints, and the top-selling item.
Step 3 — Render the charts
GET /api/v1/owner/analytics/orders?days=7|30|90 (daily order counts, sparse) and GET /api/v1/owner/analytics/revenue?days=7|30|90 (daily completed-order revenue, zero-filled, with per-truck breakdown and a changePercent vs the prior window). Scope revenue to one truck with ?truckId=.
Step 4 — Render the review histogram
GET /api/v1/owner/analytics/reviews — the 1–5 star distribution across the caller's trucks.
Step 5 — Drill into a specific job or listing
GET /api/v1/owner/job-posts/:id/analytics (application funnel + avg score + response SLA) and GET /api/v1/owner/marketplace/listings/:id/analytics (30-day paid orders + revenue + AOV; views always null).
Step 6 — Show money owed (payouts)
GET /api/v1/owner/payouts — one computed row per truck per ISO week (gross, platform fee, net), built only from orders whose payment is already paid.
Step 7 — Expand a payout into its orders
GET /api/v1/owner/payouts/:id — the same summary plus the individual paid orders inside that week.
Most reads are cached 60 seconds per owner. A just-paid order or a brand-new review will not appear instantly; it appears on the next read after the 60-second cache window rolls over. There is no event-driven invalidation — the cache is not invalidated by the payment webhook or other writes, it expires on a timer. A just-settled payout will surface only after both (a) the gateway webhook has marked the order paid and (b) the owner's 60-second cache window has elapsed. Pull-to-refresh within the TTL returns the same numbers by design. (Note: /analytics/revenue is computed per request rather than cached, but it still only reflects orders already in the DB.)
Per-step detail
Step 2 — Overview KPIs
GET /api/v1/owner/analytics/overview
GET /api/v1/owner/analytics/overview
Authorization: Bearer oat_xxx{
"data": {
"trucksOwned": 3,
"trucksOpenNow": 1,
"ordersLast7Days": 42,
"revenueLast7DaysMinor": 187500,
"complaintsCount": 2,
"reviewsCount": 18,
"averageRating": 4.5,
"topItem": { "menuItemId": "mi_abc123", "name": "Shawarma Wrap", "orders": 31 }
},
"meta": { "requestId": "req_01J..." }
}revenueLast7DaysMinorcounts only orders withstatus=completed.reviewsCount/averageRatingcount only visible, non-deleted reviews.complaintsCountis lifetime reports against your trucks and reports against reviews on them.topItemis the best-selling menu item over the last 7 days (by quantity, from completed orders), ornullif none.- Zero trucks ⇒ every number is
0andtopItemisnull.
Step 3a — Daily order count (sparse)
GET /api/v1/owner/analytics/orders — ?days=7|30|90 (default 7; any other value ⇒ 422 VALIDATION_ERROR).
GET /api/v1/owner/analytics/orders?days=7
Authorization: Bearer oat_xxx{
"data": {
"series": [
{ "date": "2026-06-15", "value": 4 },
{ "date": "2026-06-17", "value": 9 },
{ "date": "2026-06-21", "value": 6 }
]
},
"meta": { "requestId": "req_01J..." }
}- Counts ALL orders by
created_at, regardless of status. - Not zero-filled — days with no orders are simply absent (note the missing 06-16, 06-18..06-20 above). Do not assume one entry per day.
- The payload is wrapped:
data.series[].
Step 3b — Daily completed-order revenue (zero-filled)
GET /api/v1/owner/analytics/revenue — ?days=7|30|90 (default 7) and optional ?truckId=.
GET /api/v1/owner/analytics/revenue?days=7
Authorization: Bearer oat_xxx{
"data": {
"days": 7,
"totalRevenueMinor": 187500,
"totalOrders": 42,
"changePercent": 12.4,
"series": [
{
"date": "2026-06-15",
"revenueMinor": 0,
"orders": 0,
"trucks": []
},
{
"date": "2026-06-16",
"revenueMinor": 45000,
"orders": 10,
"trucks": [
{ "id": "trk_a1", "name": "Burger Bus", "revenueMinor": 45000, "orders": 10 }
]
}
]
},
"meta": { "requestId": "req_01J..." }
}- Counts only
status=completedorders. - Zero-filled — every day in the window is present (
revenueMinor: 0when none). The series length is exactlydays. changePercentis vs the immediately previous equal-length window. It isnull(not0) when the previous window's revenue was0— guard fornullbefore formatting.- Each day carries a per-truck
trucks[]breakdown unless?truckId=is supplied (then thetrucksfield is omitted entirely). - Passing a
?truckId=you do not own ⇒403 FORBIDDEN.
Step 4 — Review distribution
GET /api/v1/owner/analytics/reviews
{
"data": {
"total": 18,
"averageRating": 4.5,
"stars": [
{ "stars": 5, "count": 12 },
{ "stars": 4, "count": 4 },
{ "stars": 3, "count": 1 },
{ "stars": 2, "count": 1 },
{ "stars": 1, "count": 0 }
]
},
"meta": { "requestId": "req_01J..." }
}stars[]always has all five buckets, ordered 5→1, withcount: 0where there are none.- Only visible, non-deleted reviews are counted. No trucks ⇒
total: 0,averageRating: 0,stars: [].
Step 5a — Per-job analytics
GET /api/v1/owner/job-posts/:id/analytics
{
"data": {
"applications": 14,
"pendingApplications": 5,
"acceptedApplications": 6,
"rejectedApplications": 2,
"withdrawnApplications": 1,
"averageScore": 7.8,
"averageTimeToFirstResponseHours": 18.5
},
"meta": { "requestId": "req_01J..." }
}averageScoreisnullwhen no application has a score.averageTimeToFirstResponseHoursaveragesaccepted_at - applied_at;nullwhen no application has been accepted.- Ownership is enforced silently. A job that does not exist or is not yours returns the all-zero / all-null shape with HTTP 200 — not a
404and not a403. Do not treat the empty shape as "a real job with no activity"; it may simply not be yours. Only401is possible.
Step 5b — Per-listing analytics
GET /api/v1/owner/marketplace/listings/:id/analytics
{
"data": {
"ordersLast30Days": 23,
"revenueLast30DaysMinor": 920000,
"averageOrderValueMinor": 40000,
"viewsLast30Days": null
},
"meta": { "requestId": "req_01J..." }
}- Derived from
payment_orders(target_type=marketplace_listing,status=paid, last 30 days). averageOrderValueMinorisnullwhen there are0orders.viewsLast30Daysis alwaysnulltoday — view counting is not shipped. Render it as n/a, never0. The field exists so the counter can ship without a client deploy.- Same silent ownership rule as jobs: missing/not-yours listing ⇒ HTTP 200 all-zero shape, not
404/403. Only401is possible.
Step 6 — Payouts list
GET /api/v1/owner/payouts
{
"data": {
"items": [
{
"id": "pyo_a1b2c3d4_2026-06-15",
"weekStartUtc": "2026-06-15T00:00:00.000Z",
"weekEndUtc": "2026-06-22T00:00:00.000Z",
"truckId": "trk_a1b2c3d4",
"ordersCount": 31,
"grossMinor": 620000,
"platformFeeMinor": 31000,
"netMinor": 589000,
"currencyCode": "SAR"
}
]
},
"meta": { "requestId": "req_01J..." }
}- Rows come from
payment_orderswheretarget_type=food_truck,status=paid,paid_atnot null, grouped in SQL by truck + currency + ISO week (date_trunc('week', paid_at)— weeks start Monday, UTC); the platform fee is then applied per row at read time. There is nopayoutstable. platformFeeMinor = round(grossMinor * platformFeeBps / 10000); defaultplatformFeeBpsis500(= 5%).netMinor = grossMinor - platformFeeMinor.weekEndUtcis exactlyweekStart + 7 days(an exclusive upper bound).- Sorted newest week first. No trucks / no paid orders ⇒
items: []. - The
idis synthetic and opaque:pyo_<truckId-with-the-4-char-prefix-stripped>_<weekStartYYYY-MM-DD>. It is not a database key — treat it as a token to pass to the detail endpoint.
Step 7 — Payout detail
GET /api/v1/owner/payouts/:id
GET /api/v1/owner/payouts/pyo_a1b2c3d4_2026-06-15
Authorization: Bearer oat_xxx{
"data": {
"payout": {
"id": "pyo_a1b2c3d4_2026-06-15",
"weekStartUtc": "2026-06-15T00:00:00.000Z",
"weekEndUtc": "2026-06-22T00:00:00.000Z",
"truckId": "trk_a1b2c3d4",
"ordersCount": 31,
"grossMinor": 620000,
"platformFeeMinor": 31000,
"netMinor": 589000,
"currencyCode": "SAR",
"orders": [
{
"id": "po_xyz",
"orderNumber": "ORD-2026-0042",
"paidAt": "2026-06-16T09:14:00.000Z",
"totalMinor": 40000,
"currencyCode": "SAR"
}
]
}
},
"meta": { "requestId": "req_01J..." }
}- The server rebuilds the owner's full payout list, finds the bucket whose synthetic id matches
:id, then re-queriespayment_ordersin[weekStart, weekStart + 7d)for that truck. (It matches against the rebuilt list — it does not parse(truck, week)out of the id string.) - An unknown or not-owned id ⇒
404 NOT_FOUND. (This is the one detail endpoint that 404s — contrast with the job/listing analytics endpoints, which never do.) - The payload is wrapped:
data.payout.
What feeds each number (state table)
These are upstream states from other domains. Nothing in this domain changes them — the analytics endpoints only read.
| State | Meaning | How it got there | What it feeds here |
|---|---|---|---|
payment_order.status = paid (+ paid_at set) | Customer's payment cleared at the gateway | Payment gateway (Paymob) webhook — outside this domain | Payouts + per-listing analytics |
order.status = completed | Owner fulfilled the order | Owner order-fulfilment flow (/api/v1/owner/orders) — outside this domain | Overview revenue, /analytics/revenue series, top item |
order (any status) | An order exists | POST /api/v1/orders (customer) | /analytics/orders count (status-agnostic) |
job_application.status ∈ pending|accepted|rejected|withdrawn | Applicant's stage in the funnel | Jobs domain | Per-job funnel buckets |
review.status = visible AND deleted_at IS NULL | A live, non-removed review | Reviews domain | Reviews count, average, distribution |
Transitions that make numbers appear
- Order placed/in-progress → counted in payouts + listing revenue — via the payment gateway webhook marking
payment_orderpaid(status=paid,paid_atset). Actor: the payment gateway, not the owner. See Cart & Checkout. - Order in progress → counted in overview/series revenue + top item — via the order reaching
status=completedin the Order Lifecycle. Actor: the truck owner, via the order-fulfilment flow, not these analytics endpoints. - Stale numbers → fresh numbers — via the 60s per-owner cache TTL expiring. There is no event-driven cache invalidation here (no webhook or write busts it), so even payouts only refresh once the timer rolls over. Actor: the system, automatically.
Implementation Notes
| Integration issue | Correct handling |
|---|---|
| Building a "Request payout" / "Withdraw" button. | There is no payout entity to settle and no endpoint to trigger one. Payouts are a read-only computed view. Show the figures only. |
| Expecting a completed order to appear in payouts immediately. | Completion is not enough — payouts only count orders whose payment is paid (gateway webhook). Wait for settlement and the 60-second cache window. |
| Expecting payout gross to equal analytics revenue. | They use different filters: payouts/listing = payment_order.status=paid; analytics revenue = order.status=completed. Treat them as separate metrics. |
Treating platformFeeMinor as locked per order. | It is computed at read time from platformFeeBps config (default 5%). If the fee config changes, historical rows recompute. For accounting truth, use invoices, not this view. |
Parsing the payout id as a DB key. | It is a synthetic opaque token (pyo_<truckId>_<weekStart>). Pass it back verbatim to GET /owner/payouts/:id; do not decode it client-side. |
| Reading an empty job/listing analytics shape as "no activity". | An all-zero/all-null 200 on those two endpoints can mean the resource is not yours or does not exist — there is no 404/403 there. Do not infer a real, empty entity. |
Rendering viewsLast30Days as 0. | It is always null today (not implemented). Render n/a. |
Assuming /analytics/orders and /analytics/revenue line up. | orders is sparse and counts all statuses; revenue is zero-filled and counts only completed. Different lengths, different denominators. |
Formatting changePercent blindly. | It is null (not 0) when the prior window had zero revenue. Null-check first. |
| Showing minor units as currency directly, or assuming local time. | All money is integer minor units (e.g. halalas) — divide for display. All wire timestamps are UTC ISO-8601 with Z; X-Timezone only affects server-rendered display strings, not these payloads. |
Sending ?days=14 (or any non-enum). | Only 7, 30, 90 are valid ⇒ otherwise 422 VALIDATION_ERROR. |
| Expecting instant refresh after a write. | 60s per-owner cache. A pull-to-refresh inside the TTL returns the same numbers — by design. |
Related
- Order Lifecycle & State Machine — where
order.status=completedcomes from. - Cart & Checkout — where customer orders and their
payment_order.status=paidsettlement come from. - Jobs — the application funnel behind per-job analytics.
- Truck Management — the trucks every figure is scoped to.
- API reference — full schema for every endpoint above.