Xuda logo Xuda Docs User Guides
/
xuda.io
← All guides Commerce

Xuda Commerce API Reference

Source file: xuda-commerce-api-reference.md

Xuda Commerce API Reference

This reference covers the full method surface of Xuda Commerce: the twelve unauthenticated storefront methods that power the buyer's cart and checkout, the nineteen dashboard methods that drive the seller's Commerce screens, and the one operator method that releases abandoned stock reservations. It is written for developers embedding the cart on their own website, building against the storefront routes, or understanding exactly what each screen in the Commerce dashboard does. Every method key, parameter name, type and required flag below is taken from the shipped method contract.

How To Call These Methods

Every seller-facing method here is a CPI method. CPI methods are dispatched by name over the Xuda API and MCP layer, and the normal credential for that layer is the account API key. For the transport-level detail, including how requests are framed and how the MCP layer exposes methods, see /api-mcp-integration.

Commerce is an unusual case and you should know it before you write a line of code. None of the twenty seller-facing methods is exposed in the API-key catalog. All twenty are flagged private, and a private method is excluded from the API-key catalog and refused for API-key callers. What that leaves you today is:

  • Twelve storefront methods that are not registered in the CPI method table at all. They are reachable only through the Xuda router's own HTTP routes under /store-api/*, they take no session and no key, and they are scoped entirely by the store key. These are the shipped integration surface, and they are what the cart iframe calls.
  • Nineteen methods with user clearance that require a signed-in dashboard session, with the caller identity injected from that session. These are what the product's own screens call. They are documented in full because they define the product's behavior and because any future API tier would expose them.
  • One method with admin clearance, commerce_sweep_reservations, which sweeps held stock reservations and requires a superuser account to sweep across tenants.

Do not build against the twenty seller methods with an API key. They will be refused. The api, api_rate_per_min and webhooks flags that appear on the plan ladder are sold in the ladder and read by nothing today, and the planned commerce_api_* family does not exist in code.

Storefront transport

The storefront methods travel as HTTP JSON on the Xuda router, not over the CPI method dispatcher.

Method Route
commerce_public_origin_allowed called by the router when it serves GET /store-cart/<store_key>
commerce_public_catalog GET /store-api/catalog
commerce_public_product GET /store-api/product
commerce_public_cart_get POST /store-api/cart/get
commerce_public_cart_add POST /store-api/cart/add
commerce_public_cart_update POST /store-api/cart/update
commerce_public_cart_remove POST /store-api/cart/remove
commerce_public_cart_discount POST /store-api/cart/discount
commerce_public_checkout_address POST /store-api/checkout/address
commerce_public_checkout_shipping POST /store-api/checkout/shipping
commerce_public_checkout_pay POST /store-api/checkout/pay
commerce_public_checkout_confirm POST /store-api/checkout/confirm

Tenancy is the store_key, an unguessable st_<16 hex> identifier that comes from the store settings snippet. Every response is { code, data } with code: 1 on success, and failures map to HTTP 402, 403, 404, 409, 422 or 429. All storefront responses are sent Cache-Control: no-store, and storefront request bodies are capped at 32kb.

What The Availability Labels Mean

Every method below carries one explicit availability line. Read it first, because it tells you whether you can call the method from your own code today.

  • Availability: API key means an external developer API key or the MCP layer can call it. No Commerce method currently carries this label.
  • Availability: Dashboard session means a signed-in user in the Xuda dashboard can call it, and an API key cannot. The account identity comes from the session, never from a parameter.
  • Availability: Public endpoint means no authentication at all. It is called from the cart iframe or from your own server. The store key is the only scoping credential, and the domain check is what stands in for authentication.
  • Availability: Operator only means Xuda staff clearance. One Commerce method carries this label.

Method Index

Storefront methods, public and unauthenticated

Method What It Does
commerce_public_origin_allowed Decides whether the parent page is allowed to run this store's cart.
commerce_public_catalog Returns the store's published catalog with live availability.
commerce_public_product Returns one published product by id, handle or SKU.
commerce_public_cart_get Reads the whole cart, fully repriced on the server.
commerce_public_cart_add Adds a line and mints a cart on first add.
commerce_public_cart_update Changes a line's quantity, zero removes it.
commerce_public_cart_remove Removes a line.
commerce_public_cart_discount Applies or clears a discount code.
commerce_public_checkout_address Saves contact and delivery address, then quotes delivery.
commerce_public_checkout_shipping Chooses a delivery option by token, never by amount.
commerce_public_checkout_pay Reserves stock, writes the order and starts the Stripe payment.
commerce_public_checkout_confirm Confirms the payment by reading Stripe, then commits stock.

Seller and operator methods

Method What It Does
commerce_list_stores Lists every storefront on the account with its health and the plan.
commerce_create_store Opens another storefront, up to the plan's allowance.
commerce_get_store Reads one store's settings, the plan and this month's usage.
commerce_save_store Saves store settings, domains, payout account and delivery pricing.
commerce_delete_store Closes a storefront that holds no products and no orders.
commerce_save_product Creates or updates a product with variants and shipping facts.
commerce_list_products Lists a store's products, optionally filtered by status.
commerce_get_product Reads one product with live stock per variant.
commerce_delete_product Archives a product so it stops selling.
commerce_set_inventory Sets or adjusts stock on hand for one variant.
commerce_save_discount Creates or updates a discount code.
commerce_list_discounts Lists a store's discount codes with their usage counts.
commerce_delete_discount Removes a discount code permanently.
commerce_list_orders Lists orders newest first with both shipping pots.
commerce_get_order Reads one order in full and self-heals its delivery status.
commerce_fulfil_order Hands a paid order to Xuda Shipping as a draft delivery.
commerce_update_order Updates status, note or the label cost on an order.
commerce_set_plan Switches the account's Commerce tier and opens the first store.
commerce_get_usage Reads this month's paid orders, overage and merchandise value.
commerce_sweep_reservations Releases stock held by checkouts that were abandoned.

