Flow Design

Design a checkout that either ships and invoices an order or leaves a clear outcome for manual review.

Define the Checkout Contracts

Use shipment and invoicing as the preferred outcomes, with manual review as the fallback. Register these capabilities:

StepRequired inputsOutputs
load-orderorder_idamount, items, shipping_address, customer_email
charge-cardamountcharge_id
reserve-stockitemsreservation_id
ship-ordercharge_id, reservation_id, shipping_addresstracking_number
send-invoicecharge_id, amount, customer_emailinvoice_id
queue-for-revieworder_idreview_id

Shipment requires payment and reserved stock. Invoicing requires payment and can proceed independently of shipment.

Set ship-order and send-invoice as the Goals.

Start with the Order ID

Once those Steps are registered, start the Flow:

curl -X POST http://localhost:8080/engine/flows \
  -H "Content-Type: application/json" \
  -d '{
    "id": "checkout-123",
    "goals": {
      "steps": ["ship-order", "send-invoice"],
      "else": {"steps": ["queue-for-review"]}
    },
    "init": {"order_id": ["ord-123"]}
  }'

load-order runs once. Its amount feeds both payment and invoicing. Payment and reservation can run in parallel, and the two Goals become ready as their own required inputs are satisfied.

Only order_id is supplied initially. Supplying amount as well would freeze that Attribute at the supplied value instead of using the order service’s output. See Initial Values Are Authoritative.

Decide What Failure Means

If payment or reservation fails permanently, the Flow can move to queue-for-review, which needs only the initial order ID. Inspect the Goal Steps in the Flow state and the flow_completed event’s result to identify whether checkout completed or the order was queued for review. See Flow state.

For payment and stock reservations that can be reversed, configure compensated handling. When the primary Goal set becomes unreachable, Argyll rolls back succeeded reversible work that the fallback cannot use.

Keep optional enrichment out of the success contract. For example, a delivery note can be an optional input to ship-order, with a default and deadline. A missing reservation cannot: shipment depends on it and it belongs among the required inputs.