TrackMe API Docs
Flow guides

Paid Services & Invoices

Pay to promote a truck, job, listing, or ad for a fixed number of days — quote, pay via Paymob, and let the HMAC-verified webhook flip it live. Plus owner subscriptions and the cross-feature billing surface.

This guide is for Flutter engineers wiring the buy-a-promotion screens for the authenticated truck owner (and any authenticated customer). It covers the four one-off paid features — feature a truck, advertise a job, distribute a marketplace listing, run a marketplace ad — plus per-truck recurring subscriptions and the shared invoices / payment-orders / saved-cards surface. Admin refunds and pricing management are covered in Admin and the API reference.

All JSON endpoints are under /api/v1 and require a Bearer token: Authorization: Bearer <oat_...> (pricing and currency reference are public). The two gateway webhooks and the return page live outside /api/v1 and are called by Paymob, never by you. Send Accept-Language: ar for Arabic error copy. All wire timestamps are UTC ISO-8601 with a Z suffix.

Creating a payment order does not make the promotion live. When a fee is due, POST /api/v1/{feature}/payment-orders returns 201 with paymentOrder.status: "pending", a non-null clientSecret, immediatelyActivated: false, and activation: null. The promotion only goes live after the customer pays and Paymob calls the HMAC-verified webhook, which flips the order to paid and creates the activation server-side. Gate every "it is live" UI on the activation existing / order status: "paid" — never on the 201 from create, and never on reaching the display-only /payments/return page.

All four features share one flow

featured-listings, job-advertising, marketplace-distribution, and marketplace-advertising are byte-identical except for the URL prefix and the target they promote. Substitute the prefix and targetId and everything else is the same:

FeatureURL prefixserviceTypetargetId is the id of…
Feature a truck/api/v1/featured-listingsfeatured_trucka truck you own
Advertise a job/api/v1/job-advertisingjob_advertisementa job post you own
Distribute a listing/api/v1/marketplace-distributionmarketplace_listinga marketplace listing you own
Run a marketplace ad/api/v1/marketplace-advertisingadvertisementa drafted advertisement (see Step 0)

Marketplace ads have an extra Step 0. The other three features promote a target (truck/job/listing) that already exists. An ad does not — you must first POST /api/v1/marketplace-advertising/ads to draft it. The draft lands status: "pending" and is not visible to anyone. The id it returns is the targetId for the quote/payment steps, and the ad only goes live after you pay for a run and that order settles.

The flow at a glance

Step 0 — (ads only) Draft the advertisement

POST /api/v1/marketplace-advertising/ads with the ad content and the truck/listing you own. It returns the ad id at status: "pending" — not live. Skip this step for the other three features.

Step 1 — Discover the price (no auth)

GET /api/v1/{feature}/pricing returns the active pricing rows: dailyPriceMinor, minDurationDays, maxDurationDays, currencyCode.

Step 2 — Quote the cost (Bearer)

POST /api/v1/{feature}/quote with { targetId, durationDays, currencyCode }. Returns the computed total. quote.expiresAt is the quote validity window (now + 15 min), not the promotion window.

Step 3 — Create the payment order (Bearer)

POST /api/v1/{feature}/payment-orders with the same body. Returns 201 with { paymentOrder, clientSecret, immediatelyActivated, activation }. Branch on immediatelyActivated.

Step 4 — Pay in the Paymob sheet

If a fee is due, pass clientSecret to the native Paymob SDK. If immediatelyActivated: true (zero-price), clientSecret is null and the activation is already live — skip the sheet.

Step 5 — Webhook settles (server-to-server)

Paymob calls POST /payments/webhook/paymob (HMAC-verified). This is the source of truth. It flips the order to paid and creates the activation. You never call this.

Step 6 — Poll the order status

After the sheet closes, GET /api/v1/{feature}/payment-orders/:id until status: "paid". The sheet closing does not mean payment succeeded.

Step 7 — Confirm the live promotion

GET /api/v1/{feature}/activations — an active row with startsAt/expiresAt is your proof the promotion is live.

Step 8 — Billing artifacts (cross-feature)

GET /api/v1/invoices and GET /api/v1/payments/orders aggregate across every feature; GET /api/v1/owner/invoices/:id/pdf renders the invoice PDF.

Per-step detail

Step 0 — Draft an advertisement (ads only)

POST /api/v1/marketplace-advertising/ads
Authorization: Bearer oat_xxx
Content-Type: application/json