commerce_public_origin_allowed

Is this page allowed to run this store's cart

Called by the router when it serves the cart iframe at GET /store-cart/<store_key>. It compares the parent page's host, taken from the honest Referer or Origin header and never from a query string, against the store's allowed_domains, where a subdomain of an allowed domain counts. The domain list is never returned. The caller learns only yes or no, plus a reason: not_published when the list is empty, no_origin when there is no referer, and domain_not_allowed otherwise. This is the anti card-testing control as much as it is configuration, because a public cart endpoint that any page can drive is a magnet for card testing that costs the seller in Stripe fees and processing reputation.

Availability: Public endpoint

Parameters

Name Type Required Description
store_key string Yes The storefront's public key, from the store settings snippet.
origin string Yes The parent page URL or origin. The router supplies this from the request headers.

Notes

  • Auth: none. Plan gate: none.
  • An empty allowed_domains list means the store is not published, and it returns a different reason from a domain that is simply not on the list, so the two cases can be told apart in the cart's own message.
  • The cart iframe is served with frame-ancestors * so it can embed anywhere, and this check is what actually refuses the wrong parent page.
  • Allowed domains are capped at 25 per store and are stored as bare lowercase hostnames.

commerce_public_catalog

The store's published catalog

Returns only status: 'active' products belonging to that storefront, each with its variants, prices, media, options and, when the product tracks stock, a per-variant available count and an in_stock boolean. Products that do not track inventory always report in stock. Free-text search runs over title, short description and tags.

Availability: Public endpoint

Parameters

Name Type Required Description
store (store_key) string Yes The storefront's public key. Sent as the store query parameter.
q string No Free text filter over title, short description and tags.
type (product_type) string No Category label filter, matched against the product's product_type.
limit number No Maximum products, default 60, capped at 200.

Notes

  • Auth: none. Plan gate: none.
  • Rate limited to 300 requests per 15 minutes on the catalog, product and cart routes.
  • Draft and archived products are never returned, so a seller can stage a product without it appearing on the storefront.

commerce_public_product

One published product

Resolves by product_id, by handle (the URL slug) or by sku, always scoped to the calling storefront, and returns the product with per-variant live availability. A SKU is only resolvable inside the store whose page asked for it, so one storefront's button can never surface another storefront's product.

Availability: Public endpoint

Parameters

Name Type Required Description
store (store_key) string Yes The storefront's public key.
product_id string No Exact product id.
handle string No URL slug of the product.
sku string No A variant SKU. Matched across the store's active products.

Notes

  • One of product_id, handle or sku is required.
  • Auth: none. Plan gate: none.
  • Rate limited to 300 requests per 15 minutes.
  • SKU lookup is what makes the one-tag embed work: a seller marks a buy button data-xuda-sku="YOUR-SKU" and the loader resolves it here.

commerce_public_cart_get

Read the cart, fully repriced

Returns the whole recomputed cart every time, never a delta: lines with resolved titles, images, unit prices and line totals, plus subtotal, discount, shipping, handling, total, item count, currency and a problems array. An unknown or expired token silently yields a fresh empty cart whose cart_token is null, because a token for a cart that was never written would make the client create a second cart behind the buyer's back.

Availability: Public endpoint

Parameters

Name Type Required Description
store_key string Yes The storefront's public key.
cart_token string No The opaque cart id held by the buyer's browser. Omit for a new cart.

Notes

  • Auth: none. Plan gate: none.
  • A cart line stores only product_id, variant_id, qty and custom_fields. No amount ever arrives from a browser, and every total is computed from stored products and stored discounts on every read.
  • Carts live 30 days. The document id is the cart token itself.
  • Rate limited to 300 requests per 15 minutes.

commerce_public_cart_add

Add a line

Resolves the product by product_id or by sku, a SKU being the only product identifier a seller can reasonably hand-type into their HTML, mints a cart on first add, and merges into an existing identical line rather than creating a duplicate, unless custom fields are attached. Quantity is clamped to 1..999. Every add extends the cart's 30 day expiry. Returns the whole repriced cart.

Availability: Public endpoint

Parameters

Name Type Required Description
store_key string Yes The storefront's public key.
cart_token string No Existing cart id. Omit to start a cart.
product_id string No Exact product id. Takes precedence over sku.
sku string No Variant SKU, resolved inside this storefront only.
variant_id string No Which variant. Defaults to the product's first variant.
qty number No Units to add, default 1, clamped to 1..999.
custom_fields object No Per-line personalization data. A line carrying custom fields never merges into another line.

Notes

  • Auth: none. Plan gate: none.
  • Nothing is reserved here. Stock is only held at the payment step, which is what stops one script emptying a store's availability without spending a cent.
  • Rate limited to 300 requests per 15 minutes.
  • The response is always the full repriced cart, so a client never has to track amounts of its own.

