Create a new order + attempt AUTOMATIC payment from balance
POST/orders
Flow with 3 outcomes:
- If
StockService::isAvailable(pid)= false → 409product_unavailable. 1b. If a sub-option CLOSED for reseller sale (e.g. an out-of-stock location) is selected inextra.configoptions→ 409config_option_out_of_stock(Rabisu Mastermod_rabisu_master_configoption_stock.in_stock=0). The reseller module already hides these; this is the server-side second line of defense. - If
periodis outside the whitelist → 422invalid_period. - WHMCS
AddOrder-> an order + unpaid invoice are created. - The reseller's
auto_apply_credittoggle (GET /auth/me) is checked:- false ->
ApplyCreditis SKIPPED;status=pending_payment,payment_applied=false,notice=auto_apply_credit_disabled. The reseller pays the invoice manually (from the panel / by bank transfer) as it prefers. The toggle is enabled via the admin CLI:php bin/api-key-update.php <id> --auto-apply-credit=1. - true (default) -> WHMCS
ApplyCredit(SINGLE call), depending on the result:- success ->
status=pending_provision,payment_applied=true; the WHMCS InvoicePaid hook triggers the virtualizor queue cron. - insufficient funds ->
status=pending_payment,notice=insufficient_credit; the reseller can pay manually. - HTTP 5xx / timeout ->
status=payment_failed, a record is opened in RequestLogger with analarmflag.
- success ->
- false ->
Actions NOT called: AcceptOrder (the WHMCS InvoicePaid hook already kicks in), VirtualizorClient (the WHMCS cron installs the VPS), balance pre-check, DeleteOrder (even in the insufficient edge case).
The Idempotency-Key header is REQUIRED (otherwise 400 missing_idempotency_key). For a same key+body replay a 202 cached response is returned.
Request
Responses
- 202
- 400
- 401
- 409
- 422
- 429
- 500
The order has been written to the DB. status reflects the ApplyCredit result; poll GET /orders/{id} for the VPS to be installed.
Response Headers
Becomes "true" on a repeated request served from cache.
Idempotency-Key header missing
Authentication failed — missing header, wrong credential, outside the IP whitelist, or a revoked key. No detail is leaked; all cases return a single message.
Response Headers
RFC 7617 Basic Auth challenge
Product not in stock (product_unavailable) OR the selected config sub-option is closed for reseller sale (config_option_out_of_stock).
period outside the whitelist or a body validation error
Per-minute limit exceeded
Response Headers
Seconds to wait before retrying after a 429 (RFC 7231 §7.1.3)
The per-minute limit defined for this key
Unix epoch of the start of the next window (UTC seconds)
WHMCS AddOrder upstream error (order not created)