{
  "title": "Weekend 2-for-1 shawarma",
  "type": "promotion",
  "placement": "homepage",
  "foodTruckId": "food_truck_01jq8z4b2k6h7n8m9p0r3s5t7v"
}

type is one of promotion | offer | announcement | boost. Supply either foodTruckId or listingId (whichever you own). 404 if it is not yours, 409 on conflict, 422 on validation.

{
  "data": {
    "advertisement": {
      "id": "advertisement_01jq8zk1a3c5e7g9j1l3n5p7q9",
      "title": "Weekend 2-for-1 shawarma",
      "type": "promotion",
      "placement": "homepage",
      "status": "pending",
      "foodTruckId": "food_truck_01jq8z4b2k6h7n8m9p0r3s5t7v",
      "listingId": null,
      "createdAt": "2026-06-02T12:00:00.000Z"
    }
  },
  "meta": { "requestId": "req_01jq8zk1a3c5e7g9" }
}

The returned id is the targetId for Steps 2–3. The ad stays pending (invisible) until a paid run settles.

Step 1 — Pricing (public)

GET /api/v1/featured-listings/pricing
{
  "data": {
    "items": [
      {
        "id": "prc_01jq8zz1a3c5e7g9j1l3n5p7q9",
        "serviceType": "featured_truck",
        "currencyCode": "SAR",
        "dailyPriceMinor": 700,
        "minDurationDays": 7,
        "maxDurationDays": 90,
        "effectiveFrom": "2026-04-01T00:00:00.000Z"
      }
    ]
  },
  "meta": { "requestId": "req_01jq8zz1a3c5e7g9" }
}

All *Minor fields are integer minor units: 700 = 0.70 SAR/day, 9900 = 99.00 SAR. Render with currencyCode; never treat them as major units. Use GET /api/v1/currencies for the supported-currency list (SAR today).

Step 2 — Quote (Bearer)

POST /api/v1/featured-listings/quote
Authorization: Bearer oat_xxx
Content-Type: application/json

{
  "targetId": "trk_01jq8z2hf5t8z4w9d8x4mzg2p3",
  "durationDays": 14,
  "currencyCode": "SAR"
}
{
  "data": {
    "quote": {
      "serviceType": "featured_truck",
      "targetType": "food_truck",
      "targetId": "trk_01jq8z2hf5t8z4w9d8x4mzg2p3",
      "durationDays": 14,
      "unitPriceMinor": 700,
      "totalAmountMinor": 9900,
      "currencyCode": "SAR",
      "requiresPayment": true,
      "expiresAt": "2026-05-20T20:00:00.000Z"
    }
  },
  "meta": { "requestId": "req_01jq8z8b3d5f7h9k" }
}

409 if the target is not eligible; 422 if durationDays is outside the pricing row's min/max.

quote.expiresAt is how long this quote is valid (now + 15 minutes), not when the promotion ends. The real promo window (startsAt / expiresAt) only exists on the activation object after settlement. Do not render quote.expiresAt as "your feature ends on…".

Step 3 — Create the payment order (Bearer)

POST /api/v1/featured-listings/payment-orders
Authorization: Bearer oat_xxx
Content-Type: application/json

{
  "targetId": "trk_01jq8z2hf5t8z4w9d8x4mzg2p3",
  "durationDays": 14,
  "currencyCode": "SAR"
}

Outcome (a) — fee due (the normal path):

{
  "data": {
    "paymentOrder": {
      "id": "pmo_01jq8z8b3d5f7h9k1m3n5p7q9r",
      "orderNumber": "TM-20260520-0001",
      "serviceType": "featured_truck",
      "targetType": "food_truck",
      "targetId": "trk_01jq8z2hf5t8z4w9d8x4mzg2p3",
      "durationDays": 14,
      "totalAmountMinor": 9900,
      "currencyCode": "SAR",
      "status": "pending",
      "gateway": "paymob",
      "paidAt": null,
      "expiresAt": "2026-05-20T20:00:00.000Z",
      "createdAt": "2026-05-20T19:31:48.000Z"
    },
    "clientSecret": "egy_csk_test_4a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d",
    "immediatelyActivated": false,
    "activation": null
  },
  "meta": { "requestId": "req_01jq8z8b3d5f7h9k" }
}

Pass clientSecret to the native Paymob SDK to open the payment sheet. The order is pending and activation is null — not live yet.