commerce_public_cart_update

Change a line's quantity

Quantity 0 removes the line. Returns the whole repriced cart.

Availability: Public endpoint

Parameters

Name Type Required Description
store_key string Yes The storefront's public key.
cart_token string Yes The cart to change.
line_id string Yes The cart line to change.
qty number Yes New quantity, clamped to 0..999. Zero removes the line.

Notes

  • Auth: none. Plan gate: none.
  • Rate limited to 300 requests per 15 minutes.

commerce_public_cart_remove

Remove a line

A thin alias for commerce_public_cart_update with quantity zero. Returns the whole repriced cart.

Availability: Public endpoint

Parameters

Name Type Required Description
store_key string Yes The storefront's public key.
cart_token string Yes The cart to change.
line_id string Yes The cart line to remove.

Notes

  • Auth: none. Plan gate: none.
  • Rate limited to 300 requests per 15 minutes.

commerce_public_cart_discount

Apply or clear a discount code

The code is uppercased and validated against this storefront's codes, checking the active flag, the start and end dates and the usage cap. An invalid code is refused outright rather than silently ignored. An empty code clears the discount. The discount is only ever applied to the subtotal, never to the shipping line. Returns the whole repriced cart.

Availability: Public endpoint

Parameters

Name Type Required Description
store_key string Yes The storefront's public key.
cart_token string Yes The cart to change.
code string No The code the buyer typed. Send an empty string to clear it.

Notes

  • Auth: none. Plan gate: none.
  • Codes belong to a store, not to an account, so two of a seller's storefronts can each run their own code of the same name on their own terms.
  • The redemption counter is not incremented here. It moves only when the payment is confirmed.
  • Stacking is explicit data on the code rather than emergent behavior, so two codes cannot quietly compose into a free order.
  • Rate limited to 300 requests per 15 minutes.

commerce_public_checkout_address

Save contact and delivery address, then quote delivery

Validates the email format, and for a cart containing anything shippable requires name, line1, city and a two-letter country. In live shipping mode it asks Xuda Shipping for retail rates and stores the quote id, and if live rates come back empty it falls back to the store's flat rates rather than stranding the buyer. Returns the repriced cart plus a shipping_options array of { token, label, amount_cents, eta_days, carrier, source }, cheapest first for flat rates. A destination with no option at all is refused with "this store does not ship to that country yet".

Availability: Public endpoint

Parameters

Name Type Required Description
store_key string Yes The storefront's public key.
cart_token string Yes The cart being checked out.
email string Yes Buyer's email. Must look like an email address.
shipping_address object Conditional Required when anything in the cart ships. Fields: name, line1 (both required), city, country (two letter, required), plus optional company, line2, state, postal_code, phone.

Notes

  • Auth: none. Plan gate: none for the step itself. Live rates require the store's plan flag connect_shipping === true and a store already saved in live mode.
  • Live quotes return retail prices only, copied field by field, so no wholesale carrier cost can leak into a browser. Commerce never names a carrier of its own: the carrier label is the offer's vendor field passed through.
  • Rate limited to 300 requests per 15 minutes.

commerce_public_checkout_shipping

Choose a delivery option

The client sends a token that names a choice, never an amount. The server re-resolves that token against a freshly computed option set, re-quoting Xuda Shipping for a live: token, so a tampered token resolves to nothing rather than to a cheaper price and the call returns "that shipping option is no longer available, please choose again". Returns the whole repriced cart with the chosen shipping line.

Availability: Public endpoint

Parameters

Name Type Required Description
store_key string Yes The storefront's public key.
cart_token string Yes The cart being checked out.
shipping_token string Yes A token from the previous step's shipping_options, prefixed flat: or live:.

Notes

  • Auth: none. Plan gate: none.
  • Requires the address step to have run first.
  • The seller's handling fee is a line of its own and is only charged when a shipping charge applies. It is never hidden inside a carrier rate.
  • Rate limited to 300 requests per 15 minutes.

commerce_public_checkout_pay

Create the order and start the payment

Re-prices the entire cart from stored data, refuses out-of-stock or unavailable lines with HTTP 409 and a problems array, requires a shipping choice when anything ships, refuses totals under 50 minor units, checks the account's monthly order allowance, then reserves stock for every line or none. It writes the commerce_order document with a per-store sequential order number and creates a Stripe Checkout Session as a direct charge on the seller's connected account, with the discount sent as a real Stripe coupon so the receipt states the per-item price the buyer agreed to, and with an idempotency key derived from the order id and total. A store with no connected Stripe account is refused with HTTP 402. Returns the Stripe checkout URL.

Availability: Public endpoint

Parameters

Name Type Required Description
store_key string Yes The storefront's public key.
cart_token string Yes The cart to convert into an order.

