Orders
Lifecycle, statuses, and the refund flow that actually calls the payment provider.
An order is created from a cart at checkout. From that point on it lives independently: variants can be deleted, prices can change, and the order remembers what was sold and for how much via a JSON snapshot of every line.
Statuses
pending → paid → fulfilled
↓
refunded- draft: being put together (a quote), not yet placed.
- pending: placed, waiting for payment. Stock is reserved.
- paid: paid, goods not all delivered yet.
- fulfilled: every unit delivered (set by the order's shipments).
- cancelled: terminal. Reservations released.
- refunded: money returned. Terminal. See below.
Shipping progress is not an order status. Read fulfillment_status
(unfulfilled, partially_fulfilled, fulfilled, cancelled) and the
order's shipments. Where the money is lives in payment_status.
The status enum may gain values. Treat a status you don't recognize as
"in progress" rather than failing (see
API conventions).
Endpoints
Paths are relative to https://api.mobiari.com/v1. There is no store in
the path: a store API key (Authorization: Bearer mobi_sa_…) works only
for its store. With any other credential, send the store's id in the
Mobiari-Store header. The full list is in the
API reference.
| Method | Path | Purpose |
|---|---|---|
GET | /orders | List, newest first. Filters: status, customer_id, search, include_test, created_after, created_before. |
POST | /orders | Create an order. It starts pending. With source: manual, a sale already paid (see below). |
GET | /orders/{order_id} | Single order with lines, payment state, shipments and refunds. |
PATCH | /orders/{order_id} | Set the order's notes and its shipping_address. |
POST | /orders/{order_id}/cancellation | Cancel the order. With {"refund": true} it also returns what was paid. |
GET | /orders/{order_id}/payments | The order's payment attempts. |
POST | /orders/{order_id}/payments | Record a payment received outside a gateway (cash, card machine, PIX to the store's own key). |
POST | /orders/{order_id}/refunds | Refund through the payment provider, or record one made by hand (method: manual). Answers the order. |
GET | /refunds | List refunds. Filter by order_id. |
POST | /shipments | Add a shipment to an order (order_id goes in the body). |
PATCH | /shipments/{shipment_id} | Update a shipment: status, carrier, tracking code. |
The list is a Page: data,
has_more and next_cursor. Paging is by cursor and limit only;
offset is refused with 400 offset_not_supported. Add
include_total=true to also get total.
curl "https://api.mobiari.com/v1/orders?status=paid&limit=50" \
-H "Authorization: Bearer $MOBIARI_KEY"Setting an order's status directly is not part of the public API yet. An
order becomes paid through its payments, fulfilled through its
shipments, cancelled through POST /orders/{order_id}/cancellation and
refunded through its refunds. A sale already paid elsewhere is one
request: see A sale already paid.
Create an order
curl -X POST "https://api.mobiari.com/v1/orders" \
-H "Authorization: Bearer $MOBIARI_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"customer_id": "0199a4f2-6c1e-7d3a-9b1f-3e2c8a5d7f10",
"items": [
{ "variant_id": "0199a4f3-1b2c-7e4d-8a9f-5c6d7e8f9a0b", "quantity": 2 }
]
}'Every line is priced from the catalog and its stock is reserved. Only
items is required; customer_id, discount_code and
sales_channel_id are optional. If there is not enough stock the API
answers 409 insufficient_stock.
A sale already paid
For a sale made somewhere else and paid there (a counter, WhatsApp, an
event), send "source": "manual" with the payment. The order is
created, its stock reserved and the payment recorded in one step, and
the answer is the order, paid:
curl -X POST "https://api.mobiari.com/v1/orders" \
-H "Authorization: Bearer $MOBIARI_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"source": "manual",
"sales_channel_id": "0199a4f4-…",
"items": [{ "variant_id": "0199a4f3-…", "quantity": 2 }],
"payments": [{ "method": "cash", "amount_received_cents": 6000 }],
"contact": { "name": "Rosa", "phone": "+5511999990000" }
}'sales_channel_id is a point of sale (type: pos in
GET /sales-channels). The answer adds change_cents (what was
received in cash over what the cash paid). With a pix_qr payment the
order stays pending and the answer adds pix, the code to show the
buyer.
payments is how the sale is paid. One payment needs no amount: it
covers the total. Several in-person payments (cash plus the card
machine, two cards) each say their amount_cents and must add up to the
total (payments_total_mismatch says what the total is); pix_qr is
always the only payment. A card_terminal payment may say
card: { "kind": "credit", "installments": 3 } or { "kind": "debit" }.
The refund flow
The Reembolsar button in the admin (and
POST /orders/{order_id}/refunds in the API) doesn't just flip a
database column. It actually calls the payment provider. Today that's
Mercado Pago. The handler:
- Loads the latest approved payment for this order.
- Calls Mercado Pago's refund API. Empty body = refund everything still
refundable;
{"amount_cents": 1234}= partial refund of R$ 12,34. More than what is left is refused with 422refund_exceeds_refundable. - Only on a successful provider response does it touch local state.
A full refund marks the order
refunded, releases inventory reservations, cancels open production and emitsorders.refunded. A partial refund leaves the status alone and setspayment_statustopartially_refunded.
If the provider call fails, local state is left alone and you get a 502
provider_error. When there is nothing to refund you get a 409:
no_refundable_payment (no approved payment) or already_refunded.
A payment taken outside a gateway (cash, card machine, manual PIX)
cannot be refunded through it: the API answers 422
refund_not_supported. Record the refund you made by hand instead, with
"method": "manual" (and amount_cents, reason, both optional): it is
spread over the order's manual payments.
Both kinds answer the order, with its refunds, refunded_cents and
payment_status: one refund can be spread over several payments. So the
key needs orders.read as well; without it the request is refused with
403 before anything is refunded. The same holds for source: manual.
Send an Idempotency-Key
Each refund call is a new refund at the provider. If a partial refund
times out and you retry it blindly, the customer can be refunded twice.
Send an Idempotency-Key header and reuse it on the retry: a refund
that went through is replayed instead of repeated. See
Idempotency. A 503 is the
exception: the gateway failed, or its answer could not be read, so the
refund may or may not have happened, and the key does not keep that
answer. Look at the order's refunds before trying again.
# Full refund:
curl -X POST \
"https://api.mobiari.com/v1/orders/$ORDER_ID/refunds" \
-H "Authorization: Bearer $MOBIARI_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: refund-$ORDER_ID-full" \
-d '{}'
# Partial refund of R$ 30,00:
curl -X POST \
"https://api.mobiari.com/v1/orders/$ORDER_ID/refunds" \
-H "Authorization: Bearer $MOBIARI_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 8d4b0c1e-5a8f-4f7e-b1a2-6c3d9e0f1a2b" \
-d '{"amount_cents": 3000}'Cancel an order
POST /orders/{order_id}/cancellation cancels the order: stock is
released and open production is cancelled. By default the money stays as
it is. Send "refund": true to return what was paid first; note is
kept in the order's history for the team.
curl -X POST \
"https://api.mobiari.com/v1/orders/$ORDER_ID/cancellation" \
-H "Authorization: Bearer $MOBIARI_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: cancel-$ORDER_ID" \
-d '{"refund": true, "note": "Customer asked to cancel"}'The call is idempotent: an order that is already cancelled is returned as it is.
Pickup orders
If the buyer chose Retirar pedido na loja at checkout instead of
shipping, the order carries a pickup_location_snapshot_json and the
freight section is hidden. The snapshot is intentionally a copy of the
location at the time of purchase: you can later edit or delete the
physical location without changing the order's pickup address.
fulfillment_method on the order is either "shipping" or "pickup"
and tells the admin UI which card to render.
Permission cheatsheet
| Action | Permission |
|---|---|
| List, get | orders.read |
| Create | orders.write |
| Set notes | orders.edit |
| Record a payment | orders.manage_payments |
| Cancel | orders.cancel (and orders.refund with refund) |
| Refund | orders.refund |
| Create or update a shipment | shipments.write |