Outcome (b) — zero-price (skip the sheet):

{
  "data": {
    "paymentOrder": { "id": "pmo_...", "status": "paid", "totalAmountMinor": 0 },
    "clientSecret": null,
    "immediatelyActivated": true,
    "activation": {
      "id": "act_01jq8zy1a3c5e7g9j1l3n5p7q9",
      "serviceType": "featured_truck",
      "targetId": "trk_01jq8z2hf5t8z4w9d8x4mzg2p3",
      "startsAt": "2026-05-20T19:33:01.000Z",
      "expiresAt": "2026-06-03T19:33:01.000Z",
      "status": "active"
    }
  },
  "meta": { "requestId": "req_01jq8z8b3d5f7h9k" }
}

Check immediatelyActivated before opening Paymob. When true, the order is already paid, clientSecret is null, and the activation is live — there is nothing to charge.

Step 4–6 — Pay, settle, poll

The customer completes payment in the Paymob sheet. When the sheet closes, do not assume success — Paymob's server-to-server webhook is the only authority:

POST /payments/webhook/paymob?hmac=<hmac>

Paymob delivers the HMAC as the ?hmac= query param (an hmac / X-Paymob-Signature header is also accepted as a fallback). This is HMAC-verified, CSRF-exempt, and called by Paymob, not your app. It flips the order pending → paid and creates the activation. The hosted GET /payments/return page is display-only — landing there is not proof of payment.

After the sheet closes, poll:

GET /api/v1/featured-listings/payment-orders/:id
Authorization: Bearer oat_xxx
{
  "data": {
    "paymentOrder": {
      "id": "pmo_01jq8z8b3d5f7h9k1m3n5p7q9r",
      "status": "paid",
      "paidAt": "2026-05-20T19:33:01.000Z"
    }
  },
  "meta": { "requestId": "req_01jq8zc4d6e8f0g2" }
}

404 if :id is not a featured_truck order (the per-feature show is service-type-pinned); 403 if it is a featured_truck order owned by someone else.

Step 7 — Confirm the live promotion

GET /api/v1/featured-listings/activations?limit=50
Authorization: Bearer oat_xxx
{
  "data": {
    "items": [
      {
        "id": "act_01jq8zy1a3c5e7g9j1l3n5p7q9",
        "paymentOrderId": "pmo_01jq8z8b3d5f7h9k1m3n5p7q9r",
        "serviceType": "featured_truck",
        "targetId": "trk_01jq8z2hf5t8z4w9d8x4mzg2p3",
        "startsAt": "2026-05-20T19:33:01.000Z",
        "expiresAt": "2026-06-03T19:33:01.000Z",
        "status": "active",
        "renewedFromId": null
      }
    ]
  },
  "meta": { "requestId": "req_01jq8zd5e7f9g1h3" }
}

?limit accepts 1–200 (default 50). An active row is the only reliable "it is live" signal.

Cancel a pending order

POST /api/v1/featured-listings/payment-orders/:id/cancel
Authorization: Bearer oat_xxx

Only works while status: "pending" — any other state returns 409 CONFLICT. Sets status: "cancelled" + cancelledAt. There is no customer-facing refund; refunds are admin-only and documented in Admin / API reference. (For ads, cancelling the order does not delete the drafted ad — it stays pending.)

Step 8 — Cross-feature billing surface

These aggregate across all paid-service features in one place — prefer them over the per-feature show endpoints when you want a unified history.

GET /api/v1/payments/orders?status=paid&serviceType=featured_truck&page=1&perPage=25
GET /api/v1/payments/orders/:id
GET /api/v1/invoices?limit=50
GET /api/v1/owner/invoices/:id/pdf
  • GET /payments/orders — newest-first, filter ?status= and/or ?serviceType=, paginate ?page (default 1) + ?perPage (default 25, max 100). GET /payments/orders/:id is the cross-feature show (no service-type pin, so it never 404s on a wrong-feature id you own).
  • GET /invoices — newest-first, ?limit (default 50, max 200).
  • GET /owner/invoices/:id/pdf — renders the PDF asynchronously:
// 200 — ready (cached)
{ "data": { "pending": false, "url": "https://cdn.../inv.pdf?sig=..." }, "meta": { "requestId": "req_..." } }

// 202 — render dispatched; poll back in a few seconds
{ "data": { "pending": true, "url": null }, "meta": { "requestId": "req_..." } }