Notes

  • Auth: none. Plan gate: the account's orders_per_month allowance is enforced here.
  • Returns { order_id, order_no, checkout_url, total_cents, currency }, or { order_id, already_paid: true, order_no } when the order was already paid.
  • Rate limited to 10 calls per 15 minutes per IP, separately from the 300 per 15 minutes that covers the catalog and cart routes.
  • Idempotency: the Stripe idempotency key is derived from the order id and the total, and the order document id is derived from the cart id, so a replication conflict on the order is impossible by construction.
  • Stock reservations are all or nothing per cart and live 20 minutes. An abandoned checkout releases them.
  • Minimum order total is 50 minor units, below which the refusal reads that the total is below the minimum a card payment can take.
  • Once the monthly allowance is spent, a plan with an overage_per_order above zero lets the order through and marks it as overage. The Free plan has zero overage and refuses.
  • The charge is a direct charge on the seller's connected account, so the seller is the merchant of record. Where the plan takes a cut, it rides along as application_fee_amount computed on the order total including shipping and handling.

commerce_public_checkout_confirm

Confirm the payment

Reads the truth from Stripe rather than trusting the redirect, because anyone can open a success URL. It is also called server side by the /store/thanks page. On a confirmed payment it commits the stock reservation, flips the order to paid and open, records the payment intent, adopts Stripe's shipping address and customer name when the order had none, marks the cart converted, increments the discount's usage counter and meters the order against the monthly allowance.

Availability: Public endpoint

Parameters

Name Type Required Description
store_key string Yes The storefront's public key.
order_id string Yes The order id returned by the pay step.

Notes

  • Auth: none. Plan gate: none.
  • Idempotency: safe to call repeatedly. An already-paid order returns its public shape with replayed: true, and an unsettled payment returns pending: true.
  • This is the only place the monthly usage counter moves. Carts and catalog reads are never metered.
  • There is no inbound webhook for this. Payment confirmation is a pull from Stripe, which is why the call is written to be replayed from a thank-you page.

commerce_list_stores

List Stores

Lists every storefront this account runs, with what each one holds (products, orders this month, whether it is published) plus the account's commerce plan and whether Commerce has been switched on at all. This is the one call the Commerce landing screen makes. Returns per-store rows with store_id, store_key, name, currency, published (true when the domain list is non-empty), the first three domains and a total domain count, paid_ready (a Stripe account is connected), shipping mode, product and active-product counts, orders this month and monthly GMV, plus account-level activated, plan_id, plan_name, price, flags, store_limit, can_create and usage.

Availability: Dashboard session

Parameters

This method takes no parameters.

Notes

  • Auth: authenticated user. Plan gate: none to call.
  • The counting pass caps at 2000 products and 5000 orders per account read, and sets a products_capped or orders_capped flag when a cap is hit.
  • published is derived from the domain list, not from a separate switch. An empty list means no website is allowed to run the cart yet.

commerce_create_store

Create Store

Opens another storefront, up to the number the plan includes. Each store has its own key, domain list, catalog, discount codes and order numbering. It is refused before a plan has been chosen, with "choose a Commerce plan before opening a store", and refused once the plan's stores allowance is used.

Availability: Dashboard session

Parameters

Name Type Required Description
name string No Store name shown to buyers. Defaults to "Store N". Truncated to 120 characters.

Notes

  • Auth: authenticated user. Plan gate: flags.stores, which is 1 on Free and Starter, 3 on Growth and 10 on Scale.
  • The monthly order allowance stays one account-wide pool no matter how many storefronts are open.
  • The account's first store keeps a deterministic id, so documents written before multi-store existed still resolve into it. Later stores get a random id.

commerce_get_store

Get Store

Reads this account's store settings, its commerce plan and this month's order usage. It creates the store on first read so a new seller has somewhere to configure. Returns { store, plan_id, plan_name, price, activated, flags, usage }, where usage counts orders, overage and GMV per account rather than per store.

Availability: Dashboard session

Parameters

Name Type Required Description
store_id string No Which storefront to work on. Defaults to the account's first store.

Notes

  • Auth: authenticated user. Plan gate: none.
  • Where any seller method takes store_id, omitting it means the account's first, oldest store.

commerce_save_store

Save Store

Saves store settings: name, currency, connected Stripe account, allowed domains, shipping mode and flat rates, handling fee and policies. Domains are normalized to bare lowercase hostnames, because a full URL in the list would silently match nothing and look exactly like a broken widget. It refuses live carrier rates unless the plan includes them and the seller's Xuda Shipping wallet can actually pay for a label, checked at the moment the seller opts in rather than at 3am with an order waiting.

Availability: Dashboard session

Parameters

Name Type Required Description
store_id string No Which storefront to work on. Defaults to the account's first store.
name string No Store name shown to buyers. Max 120 characters.
currency string No Three letter ISO currency, for example USD.
finance_account_id string No The connected Stripe account that takes the money. The seller is the merchant, not Xuda. Must be a real Connect account, not a Finance delegate seat.
allowed_domains array No Hostnames allowed to call the storefront, max 25. Also the anti card-testing control. An empty list keeps the cart switched off.
shipping object No { mode: 'flat' | 'live', flat_rates: [{ id, label, countries[], amount_cents, eta_days }], free_over_cents }. Max 25 flat rates.
handling_fee_cents number No Seller handling fee, shown to the buyer as its own line, never hidden inside a carrier rate. Only charged when a shipping charge applies.
policies object No { returns, terms, privacy, contact_email }.
checkout object No { collect_phone, terms_required, note_enabled }.

Notes

  • Auth: authenticated user. Plan gate: flags.connect_shipping === true for mode: 'live'. The Free plan carries the string "flat_only", so live rates are refused there with a message saying live carrier rates need a plan that includes the shipping integration and that flat rates are available on every plan.
  • The wallet check accepts a positive balance or an armed auto top-up, and it fails open when Xuda Shipping is unreachable.
  • Currency is one ISO code per store. There is no per-currency price override today.

