API (api-v2)
Orders, refunds & returns
The server prices every order, applies discounts and tax, draws stock from one or more locations, and posts to the ledger. Refunds move money, returns move goods, and the two are kept separate.
Orders
Tables:
ordersorder_line_item: per-linelocation_id,note, preorder snapshotorder_shipping_line,order_payment,order_transaction,order_adjustmentshop_pos_customer: the synthetic walk-in buyer- refund tables
- Lookups:
order_source,financial_status,cancel_reason
| Route | Guard |
|---|---|
get-shop-orders (filters, archive scope, sort) | perm orders.view |
get-orders, get-order-actions, cancel-order, mark-order-as-paid, close-order, reopen-order | oScoped |
create-order | requirePermissionAtAll orders.create (every location the order names) |
Pricing rules
- The unit price comes from the variant, converted from USD. A merchant may override it, or enter a custom line.
- Modifier deltas are added to the unit price.
- Line discounts are applied before tax.
- Tax is computed per line, from the variant's
taxableflag and the shop'stax_rate. Withtaxes_included, tax is backed out of the price instead of added. - The order-level discount is applied after tax.
Behaviour
- Idempotent: a repeated idempotency key returns the original order (
idempotentReplay). - Multi-location: each line has its own
location_id, or setautoRouteand the server picks. - Partial payments:
mark-order-as-paidtakes an amount, and each instalment writes one ledger entry. - Ledger: the sale posting runs in the order's transaction. The payment posting runs after commit, through
accountingClient.
Enumerations
| Enum | Values |
|---|---|
| Source | pos, online, merchant, the_circle, the_circle_kids, the_circle_arabic (the last three have no write path yet) |
| Financial status | pending, authorized, partially_paid, paid, partially_refunded, refunded, voided |
| Cancel reason | customer, fraud, inventory, declined, other |
The dashboard asks get-order-actions / get-fulfillment-actions which buttons to render. It never infers allowed actions client-side.
Refunds
Routes: calculate-refund, create-refund, get-order-refunds [oScoped]
- The refund is capped at collected − already refunded. This is re-checked under a row lock.
- Tax is apportioned from the original snapshot, not recalculated.
- Restock types:
no_restock,cancel(never shipped),return. restockOnlyreturns goods with no money movement, which the dashboard uses on unpaid orders.paidFromDrawertakes cash out of the caller's open drawer, so shift expected cash stays correct.- Adjustments: shipping refund, discrepancy, restocking fee.
Returns
Tables: order_return*, reverse_fulfillment_order*, reverse_delivery
Routes: get-returnable-items, create-return, get-order-returns, receive-return-items, update-reverse-delivery, cancel-return, close-return [oScoped]
- Only shipped units are returnable.
- A return never touches money.
- Stock moves only when items are received and dispositioned: restocked, damaged, not restocked, disposed, or still processing.
- Statuses: requested, open, closed, declined, canceled.
- Reasons (11):
unknown,defective,wrong_item,not_as_described,size_too_large,size_too_small,color,style,unwanted,delivery_failed,other.
Fulfillment
Routes: get-fulfillment-orders, get-order-fulfillment-orders, get-fulfillments, get-order-fulfillments, get-fulfillment-actions, create-fulfillment, cancel-fulfillment, update-fulfillment-shipping [oScoped]
- Partial fulfilment, with quantities per line.
- Tracking is manual (company, URL, number), or uses one of the merchant's own carriers.
- Not ported: live carrier labels and rates (Wakilni). Passing a
carrierCodereturns 400. - Deferred: a preorder fulfillment hold (
check_later.md#14).
Carriers & packages
Tables:
carrier: the platform catalogueshop_carrierpackagemerchant_carrier: the shop's own named couriers
| Route | Guard |
|---|---|
/merchant/carriers/v1/get-carriers | oScoped |
get-shop-carriers, add-shop-carrier, disable-shop-carrier | wide orders.fulfill |
get-shop-packages, create/update/delete-package, set-default-package | wide orders.fulfill |
get-merchant-carriers | perm orders.fulfill |
create/update/delete-merchant-carrier | wide orders.fulfill |