The signed url is valid for 7 days.

Pay a pending order with a saved card (CIT)

Instead of re-opening the sheet, charge a stored card:

POST /api/v1/payments/orders/:id/charge-saved-card
Authorization: Bearer oat_xxx
Content-Type: application/json

{ "paymentMethodId": "pmt_01jqn8z4f3g5h7j9k1m3n5p7q9", "cvv": "123" }

Runs the Paymob CIT flow then advances the order like a webhook would. On a 3-DS step-up the order stays pending and the response carries status3ds: "required" — poll the order until paid. 502 on a gateway error. Manage stored cards with GET /api/v1/payments/methods (display metadata only — brand, last4, expMonth/Year, walletType) and DELETE /api/v1/payments/methods/:id.

Owner promotion packages

GET /api/v1/owner/promotion-pricing
Authorization: Bearer oat_xxx

A curated package list for featured-truck add-ons — distinct from the raw GET /api/v1/featured-listings/pricing rows.

Recurring subscriptions (owner)

Separate from one-off paid services: a per-truck monthly plan. The "not live on create" rule applies here too.

GET  /api/v1/owner/subscription-plans
GET  /api/v1/owner/subscriptions
GET  /api/v1/owner/trucks/:id/subscription
POST /api/v1/owner/trucks/:id/subscription            { "planId": "subp_owner_truck_pro_monthly" }
POST /api/v1/owner/trucks/:id/subscription/cancel
POST /api/v1/owner/trucks/:id/subscription/reactivate