commerce_delete_store

Delete Store

Closes a storefront. It is refused while the store still holds products or any orders, and refused for the account's only store. Orders are financial records and products are work, so the refusal names what to clear first.

Availability: Dashboard session

Parameters

Name Type Required Description
store_id string Yes The storefront to close.

Notes

  • Auth: authenticated user, must own the store. Plan gate: none.
  • The refusal is a sentence naming what is in the way, so the seller knows whether products or orders are blocking the close.

commerce_save_product

Save Product

Creates or updates a product with its variants, price, media, inventory policy and the shipping facts (weight, dimensions, HS code, country of origin) that a correct shipping rate and a customs document need. Every product ends up with at least one variant even when the seller defined no options, so one code path prices a t-shirt in three sizes and a single ebook. A shippable product cannot be published without a weight, and no product can be published without a price. A missing HS code or country of origin comes back as warnings alongside a successful save.

Availability: Dashboard session

Parameters

Name Type Required Description
store_id string No Which storefront to work on. Defaults to the account's first store.
product_id string No Omit to create a new product.
title string Yes Product name. Max 200 characters.
handle string No URL slug. Derived from the title when omitted.
description string No Full description shown on the product page. Max 20000 characters.
short_description string No One line summary for cards and listings. Max 500 characters.
kind string No physical, digital or service. Defaults to physical.
status string No draft, active or archived. Only active products are sold. Defaults to draft.
price_cents number No Price in minor units. Variants may override it.
compare_at_cents number No Was-price, shown struck through.
cost_cents number No What the item costs the seller. Never shown to a buyer.
media array No Up to 20 image URLs, or objects with url and alt.
options array No Up to 3 option axes, for example Size and Color. Each is { name, values[] }.
variants array No Variants with sku, barcode, option_values, price_cents, compare_at_cents, weight_g and image. A variant with no price inherits the product's.
requires_shipping boolean No Whether this item is physically shipped. Defaults to true for physical.
weight_g number No Weight in grams. Required before a shippable product can be published.
dims object No { l_mm, w_mm, h_mm }.
hs_code string No Customs tariff code, needed for international shipments. Digits and dots only, max 14 characters.
origin_country string No Two letter country of manufacture, needed for customs.
track_inventory boolean No Whether stock is counted for this product.
inventory_policy string No deny stops selling at zero, continue allows backorders. Defaults to deny.
tags array No Up to 30 free-text tags for filtering.
product_type string No Category label used by the storefront filter.
min_qty number No Minimum units per order.
max_qty number No Maximum units per order, 0 for no limit.
tax_code string No Tax code carried on the product. Accepted and stored, not yet consumed by any pricing path.

Notes

  • Auth: authenticated user, must own the product when updating. Plan gate: flags.products on create, flags.variants_per_product on save.
  • The product allowance is counted per account across all storefronts, not per store: 10 on Free, 100 on Starter, 1000 on Growth and unlimited on Scale.
  • Variants per product are 3 on Free, 25 on Starter and 100 on Growth and Scale. An unlimited setting falls back to a hard cap of 100.
  • Two publish blocks exist because both produce a wrong price: no weight on a shippable product going active, and no price anywhere on any product going active.
  • A save that succeeds with a missing HS code or origin country returns warnings rather than failing, and the dashboard shows them in an amber "Saved, with a note" panel.
  • Variant ids are minted by this call. Stock has to be written afterwards with commerce_set_inventory, once the ids exist.

commerce_list_products

List Products

Lists this store's products, optionally filtered by status. Scoping to the storefront happens in memory rather than in the query selector, because the account-wide query is the one the database is indexed for.

Availability: Dashboard session

Parameters

Name Type Required Description
store_id string No Which storefront to work on. Defaults to the account's first store.
status string No draft, active or archived.
limit number No Maximum rows, default 200, capped at 500.

Notes

  • Auth: authenticated user. Plan gate: none.

commerce_get_product

Get Product

Reads one product with its live stock per variant. Stock is returned as { on_hand, reserved, available } per variant, and is null for a product that does not track inventory.

Availability: Dashboard session

Parameters

Name Type Required Description
product_id string Yes Product to read.

Notes

  • Auth: authenticated user, must own the product. Plan gate: none.
  • Available stock is on_hand minus reserved, and reservations are the 20 minute holds taken at the payment step.

commerce_delete_product

Archive Product

Archives a product so it stops selling. This is never a hard delete, because paid orders reference the product and a missing product turns an order history into a row of blanks.

Availability: Dashboard session

Parameters

Name Type Required Description
product_id string Yes Product to archive.

Notes

  • Auth: authenticated user, must own the product. Plan gate: none.
  • The same effect is available by saving the product with status: 'archived'.
  • Archived products are excluded from the storefront catalog immediately, since only active products are ever returned publicly.

commerce_set_inventory

Set Inventory

Sets or adjusts stock on hand for one variant. The stock document id is derived from the variant id, so the hot path is a direct read and two writers cannot mint two stock records for one variant. Writes use a strict-save plus re-read loop of up to 6 attempts, so two people counting stock at once cannot merge a stale number forward and oversell. A contended write returns "inventory is being changed elsewhere, try again".

Availability: Dashboard session

Parameters

