Skip to content

Order Processing Pipeline

intermediate
📜Corecommerce

Placing an order is not the end of the transaction. It is the beginning of a multi-step process that spans payment capture, fraud review, warehouse picking, shipping, delivery confirmation, and potentially returns. Treating order processing as a single step means losing visibility into where each order stands, which makes customer service reactive and fulfillment error-prone.

Optimizely Commerce models order processing as an event-driven pipeline with explicit states. Each order moves through a defined sequence, and each transition publishes events that downstream systems can consume. This gives operations teams real-time visibility and gives developers clean integration points for connecting external systems.

An order moves through a series of states from placement to completion. The built-in state machine covers the standard lifecycle.

StateMeaningTypical next states
In ProgressCart is still being built (pre-checkout)Completed
CompletedOrder has been placed and payment authorizedOn Hold, Awaiting Exchange
On HoldOrder paused for manual review (fraud, stock, etc.)Completed, Cancelled
Awaiting ExchangeProcessing a fulfillment or shipmentPartially Shipped, Shipped
Partially ShippedSome line items shipped, others pendingShipped
ShippedAll items shippedReturned
CancelledOrder cancelled before fulfillment— (terminal)
ReturnedAll items returned— (terminal)

Not every order follows the same path. A digital-only order might skip from Completed directly to Shipped. A partially available order might split into multiple shipments, moving through Partially Shipped before reaching Shipped.

Commerce separates orders from shipments. A single order can produce multiple shipments when items ship from different warehouses, have different delivery dates, or use different shipping methods.

Each shipment tracks:

  • Line items — Which variants and quantities are in this shipment
  • Warehouse — Which inventory location fulfills this shipment
  • Shipping method — The carrier and service level
  • Tracking information — Carrier tracking numbers and URLs
  • Shipment status — Its own state independent of the order state

This separation matters because an order is not “shipped” until all its shipments are shipped. The pipeline aggregates shipment states to determine the overall order state automatically.

Payment authorization happens at checkout, but capture — actually moving money from the customer to the merchant — happens at fulfillment. This is a deliberate design choice.

The capture flow:

  1. Checkout — Payment is authorized for the full order amount
  2. Shipment created — A shipment is prepared for a subset of line items
  3. Shipment dispatched — Payment is captured for the shipped amount
  4. Partial shipment — If only some items ship, only the corresponding amount is captured
  5. Remaining items — Captured when their shipment dispatches, or voided if cancelled

This per-shipment capture model prevents overcharging. If a customer orders three items and one is backordered, they are only charged for the two items that ship. The backordered item’s payment is captured when it ships or voided if cancelled.

Returns are modeled as a reverse flow through the pipeline. Commerce supports Return Merchandise Authorization (RMA) as a structured process.

The return workflow:

  1. RMA requested — Customer or service agent initiates a return for specific line items
  2. RMA approved — The return request is reviewed and approved (can be automatic based on rules)
  3. Items received — Warehouse confirms receipt of returned items
  4. Refund processed — Payment refund is issued to the original payment method
  5. Inventory updated — Returned items are added back to available stock (if in sellable condition)

Each step publishes events, enabling external systems to react. An ERP might update its accounting when a refund is processed. A customer service platform might close the support ticket when items are received.

A customer who ordered five items can return two. Commerce tracks returns at the line-item level, so partial returns do not affect the remaining fulfilled items. The refund amount corresponds only to the returned items, including any applicable restocking fees defined in your return policy.

The order processing pipeline publishes events at each state transition. This architecture provides three key benefits:

Loose coupling. External systems (ERP, warehouse, email, analytics) subscribe to events rather than being called directly. Adding a new integration does not require modifying the pipeline.

Auditability. Every state change is recorded with a timestamp and the triggering action. You can reconstruct the full history of any order from its event stream.

Extensibility. Custom event handlers can inject business logic at any transition point. When an order moves to “Completed,” a handler might trigger a fraud check. When a shipment is dispatched, a handler might send a shipping confirmation email.

EventTypical subscribers
Order completedFraud review service, ERP sync, confirmation email
Shipment dispatchedEmail notification, tracking page, analytics
Payment capturedERP accounting, revenue reporting
Return approvedWarehouse system, customer service platform
Refund processedERP accounting, customer notification

Commerce Customized lets you modify the state machine by adding custom states or changing transition rules. For example, a pharmaceutical company might add a “Compliance Review” state between Completed and Awaiting Exchange. A made-to-order manufacturer might add a “Production” state.

Custom states participate in the same event system. Your custom “Compliance Review” state publishes events that your compliance system subscribes to, and the pipeline only advances when the compliance system signals approval.