POST /owner/trucks/:id/subscription takes { planId } (the plan's id, not its code) and creates a recurring checkout — 201 returns the subscription plus paymentIframeUrl/clientSecret, and the subscription stays status: "pending" until POST /payments/webhook/paymob/subscriptions activates it. Cancel is an immediate hard cancel — it sets status: "cancelled" right away (no grace period) and stamps both cancelAtPeriodEndAt and cancelledAt; despite the name, there is no cancel_at_period_end state in practice. Reactivate resumes a cancelled (or past_due) subscription back to active — but only when a gateway subscription id exists, and it 409s on a still-pending subscription (complete checkout instead). 403 if you are not the owner (404 if the truck does not exist); GET .../subscription returns 200 with subscription: null when the truck never subscribed.

Lifecycles

Payment order

StateMeaningHow you got hereAllowed next
pendingCreated, fee due, awaiting paymentPOST /{feature}/payment-orders (fee due)paid (webhook / saved-card), cancelled (you), expired (>30 min), failed (declined)
paidSettled; activation createdwebhook settled, or zero-price inlinerefunded (admin only)
cancelledYou cancelled while pendingPOST .../cancel—
expiredLeft pending >30 minreconcile job— (a late webhook can still settle it to paid)
failedGateway declinedwebhook— (create a new order to retry)
refundedAdmin reversed a paid orderadmin refund (cascades activation → cancelled)—

Activation (the actual promotion)

StateMeaningHow you got hereAllowed next
activePromotion is livewebhook settled (or zero-price inline)expired (term elapses), cancelled (admin refund)
expiredTerm elapsed (expiresAt passed)time— (buy again to renew; the new term stacks)
cancelledUndone by an admin refundrefund cascade—
StateMeaningHow you got hereAllowed next
pendingDrafted, not visible to anyonePOST /marketplace-advertising/adsactive (pay for a run + webhook settles)
activeLive, after a paid runrun order settled(governed by its activation term)

Subscription

StateMeaningHow you got hereAllowed next
pendingCheckout created, not yet paidPOST /owner/trucks/:id/subscriptionactive (paid → POST /payments/webhook/paymob); cancelled (you) — cannot reactivate
activeLive recurring accesswebhook activated, or successful renewalpast_due/cancelled (subscription webhook), cancelled (you, immediate)
past_dueRenewal payment failedsubscription webhook (past_due/failed/suspended)active (Paymob retry succeeds), cancelled (you / webhook)
cancelledEnded — cancel is immediate, no grace periodPOST .../subscription/cancel, or webhook (cancelled/canceled/ended)active (reactivate, only if a gateway subscription id exists)
cancel_at_period_endDeclared in the enum but never produced by any endpoint — cancel is always immediate. Do not build UI for it.(not reachable)—

Transitions

  • (none) → payment_order:pending — POST /{feature}/payment-orders (fee due; clientSecret set, activation: null).
  • (none) → payment_order:paid — same endpoint, zero-price path (immediatelyActivated: true, activation inline).
  • payment_order:pending → paid — POST /payments/webhook/paymob (HMAC-verified; creates the activation). Source of truth.
  • payment_order:pending → cancelled — POST /{feature}/payment-orders/:id/cancel (pending only; else 409).
  • payment_order:pending → expired — reconcile job, orders stuck pending >30 min.
  • payment_order:pending → failed — webhook (declined).
  • payment_order:paid → activation:active — server, on settlement; term starts at max(now, prior.expiresAt) so renewals stack.
  • activation:active → expired — term elapses.
  • advertisement:pending → active — pay for a run: POST /marketplace-advertising/payment-orders then webhook settles.
  • subscription:(none|active|past_due) → cancelled — POST /owner/trucks/:id/subscription/cancel (immediate hard cancel; also cancels at Paymob when a gateway sub exists).
  • subscription:(cancelled|past_due) → active — POST /owner/trucks/:id/subscription/reactivate (resumes at Paymob; 409 if still pending or no gateway subscription id).
  • subscription:active → past_due | cancelled — POST /payments/webhook/paymob/subscriptions.

Implementation Notes

Integration issueCorrect handling
Treating the 201 from POST /{feature}/payment-orders as "it is live".When a fee is due the order is pending, activation: null, immediatelyActivated: false. Gate "live" UI on the activation existing / status: "paid", set by the webhook.
Opening the Paymob sheet on the zero-price path.If immediatelyActivated: true, clientSecret is null and the activation is already live. Check immediatelyActivated first; skip the sheet.
Trying to quote/pay an ad straight away.Ads need Step 0: POST /marketplace-advertising/ads first. Its returned id is the targetId; the ad is invisible until a paid run settles.
Treating the sheet closing or /payments/return as success.The return page is display-only. Poll GET /{feature}/payment-orders/:id (or /payments/orders/:id) until status: "paid". Saved-card CIT can return status3ds: "required" and stay pending — also poll.
Showing quote.expiresAt as the promotion end date.That's the 15-minute quote-validity window. The real window is startsAt/expiresAt on the activation, only present after settlement.
Calling cancel on a paid/expired/cancelled order.Cancel is pending-only → 409 CONFLICT otherwise. There is no customer refund.
GET/canceling a job order under /featured-listings/....Per-feature show/cancel are service-type-pinned → 404 for a wrong-feature id even if you are the payer. Use GET /api/v1/payments/orders[/:id] for a unified view. 403 = right feature, someone else's order.
Assuming a renewal's durationDays counts from now.Renewing the same target while a prior activation is live starts the new term at max(now, prior.expiresAt) — durations stack.
Hanging on to a stale pending clientSecret.Orders left pending >30 min auto-expire via a reconcile job. Re-fetch status; do not reuse an old secret indefinitely.
Expecting POST /owner/trucks/:id/subscription to be live on create.It returns pending + paymentIframeUrl/clientSecret; the subscription webhook activates it. Same "not live on create" rule.
Sending { planCode } to POST /owner/trucks/:id/subscription.The body field is planId (the plan's id, e.g. subp_owner_truck_pro_monthly), not planCode/code. A wrong/inactive id throws 404.
Treating subscription/cancel as a cancel_at_period_end/end-of-period cancel.It is an immediate hard cancel → status: "cancelled" now, no grace period. The cancel_at_period_end enum value is never set. Reactivate (cancelled/past_due only, and only if a gateway sub id exists) brings it back to active; it 409s on a pending sub.
Rendering totalAmountMinor as major units.*Minor fields are integer minor units (9900 = 99.00 SAR). Format with currencyCode.
Treating the first GET /owner/invoices/:id/pdf as failed when it returns 202.202 { pending: true, url: null } means the render was dispatched — poll until 200 { pending: false, url }. The signed URL expires after 7 days.
  • Payments — the gateway webhook, saved cards, and the cross-feature payment-order/invoice surface in depth
  • Subscriptions — the full per-truck recurring-plan lifecycle (cancel is immediate; planId not planCode)
  • Truck Management — the truck you feature with featured_truck
  • Jobs — the job post you promote with job_advertisement
  • Discovery & Search — where featured trucks, listings, and ads surface to customers
  • API reference

On this page