Name Type Required Description
product_id string Yes Product the variant belongs to.
variant_id string Yes Variant to stock.
on_hand number No Absolute quantity to set.
adjust_by number No Signed change to apply instead of an absolute set.

Notes

  • One of on_hand or adjust_by is required.
  • Auth: authenticated user, must own the product. Plan gate: none.
  • Stock only counts for a product saved with track_inventory on. An untracked product always reports in stock on the storefront.

commerce_save_discount

Save Discount

Creates or updates a discount code: percent, fixed amount or free shipping, with a minimum subtotal, a usage cap and a date window. Codes are stored uppercase and belong to a store, not to an account, so two of a seller's storefronts may each run their own SUMMER10 on their own terms. Stacking is explicit data rather than emergent behavior, so two codes cannot quietly compose into a free order.

Availability: Dashboard session

Parameters

Name Type Required Description
store_id string No Which storefront to work on. Defaults to the account's first store.
discount_id string No Omit to create.
code string Yes What the buyer types. Stored uppercase, max 40 characters.
type string No percent, fixed or free_shipping. Defaults to percent.
value number No Percent 0 to 100, or an amount in minor units.
min_subtotal_cents number No Cart subtotal required before the code applies.
max_uses number No Total redemptions allowed, 0 for unlimited.
starts_ts number No Epoch milliseconds the code becomes valid.
ends_ts number No Epoch milliseconds the code expires.
stackable boolean No Whether this code may combine with another. Defaults to false.
active boolean No Turn the code on or off without deleting it. Defaults to true.

Notes

  • Auth: authenticated user. Plan gate: flags.discounts on create, counted per account. Free includes 1, Starter 25, Growth and Scale unlimited.
  • A discount is only ever applied to the subtotal, never to the shipping line.
  • The uses counter is incremented when a payment is confirmed, not when a buyer types the code.
  • At checkout the discount is sent to Stripe as a real coupon, so the receipt states the per-item price the buyer agreed to.

commerce_list_discounts

List Discounts

Lists this store's discount codes with their usage counts.

Availability: Dashboard session

Parameters

Name Type Required Description
store_id string No Which storefront to work on. Defaults to the account's first store.

Notes

  • Auth: authenticated user. Plan gate: none.
  • The discount list is capped at 200 rows.

commerce_delete_discount

Delete Discount

Removes a discount code permanently.

Availability: Dashboard session

Parameters

Name Type Required Description
discount_id string Yes Code to remove.

Notes

  • Auth: authenticated user, must own the discount. Plan gate: none.
  • Unlike a product, a discount is a hard delete. Use active: false on commerce_save_discount to switch a code off without losing it.

commerce_list_orders

List Orders

Lists orders newest first with their status, payment status and fulfilment status, plus what the buyer paid for shipping next to what the label actually cost and the net between them, so a seller can see when they are shipping below cost. Each row carries order_id, order_no, buyer email, the three status axes, currency, total, item count, shipping_charged_cents, shipping_cost_cents, shipping_net_cents and the created timestamp.

Availability: Dashboard session

Parameters

Name Type Required Description
store_id string No Which storefront to work on. Defaults to the account's first store.
status string No pending, open, completed or cancelled.
payment_status string No unpaid, authorized, paid, partially_refunded, refunded, disputed or failed.
limit number No Maximum rows, default 100, capped at 500.

Notes

  • Auth: authenticated user. Plan gate: none.
  • shipping_net_cents goes negative when the seller charged less for delivery than the label cost, which is exactly the case the Orders screen paints red.
  • Order numbers are sequential per store starting at 1000, so a buyer can read one out over the phone.
  • Commerce never writes partially_refunded, refunded or disputed itself. Refunds are handled in Finance and are out of scope for this module.

commerce_get_order

Get Order

Reads one order in full, including priced lines, addresses, totals, payment reference and any delivery id. It self-heals on read: an order whose delivery has moved on since the last look gets its fulfilment status refreshed from Xuda Shipping, so the screen never depends on a webhook having worked. Shipping's status vocabulary is mapped onto Commerce's in one place, so no carrier string ever reaches a Commerce screen.

Availability: Dashboard session

Parameters

Name Type Required Description
order_id string Yes Order to read.

Notes

  • Auth: authenticated user, must own the order. Plan gate: none.
  • The three status axes are independent fields: order status (pending, open, completed, cancelled), payment status (unpaid, authorized, paid, partially_refunded, refunded, disputed, failed) and fulfilment status (unfulfilled, ready, partially_shipped, shipped, delivered, returned).
  • The order lines are a fully priced snapshot taken when the order was written, so a later price change never rewrites history.

commerce_fulfil_order

Fulfil Order

Hands a paid order to Xuda Shipping as a draft delivery, filed under the order's own storefront profile. Buying the label stays a separate, deliberate act in Shipping, because that is what spends the seller's shipping wallet. It refuses an unpaid order. An order with nothing shippable is closed out as shipped and completed. It requires a ship-from address in the seller's Xuda Shipping locations, and says so in plain words when there is none: add the address you ship from before fulfilling an order, because Xuda Shipping needs it to price and print a label.

Availability: Dashboard session

Parameters

Name Type Required Description
order_id string Yes Paid order to fulfil.
service_mode string No parcel or local. Defaults to parcel.
from object No Ship-from address override. Must carry at least country and line1 to be used.

