TrackMe API Docs
Flow guides

Payments — Paymob, Cards & Webhooks

How an owner pays for a featured truck, an advertised job, or a distributed marketplace listing — the quote → create → pay → webhook pipeline, and why the paid create call is only an intent until settlement.

This guide is for Flutter engineers building the owner "paid services" screens. TrackMe monetises three owner-facing services through one payment pipeline backed by Paymob's Unified Intention API:

  • Featuring a truck (featured_truck) — URL family /api/v1/featured-listings/*
  • Advertising a job (job_advertisement) — URL family /api/v1/job-advertising/*
  • Distributing a marketplace listing (marketplace_listing) — URL family /api/v1/marketplace-distribution/*

The three families have identical request/response shapes — only the URL prefix and the pinned (serviceType, targetType) differ. Cross-feature surfaces (unified order list, invoices, currencies, saved cards, charge-saved-card, invoice PDF, promotion pricing) live under /api/v1/payments/* and /api/v1/{invoices,currencies,owner/*}. Admin operations (pricing, refund, cancel, webhook replay, financial reports) are covered in Admin and the API reference.

All authenticated calls are under /api/v1 and require a Bearer token: Authorization: Bearer <oat_...>. The caller must own the target (be its truck owner). Send Accept-Language: ar for Arabic error/notification copy. All wire timestamps are UTC ISO-8601 with a Z suffix.

Payment-order numbers are opaque strings of the form PAY-YYYYMMDD-XXXXXX (e.g. PAY-20260524-K8Y3D1). Do not parse them — treat id (the pmo_... identifier) as the key for all lookups.

Money is always an integer in the currency's minor unit (e.g. 9900 = 99.00 SAR). Divide by minorScale from GET /api/v1/currencies (100 for SAR/USD) to display. Never sum amounts across rows with different currencyCode.

Creating a payment order does not make the paid service live. POST .../payment-orders returns an order with status: "pending" — the truck is not featured, the job has no paid advertising term yet, and the listing has no paid distribution term yet. The paid activation becomes live only when the HMAC-verified Paymob webhook (or a saved-card charge that returns status3ds: "completed") flips the order to paid. Treat the create response as "intent to pay", not as success. The native Paymob SDK closing successfully, and the /payments/return redirect, are not proof of payment — the server webhook is the single source of truth.

The flow at a glance

Step 1 — (optional) Show pricing / packages

For featured_truck, read GET /api/v1/owner/promotion-pricing for the official packages (durationDays + amountMinor). The package price is exactly what the owner is charged for that duration. The public per-day pricing endpoints (GET /api/v1/{feature}/pricing) are a fallback; for featured_truck the promotion package wins at quote time.

Step 2 — Quote the cost

POST /api/v1/{feature}/quote with { targetId, durationDays, currencyCode }. Returns totalAmountMinor, requiresPayment, and an expiresAt (quote valid 15 min). A duration outside the min/max bounds returns 409 CONFLICT.

Step 3 — Create the payment order

POST /api/v1/{feature}/payment-orders with the same body. Server re-quotes, verifies ownership, inserts a PaymentOrder at status: "pending" (expires 30 min after creation), and returns 201 with { paymentOrder, clientSecret, immediatelyActivated, activation }. No paid activation is live yet.

Step 4 — Pay

Hand clientSecret to the native Paymob SDK, which opens the payment sheet and handles card entry + 3-DS. (For a saved card, skip the SDK and call charge-saved-card instead — see Step 6.)

Step 5 — Wait for the webhook, then confirm

After the sheet closes, Paymob POSTs an HMAC-verified webhook to the server, which flips the order to paid and creates the active activation. Poll GET /api/v1/payments/orders/:id (or the feature-specific show endpoint) until status is paid. There can be a few seconds of lag between sheet-close and webhook arrival.

There are two shortcut paths off this sequence:

  • Zero-price path — if the quote's requiresPayment is false, Step 3's create call skips the gateway entirely: it returns immediatelyActivated: true, clientSecret: null, and the activation already populated. No SDK, no webhook, no polling.
  • Saved-card (CIT) path — instead of the SDK in Step 4, call POST /api/v1/payments/orders/:id/charge-saved-card. A clean charge returns status3ds: "completed" (already paid + activated); a 3-DS step-up returns status3ds: "required" (still pending — poll for the webhook).

Per-step detail

GET /api/v1/owner/promotion-pricing
Authorization: Bearer oat_xxx
{
  "data": {
    "items": [
      { "serviceType": "featured_truck", "durationDays": 14, "amountMinor": 19900, "currencyCode": "SAR" },
      { "serviceType": "featured_truck", "durationDays": 30, "amountMinor": 39900, "currencyCode": "SAR" }
    ]
  },
  "meta": { "requestId": "req_01jq..." }
}

GET /api/v1/{feature}/pricing (public, no auth) returns the per-day pricing rows with dailyPriceMinor, minDurationDays, maxDurationDays — use these to render the duration picker bounds.

Step 2 — Quote

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_01jq..." }
}

The job-advertising and marketplace-distribution quote endpoints take the identical body and return the identical shape (with their own serviceType / targetType). A durationDays outside the pricing row's min/max returns 409 CONFLICT. The quote is good for 15 minutes (expiresAt).

Step 3 — Create the payment order

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

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

Paid path — 201, order is pending, clientSecret is present, no paid activation is live:

{
  "data": {
    "paymentOrder": {
      "id": "pmo_01jq8z8b3d5f7h9k1m3n5p7q9r",
      "orderNumber": "PAY-20260520-K8Y3D1",
      "payerId": "usr_01jq8z4f3g5h7j9k1l3m5n7o9p",
      "serviceType": "featured_truck",
      "targetType": "food_truck",
      "targetId": "trk_01jq8z2hf5t8z4w9d8x4mzg2p3",
      "durationDays": 14,
      "unitPriceMinor": 700,
      "totalAmountMinor": 9900,
      "currencyCode": "SAR",
      "status": "pending",
      "gateway": "paymob",
      "gatewayReference": "int_42915720",
      "paidAt": null,
      "cancelledAt": 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_01jq..." }
}

Zero-price path — requiresPayment was false, so the gateway is skipped and the service is live in the create response itself:

{
  "data": {
    "paymentOrder": { "id": "pmo_01jq...", "status": "paid", "totalAmountMinor": 0, "...": "..." },
    "clientSecret": null,
    "immediatelyActivated": true,
    "activation": {
      "id": "act_01jq8zy1a3c5e7g9j1l3n5p7q9",
      "paymentOrderId": "pmo_01jq...",
      "serviceType": "featured_truck",
      "targetType": "food_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_01jq..." }
}

clientSecret: null means free, not failed. On the paid path the secret is always present — the server returns 502 if the gateway hands back no secret, so you never see a null secret on a paid order. clientSecret is null only when immediatelyActivated: true. Branch on immediatelyActivated, not on whether the secret is null.

Step 4 & 5 — Pay via the SDK, then confirm

Pass clientSecret to the native Paymob SDK. The customer enters their card and completes any 3-DS step-up inside the SDK sheet. When the sheet closes, do not assume success. Poll the order:

GET /api/v1/payments/orders/pmo_01jq8z8b3d5f7h9k1m3n5p7q9r
Authorization: Bearer oat_xxx
{
  "data": {
    "id": "pmo_01jq8z8b3d5f7h9k1m3n5p7q9r",
    "orderNumber": "PAY-20260520-K8Y3D1",
    "status": "paid",
    "totalAmountMinor": 9900,
    "currencyCode": "SAR",
    "paidAt": "2026-05-20T19:33:01.000Z"
  },
  "meta": { "requestId": "req_01jq..." }
}

When status becomes paid, the webhook has settled: an invoice was created and the PaidServiceActivation (status active) is what actually features the truck, starts or extends the job advertising term, or starts or extends marketplace distribution until expiresAt. A payment_succeeded notification also fires. You can read the live activation term from GET /api/v1/{feature}/activations.

The feature-specific show endpoint (GET /api/v1/{feature}/payment-orders/:id) returns the full order object (the same shape as the create response's paymentOrder); the unified GET /api/v1/payments/orders/:id returns the slim shape above. Either works for polling.

The two endpoints differ on cross-tenant access. The unified GET /api/v1/payments/orders/:id returns 404 for any order that is not yours (existence is never leaked). The feature-specific GET /api/v1/{feature}/payment-orders/:id returns 403 when the order exists but belongs to someone else, and 404 only when no such order exists. Handle both codes on the feature-specific path.

Step 6 — Saved-card (CIT) path

Instead of the SDK, charge a saved card directly. paymentMethodId comes from GET /api/v1/payments/methods (see below).

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

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

Clean charge — 200, the order is already paid and activated inline:

{
  "data": {
    "paymentOrder": {
      "id": "pmo_01jq...",
      "orderNumber": "PAY-20260524-K8Y3D1",
      "status": "paid",
      "totalAmountMinor": "17500",
      "currencyCode": "EGP",
      "paidAt": "2026-05-24T12:34:56.789Z"
    },
    "status3ds": "completed"
  },
  "meta": { "requestId": "req_01jq..." }
}

3-DS step-up — 200, but the order is still pending and you must poll for the follow-up webhook:

{
  "data": {
    "paymentOrder": { "id": "pmo_01jq...", "orderNumber": "PAY-...", "status": "pending", "totalAmountMinor": "17500", "currencyCode": "EGP", "paidAt": null },
    "status3ds": "required"
  },
  "meta": { "requestId": "req_01jq..." }
}

status3ds: "required" is not success — the order is still pending until the follow-up webhook lands. Only status3ds: "completed" means paid. Note that in this response totalAmountMinor is serialized as a string (e.g. "17500"); coerce it. Failure modes: 502 on a hard decline (order → failed); 409 if the order is not pending; 409 SAVED_CARD_TOKEN_UNREADABLE if the stored token can no longer be decrypted (prompt the user to re-save the card via a fresh checkout); 404 for an unknown order; 403 if the card belongs to another user.

Cancelling a pending order

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

Cancel works only on pending orders; a non-pending order (already paid/failed/cancelled/expired) returns 409 CONFLICT. To unwind a paid order, the owner must request an admin refund — there is no customer refund endpoint.

Saved cards

GET /api/v1/payments/methods
Authorization: Bearer oat_xxx
{
  "data": {
    "items": [
      { "id": "pmt_01jq8za1a3c5e7g9j1l3n5p7q9", "provider": "paymob", "walletType": null, "brand": "visa", "last4": "4242", "expMonth": 12, "expYear": 2030, "isDefault": true, "createdAt": "2026-05-14T13:20:11.000Z" }
    ]
  },
  "meta": { "requestId": "req_01jq..." }
}

There is no client-side "add card" endpoint. Saved cards are created server-side from Paymob's TOKEN webhook when the customer ticks "save card" during a normal SDK checkout. GET /api/v1/payments/methods only lists what already exists; the encrypted provider token never leaves the server. The first save always happens through the SDK sheet, not an API call. Remove a card with DELETE /api/v1/payments/methods/:id → 200 { id, deleted: true }.

Invoices & PDFs

GET /api/v1/invoices lists the caller's invoices across all three features (?limit=, default 50, max 200, newest-first). Each item carries downloadableUrl when a PDF has already been rendered.

PDFs render lazily. GET /api/v1/owner/invoices/:id/pdf returns 200 { pending: false, url } if cached, or 202 { pending: true, url: null } the first time after dispatching the render job — poll back a few seconds later. The signed URL is valid ~7 days.

{ "data": { "pending": false, "url": "https://cdn.trackme.sa/invoices/INV-20260520-0001.pdf?signature=…" }, "meta": { "requestId": "req_01jq..." } }

The unified order list

GET /api/v1/payments/orders lists the caller's payment orders across all three features. Filter with ?status= and/or ?serviceType=; paginate with ?page= (default 1) + ?perPage= (default 25, max 100). Newest-first. Pagination meta is under meta.pagination (page, perPage, total, totalPages, hasMore).

The webhook (server-to-server — mobile never calls this)

POST /payments/webhook/paymob is not under /api/v1, is CSRF-exempt, and is authenticated by an HMAC-SHA512 signature on the hmac query param. It is the real source of truth that flips pending → paid and creates the activation. A bad signature → 401; a duplicate event → idempotent 200 no-op; an amount/currency mismatch → 200 + logged, no activation. There is also POST /payments/webhook/paymob/subscriptions for recurring subscription state. Mobile never touches either — they exist so you understand where "paid" actually comes from.

Payment-order state table

StateMeaningHow you got hereAllowed next
pendingOrder created, fee due, not live. Awaiting payment + webhook. Expires 30 min after creation.POST .../payment-orders (paid path)paid, failed, cancelled, expired
paidWebhook (or saved-card completed) settled. Invoice + active activation created — service is live.Paymob webhook / charge-saved-card completed / zero-price createrefunded (admin only)
failedGateway hard decline, or a failed/voided webhook.webhook (success:false) / charge-saved-card 502— (start a new order)
cancelledA still-pending order the customer (or admin) cancelled before payment.POST .../payment-orders/:id/cancel— (terminal)
refundedAdmin- or gateway-initiated refund on a paid order; the linked activation is cancelled and the target archived.admin refund / refund webhook— (terminal)
expiredPending order that aged out / was never paid. Reconciled by a background job.quote/order timeout + ReconcilePaymentsJob— (terminal)

Activation state table

StateMeaningHow you got hereAllowed next
activeThe paid service is live (truck featured, job advertised, listing distributed) until expiresAt.order reached paidexpired, cancelled
expiredActivation reached expiresAt; the target is marked expired by the scheduled worker.scheduled expiry worker— (terminal)
cancelledActivation reversed by a refund; the target is archived / unfeatured.order refunded— (terminal)

Transitions

FromToActorVia
(none)order pendingcustomer (owner)POST /api/v1/{feature}/payment-orders
(none)order paid + activation activesystem (zero-price)POST .../payment-orders when quote.requiresPayment is false (immediatelyActivated:true, no clientSecret)
order pendingorder paid + activation activePaymob gatewayPOST /payments/webhook/paymob (success, HMAC-verified)
order pendingorder paid + activation activecustomer (saved card / CIT)POST /api/v1/payments/orders/:id/charge-saved-card → status3ds:"completed"
order pendingorder pending (unchanged, 3-DS step-up)customer (saved card / CIT)charge-saved-card → status3ds:"required" — follow-up webhook settles it
order pendingorder failedPaymob / saved-card declinewebhook (success:false) or charge-saved-card hard decline (502)
order pendingorder cancelledcustomerPOST /api/v1/{feature}/payment-orders/:id/cancel
order pendingorder paid/failed/expired (reconciled)system (ReconcilePaymentsJob)cron inquiry for orders pending > 30 min when the webhook was lost
order paidorder refunded + activation cancelledadmin or gatewayadmin refund endpoint, or refund TRANSACTION webhook (target archived)
activation activeactivation expiredsystem (scheduled worker)activation reaches expiresAt

Implementation Notes

Integration issueCorrect handling
Treating the POST .../payment-orders 201 as success and showing the paid service as live.The order is pending — no paid activation is live. It only goes live when the webhook (or saved-card completed) flips it to paid and creates the active activation. The create response is intent to pay.
Treating a successful SDK sheet close, or the /payments/return redirect, as proof of payment.The server webhook is the single source of truth. After the sheet closes, poll GET /api/v1/payments/orders/:id until status is paid. Expect a few seconds of lag.
Reading clientSecret: null as a failure.Null secret happens only on the zero-price path (immediatelyActivated: true). On the paid path the secret is always present (the server 502s otherwise). Branch on immediatelyActivated.
Showing success on charge-saved-card status3ds: "required".That order is still pending — the 3-DS step-up is not done. Only status3ds: "completed" means paid; otherwise poll for the follow-up webhook.
Displaying totalAmountMinor raw, or summing across currencies.Amounts are integers in the minor unit — divide by minorScale from GET /api/v1/currencies (100 for SAR/USD). Never sum across rows with different currencyCode. Note charge-saved-card returns totalAmountMinor as a string.
Trying to cancel a paid order, or expecting cancel to refund.Cancel works only on pending orders (409 otherwise). Unwinding a paid order requires an admin refund — there is no customer refund endpoint.
Holding a stale clientSecret / quote and re-using it.Quotes expire after 15 min; orders expire 30 min after creation. A pending, never-paid order is reconciled by a background job and ends up paid/failed/expired. Re-quote and re-create if stale.
Looking for a client "add/save card" endpoint.No client endpoint exists for this. Cards are saved server-side from Paymob's TOKEN webhook when the user ticks "save card" during an SDK checkout. GET /payments/methods only lists existing cards.
Retrying on 409 SAVED_CARD_TOKEN_UNREADABLE.The stored token can no longer be decrypted (e.g. key rotation). Prompt the user to re-save the card via a fresh SDK checkout instead of retrying.
Conflating cross-tenant 403 vs 404.Someone else's order on the unified GET /api/v1/payments/orders/:id (and charge-saved-card) returns 404 (existence is never leaked). The feature-specific GET /api/v1/{feature}/payment-orders/:id (and .../cancel) returns 403 when the order exists but is not yours, 404 when it does not exist. Someone else's saved card returns 403. Handle all of these.
Polling the invoice PDF once and giving up on 202.PDFs render lazily: the first call may return 202 { pending: true }. Poll back a few seconds later for { pending: false, url }. The signed URL expires in ~7 days.
Hardcoding one URL family for all three services./featured-listings, /job-advertising, /marketplace-distribution are three families with identical shapes. Key the prefix on serviceType. Use the unified /api/v1/payments/orders and /api/v1/invoices to read across all three.
  • Truck Management — the featured_truck target an activation features
  • Jobs — the job_advertisement target an activation publishes
  • Marketplace — the marketplace_listing target an activation distributes
  • Notifications & Push — the payment_succeeded push fired on settlement
  • Order Lifecycle — note customer food orders record paymentMethod: in_person (no online charge), separate from this paid-services pipeline
  • API reference

On this page