Notes

  • Auth: authenticated user, must own the order. Plan gate: none in Commerce. Xuda Shipping applies its own.
  • Idempotency: an order that already has a delivery returns it with replayed: true rather than creating a second one.
  • The row moves to ready fulfilment status once the draft delivery exists. It does not become shipped until Shipping says so, which commerce_get_order picks up on read.
  • The label cost is not known here. Write it later with commerce_update_order so the per-order shipping net becomes real.

commerce_update_order

Update Order

Updates an order's status, fulfilment status, internal note, or the label cost once Shipping has spent it, which is what makes the per-order shipping net real. Cancelling an unpaid order releases its held stock. Cancelling a paid order is refused: refund the order from Finance first, a paid order cannot just be cancelled.

Availability: Dashboard session

Parameters

Name Type Required Description
order_id string Yes Order to update.
status string No pending, open, completed or cancelled.
fulfilment_status string No unfulfilled, ready, partially_shipped, shipped, delivered or returned.
note string No Internal note on the order. Max 2000 characters.
shipping_cost_cents number No What the label cost from the shipping wallet.

Notes

  • Auth: authenticated user, must own the order. Plan gate: none.
  • This method has no dashboard control today. Recording a label cost or an internal note is an API-shaped operation, performed from a first-party caller with a dashboard session.
  • Writing shipping_cost_cents is what turns the Orders screen's Difference card from an estimate into a real number.

commerce_set_plan

Set Commerce Plan

Switches the account to a Xuda Commerce plan and adds it to the consolidated subscription. Picking a plan is what switches Commerce on, and it opens the account's first storefront in the same call. It refuses a downgrade that would strand more published products than the lower tier includes, would leave more storefronts open than the tier allows, or would leave a store on live carrier rates the tier does not include. Downgrades that Stripe schedules for the end of the paid period return scheduled: true and leave the current tier in place until the subscription webhook moves it.

Availability: Dashboard session

Parameters

Name Type Required Description
plan_id string Yes Plan key: commerce_free, commerce_starter, commerce_growth or commerce_scale.

Notes

  • Auth: authenticated user. Plan gate: this is the gate.
  • The downgrade check counts published products only, not drafts or archived ones.
  • No Commerce plan is billed today. All four Stripe price ids are still placeholders, and the subscription call refuses a placeholder price id, so a tier can be selected and its entitlements granted without a subscription line ever being created. Treat the ladder as entitlement, not as billing.

commerce_get_usage

Get Commerce Usage

This month's paid orders, overage count, gross merchandise value and what the plan includes, plus the remaining allowance, the overage price per order and the transaction fee percentage. Carts and catalog reads are never metered. included and remaining come back as -1 when the plan is unlimited.

Availability: Dashboard session

Parameters

This method takes no parameters.

Notes

  • Auth: authenticated user. Plan gate: none.
  • Usage is counted per account per month, not per store, so several storefronts draw on one pool.
  • The counter moves only when a payment is confirmed, which is why an abandoned checkout costs a seller nothing.

commerce_sweep_reservations

Sweep Stock Reservations

Releases stock held by checkouts that were abandoned at the payment step, so a store does not slowly reserve itself into looking sold out. It is safe to run on a schedule, since every guard is a no-op when nothing has expired. It scans up to 500 held reservations per run and returns { checked, released }.

Availability: Operator only

Parameters

Name Type Required Description
owner_uid string No Sweep one tenant only. Omit to sweep all, which requires superuser.

Notes

  • Auth: clearance admin. Sweeping every tenant requires a superuser account id. Plan gate: none.
  • Nothing calls this on a schedule today. It is registered as a non-job with no scheduler entry, so abandoned 20 minute reservations are released only when the method is called.
  • A reservation is held all-or-nothing per cart, committed when the payment is confirmed and released on failure, cancellation or a sweep.

The Plan Ladder And What It Gates

Four tiers, commerce_free, commerce_starter, commerce_growth and commerce_scale. Prices are deliberately not quoted here: all four Stripe price ids are still placeholders, the subscription call refuses a placeholder price id, and commerce_set_plan writes the tier anyway, so no Commerce plan is billed today and any figure would be misleading.

Flag Free Starter Growth Scale
products 10 100 1000 unlimited
variants_per_product 3 25 100 100
orders_per_month 50 500 3000 20000
overage_per_order 0, a hard stop 0.05 0.03 0.02
transaction_fee_pct 2 0 0 0
stores 1 1 3 10
currencies 1 1 3 unlimited
checkout stripe_hosted xuda_hosted xuda_hosted xuda_hosted
custom_checkout_domain false false true true
digital_products false true true true
subscription_products false false true true
discounts 1 25 unlimited unlimited
abandoned_cart false false true true
connect_shipping flat_only true true true
connect_tickets false true true true
connect_ai_agent false false true true
trust_badge false true true true
reviews false false true true
api none read full full
api_rate_per_min 0 30 60 240
webhooks false true true true
seats 1 3 10 unlimited
retention_days 90 365 730 unlimited

Enforced in code today: stores on create and on downgrade, products on create (counted per account across all storefronts) and on downgrade (counted against published products only), variants_per_product on save, discounts on create (counted per account), orders_per_month at pay time, overage_per_order at pay time, transaction_fee_pct as the Stripe application_fee_amount computed on the order total including shipping and handling, and connect_shipping when a store opts into live carrier rates.

Present in the ladder but not read by any code path today: currencies, checkout, custom_checkout_domain, digital_products, subscription_products, abandoned_cart, connect_tickets, connect_ai_agent, trust_badge, reviews, api, api_rate_per_min, webhooks, seats and retention_days. Two of these matter for planning an integration:

  • Every checkout goes to Stripe-hosted Checkout regardless of the checkout: "xuda_hosted" flag on the paid tiers.
  • The api, api_rate_per_min and webhooks flags describe an external API that does not exist. There are no Commerce methods reachable with an API key and no outbound webhooks.

Errors

Storefront responses use the { code, data } envelope with code: 1 on success. Failures map onto HTTP status codes:

Status Meaning
402 Payment is not possible: the store has no connected Stripe account, or the monthly order allowance is spent on a plan with no overage.
403 The parent page's host is not on the store's allowed domain list, or the store is not published.
404 The store, product, cart or order does not exist for this store key.
409 The cart moved between reading and paying: something went out of stock or unavailable. A problems array names each line.
422 The request did not validate: a bad email, a missing address field, a missing shipping choice, or a total below the 50 minor unit minimum.
429 A rate limit was exceeded.

Refusals you will meet in normal use, quoted from the product:

  • No delivery option for the destination: this store does not ship to that country yet.
  • A stale or tampered shipping token: that shipping option is no longer available, please choose again.
  • The Free plan's monthly cap: this store has reached its 50 orders for the month on the Free plan.
  • Live carrier rates on a plan without them: live carrier rates need a plan that includes the shipping integration, and flat rates are available on every plan.
  • No ship-from address at fulfilment: add the address you ship from before fulfilling an order, because Xuda Shipping needs it to price and print a label and it lives in your Shipping locations.
  • Cancelling a paid order: refund this order from Finance first, a paid order cannot just be cancelled.
  • A contended inventory write: inventory is being changed elsewhere, try again.
  • Opening a store before choosing a tier: choose a Commerce plan before opening a store.

Seller-facing methods return the platform CPI error envelope. A refusal on entitlement carries code: -402. Ownership is checked per document on every method that names a store_id, product_id, discount_id or order_id.

Rate Limits

Scope Limit
Storefront catalog, product and cart routes 300 requests per 15 minutes
Storefront pay step (commerce_public_checkout_pay) 10 requests per 15 minutes per IP
Storefront request body size 32kb

The seller-facing methods carry no rate limit of their own. The api_rate_per_min values on the plan ladder describe an API tier that does not exist yet and are not enforced anywhere.

Idempotency, Lifetimes And Other Limits

  • Payment confirmation is safe to replay. commerce_public_checkout_confirm returns replayed: true for an already-paid order and pending: true for one Stripe has not settled.
  • Fulfilment is idempotent. commerce_fulfil_order returns the existing delivery with replayed: true rather than creating a second one.
  • Order ids are derived from the cart id and the Stripe idempotency key is derived from the order id and total, so a duplicate pay attempt cannot produce a duplicate order document.
  • Inventory writes retry rather than merge. Up to 6 strict-save attempts, then a refusal, so a stale count can never merge forward into an oversell.
Lifetime or limit Value
Cart lifetime 30 days, extended on every add
Stock reservation 20 minutes, taken at the payment step only
Order numbering sequential per store, starting at 1000
Minimum order total 50 minor units
Allowed domains per store 25
Flat rates per store 25
Product media 20 images
Product tags 30
Option axes per product 3
Description / short description 20000 / 500 characters
Cart line quantity 1..999
Seller list caps products 500 max (default 200), orders 500 max (default 100), catalog 200 max (default 60), discounts 200
Stores-overview counting caps 2000 products and 5000 orders per account read, flagged products_capped and orders_capped

Webhooks

Commerce publishes no webhooks and consumes none.

  • Inbound: none. Payment confirmation is a pull from Stripe on the thank-you page, not a webhook push, which is why commerce_public_checkout_confirm reads the Checkout Session directly and is written to be replayed.
  • Outbound: none. There is no order.created, order.paid, order.fulfilled or cart.abandoned delivery, and the webhooks plan flag is not read anywhere.
  • Crons: one pass, every five minutes. The controller runs commerce_sweep_payments and then commerce_sweep_reservations on the primary box (config commerce_sweep, enabled and cron), so a stock hold lasts 20 to 25 minutes. An expired hold whose payment is still open at the rail, or whose order already records money, is kept until the payments sweep has asked the rail about it.

The Stripe subscription webhooks that maintain the consolidated subscription belong to the billing module, not to Commerce. The one place a Stripe webhook touches Commerce is a scheduled downgrade, which returns scheduled: true and leaves the current tier in place until that webhook moves it.

A Note On The Rest Of The Surface

Beyond the thirty-two methods above, Commerce reaches Stripe and Xuda Shipping through module-to-module helpers that are deliberately unregistered in the CPI method table: the connected checkout session create and read on the Stripe side, and quote, wallet, locations and delivery calls on the Shipping side. No HTTP route reaches them, they are not part of any documented or supported surface, and they are not listed here. The router additionally owns two server-rendered buyer pages, /store/thanks and /store/cancelled, which are pages rather than methods.

Xuda Commerce is live on the development environment and is not yet published to production. Nothing in this reference should be treated as production-available until the module ships.