Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Plug Your APIs and Deploy

This guide walks from zero to a running Commerce Orchestrator calling your six downstream APIs, with local smoke tests and deployment validation.

Prerequisites

  • Rust toolchain (for local run and tests).
  • Docker (for container build).
  • Kubernetes cluster or Docker Compose for deployment (or run the server locally and point it at stub/mock URLs for development).
  • An operating-system CA trust store on the host or image. Outbound HTTPS (providers, OAuth token endpoints, Web Bot Auth key directories) is verified against the platform’s trust store, not a bundled root list. The provided image installs ca-certificates. If you build a custom image, install it too, or add your private CA there.

1. Downstream API Contracts

The orchestrator calls your services over HTTP. Each base URL must not have a trailing slash. Implement the following endpoints so the integration adapters can call them.

The machine-readable version of this section is the OpenAPI 3.1 spec providers/openapi.yaml. Generate server stubs from it, or load it into your API tooling. A test in the integration-adapters crate checks it against the adapters on every CI run, so it does not drift from what the orchestrator actually sends.

Catalog

MethodPathRequestResponse (200)
GET{base}/items/{item_id}—{ "id": "<string>", "title": "<string>", "price_minor": <integer> }
POST{base}/catalog/lookup{ "ids": ["<string>"] }{ "products": [ { "id", "title", "price_minor" } ] }
POST{base}/catalog/search{ "query": "<string>"? }{ "products": [ { "id", "title", "price_minor" } ] }
  • 404 or non-2xx: item not found or error.

Pricing

MethodPathRequest (JSON body)Response (200)
POST{base}/prices/resolveCart projection (see adapter){ "prices": [ { "line_id": "<string>", "unit_price_minor": <int>, "total_minor": <int> } ] }
POST{base}/discounts/resolve{ "cart": <cart projection>, "codes": ["<string>"] }{ "discounts": [ { "code": "<string>", "description": "<string>"?, "amount_minor": <int>, "line_id": "<string>"? } ] }
  • Request body is the orchestrator’s cart projection; your service returns one price entry per line.
  • discounts/resolve prices the buyer’s adjustment codes. Return only the codes you grant; a non-2xx rejects the codes (use it for expired or ineligible campaigns), and amount_minor is positive and is clamped to the amount owed. It is only called when the cart carries at least one code.

Tax

MethodPathRequest (JSON body)Response (200)
POST{base}/tax/resolveCart projection{ "total_tax_minor": <integer> }

Geo

MethodPathRequest (JSON body)Response (200)
POST{base}/geo/check{ "cart": <CartProjection>, "request": <CheckoutRequest> }{ "allowed": <boolean> }
  • Return allowed: true if the cart/request is allowed in the given geography; otherwise false.

Payment

MethodPathRequest (JSON body)Response (200)
POST{base}/authorizeCheckout request{ "authorized": <boolean>, "reference": "<string>" }
POST{base}/capturePayment lifecycle request{ "success": <boolean>, "reference": "<string>" }
POST{base}/voidPayment lifecycle request{ "success": <boolean>, "reference": "<string>" }
POST{base}/refundPayment lifecycle request{ "success": <boolean>, "reference": "<string>" }
GET{base}/state/{transaction_id}—Optional: `{ “state”: “<authorized
  • For reconciliation, implement GET .../state/{transaction_id}; if you don’t, the orchestrator treats provider state as unknown.

3DS2 step-up (optional). Set PAYMENT_AUTHENTICATION_ENABLED=true only if your payment service implements these:

MethodPathRequest (JSON body)Response (200)
POST{base}/authorizeCheckout requestAdd "authentication_required": { "authentication_id", "device_data_collection_url"?, "challenge_url"?, "acquirer_details"?, "directory_server"? } with "authorized": false when the issuer wants 3DS2 first
GET{base}/authentication/{authentication_id}—{ "status": "pending" } or { "status": "completed", "result": { "outcome", "electronic_commerce_indicator"?, "three_ds_cryptogram"?, "transaction_id"?, "version"? } }
POST{base}/authentication/{authentication_id}/authorize{ "checkout": <CheckoutRequest>, "result": <AuthenticationResult> }, Idempotency-Key: <checkout key>:authenticated{ "authorized": <boolean>, "reference": "<string>" }
  • The URLs are pages you host that run the 3DS Method and the challenge in the buyer’s browser; EMV 3DS messages never pass through the orchestrator.
  • acquirer_details (acquirer_bin, acquirer_country, acquirer_merchant_id, merchant_name) and directory_server (visa, mastercard, american_express) are what ACP agents need for delegate authentication; without both, ACP sessions show no authentication_metadata.
  • outcome uses ACP’s values (authenticated, attempt_acknowledged, denied, rejected, abandoned, …). The orchestrator only calls /authorize on the authentication for authenticated and attempt_acknowledged.
  • Without the flag, an authentication_required answer is treated as a decline and 3DS2 is not advertised.

Receipt

MethodPathRequest (JSON body)Response (200)
POST{base}/receipts/generate{ "cart": <CartProjection>, "result": <TransactionResult> }{ "content": "<string>" }
  • content is the receipt text or payload your system returns (e.g. PDF URL or plain text).

Fulfillment (optional)

MethodPathRequest (JSON body)Response (200)
POST{base}/fulfillment/quote{ "cart": <CartProjection>, "method_type": "shipping"|"pickup", "destination": <destination>, "line_item_ids": ["<string>"] }{ "options": [ { "id", "title", "description"?, "carrier"?, "earliest_fulfillment_time"?, "latest_fulfillment_time"?, "amount_minor" } ] }
  • Without FULFILLMENT_BASE_URL, the orchestrator quotes its built-in standard, express and pickup options.

Payment delegation (optional)

MethodPathRequest (JSON body)Response (200)
POST{base}/delegate_payment{ "tenant_id": "<string>", "token": "<caller token>", "method_type": "<string>?", "max_amount_minor": <int>?, "metadata": { } }{ "id": "<string>", "token": "<delegated token>", "status": "delegated", "expires_at": "<rfc3339>?" }
  • The returned token must be a new, scoped credential — returning the caller’s own token grants nothing and is not delegation.
  • The orchestrator forwards Idempotency-Key so a retry cannot mint two tokens.
  • Without PAYMENT_DELEGATION_BASE_URL, POST /api/v1/acp/delegate_payment returns 501 NOT_CONFIGURED and the ACP discovery document omits the delegate_payment service.

Identity linking (optional)

MethodPathRequest (JSON body)Response (200)
POST{base}/identity/link{ "tenant_id": "<string>", "merchant_id": "<string>", "agent_id": "<string>", "link_token": "<string>" }{ "link_id": "<string>", "status": "linked", "expires_at": "<rfc3339>?" }
  • Without IDENTITY_LINK_BASE_URL, POST /api/v1/a2a/identity/link returns 501 NOT_CONFIGURED and dev.ucp.common.identity_linking is absent from discovery.
  • Without EMBEDDED_CHECKOUT_URL (or without signing keys), POST /api/v1/ucp/checkout/:id/embedded-link returns 501 NOT_CONFIGURED and the embedded transport is absent from discovery.

For exact request shapes, see the integration adapter types in the repo (integration-adapters crate) and the wiremock tests under crates/integration-adapters/tests/ (e.g. catalog_http_test.rs, adapters_http_test.rs).

2. Environment Variables

Configure the server with these (see also Consumption guide – Config reference and deploy/README.md).

VariableRequired (production)DescriptionExample
ENVYesproduction enables auth and real adapters.production
PUBLIC_BASE_URLYesPublic base URL advertised in /.well-known/ucp; required in production to avoid localhost discovery output.https://orchestrator.example.com
DATABASE_URLYesPostgreSQL connection string for durable runtime state.postgres://orchestrator:secret@postgres:5432/orchestrator
AUTH_MODEYesstatic or jwt.static
AUTH_BEARER_TOKENYes (when AUTH_MODE=static)Secret token; clients send Authorization: Bearer <token>.(secret)
AUTH_JWT_HS256_SECRETYes (when AUTH_MODE=jwt)HS256 secret used to verify JWT tokens.(secret)
CATALOG_BASE_URLYesCatalog service base URL, no trailing slash.http://catalog-service:8080
PRICING_BASE_URLYesPricing service base URL.http://pricing-service:8080
TAX_BASE_URLYesTax service base URL.http://tax-service:8080
GEO_BASE_URLYesGeo service base URL.http://geo-service:8080
PAYMENT_BASE_URLYesPayment service base URL.http://payment-service:8080
RECEIPT_BASE_URLYesReceipt service base URL.http://receipt-service:8080
UCP_SIGNING_KEY_IDYesKey id advertised in discovery and sent as keyid in Signature-Input.orch-2026-a
UCP_SIGNING_KEYYesBase64 32 bytes for the active signing key: an Ed25519 seed, or a P-256 private scalar with UCP_SIGNING_KEY_ALG=ES256. Production refuses to start without it.(secret)
UCP_SIGNING_KEY_ALGNoEdDSA (default) or ES256. ES256 is the algorithm every UCP verifier must support.ES256
UCP_SIGNING_PREVIOUS_KEYSNoRetired keys still published for verification during rotation, kid:seed or kid:ES256:secret, comma-separated.orch-2025-b:<seed>
UCP_AGENT_JWKSNoAgent public keys as a JWK Set JSON ({"keys":[...]}, Ed25519 or P-256), as agents publish them in their UCP profile. Setting this or UCP_AGENT_KEYS makes inbound RFC 9421 signatures mandatory on /api/v1.{"keys":[{"kid":"agent-1","kty":"EC",...}]}
UCP_AGENT_KEYSNoEd25519 agent public keys, kid:base64-public-key comma-separated.agent-1:<public key>
PAYMENT_DELEGATION_BASE_URLNoPSP delegation service. Without it POST /api/v1/acp/delegate_payment returns 501 and the ACP delegate_payment service is not advertised.http://psp-delegation:8080
PAYMENT_AUTHENTICATION_ENABLEDNotrue when the payment service implements 3DS2 step-up (authentication_required and the /authentication endpoints). Off by default: UCP dev.ucp.common.payment.authentication and the ACP 3ds intervention are not advertised, and a step-up answer is a decline.true
IDENTITY_LINK_BASE_URLNoIdentity system for agent identity linking. Without it identity linking returns 501 and dev.ucp.common.identity_linking is not advertised.http://identity:8080
EMBEDDED_CHECKOUT_URLNoYour hosted embedded checkout page. Handoff links point here with session, expires, kid and token query parameters; verify token as an Ed25519 signature over ucp-embedded-checkout:{session}:{expires} using the JWK named by kid in /.well-known/ucp. Requires signing keys.https://shop.example.com/checkout/embedded
MPP_CHALLENGE_SECRETNoHMAC key that binds MPP Payment challenges. Set, MPP checkouts must answer a 402 challenge and get a Payment-Receipt. Unset, they are not challenged. Keep it in the Secret, and use the same value on every replica.32+ random bytes
MPP_REALMNoRealm named in MPP challenges. Defaults to the host of PUBLIC_BASE_URL; startup fails if neither is set while MPP_CHALLENGE_SECRET is.shop.example.com
MPP_CHALLENGE_TTL_SECSNoHow long an MPP challenge stays answerable, 1–3600. Default 300.300
UCP_PAYMENT_HANDLERSNoYour payment providers’ UCP handlers, published as ucp.payment_handlers: JSON object keyed by reverse-DNS handler name, each an array of entries with id and a YYYY-MM-DD version (plus spec, schema, available_instruments, config as the handler defines). Validated at startup; unset publishes {}.{"com.example.tokenizer":[{"id":"tok","version":"2026-08-25",...}]}
UCP_DEFAULT_MERCHANT_IDNoThe default merchant for every protocol whose payloads carry none: UCP carts and checkouts without a merchant_id, and ACP checkout sessions and carts (REST and MCP; over MCP meta.merchant_id wins). A request value wins. Unset, such requests get MERCHANT_REQUIRED.shop-main
UCP_CATALOG_CURRENCYNoISO 4217 currency for UCP catalog prices on the MCP binding when the request has no context.currency (which wins), and for ACP carts (ACP lets the seller pick it). Validated at startup. Unset, such requests get a currency_required error.USD
UCP_PROFILE_NEGOTIATIONNoUCP platform profile negotiation on /api/v1/ucp/* and /api/v1/ucp/mcp: off (default, nothing fetched), lenient (fetch and negotiate, never refuse) or strict (refuse as UCP requires: invalid_profile_url, profile_unreachable, profile_malformed, version_unsupported, capabilities_incompatible). Needs egress on 443 to platforms’ profile hosts. See negotiation.lenient
MCP_ALLOWED_ORIGINSNoBrowser origins allowed to call the MCP endpoints (scheme://host[:port], comma-separated), or *. Validated at startup. Unset, a request carrying an Origin header is refused with 403 (DNS-rebinding protection); agents calling from servers send no Origin and are unaffected.http://localhost:6274
FULFILLMENT_BASE_URLNoShipping rate service. Without it the built-in static rate table is used.http://fulfillment:8080
MIGRATE_ONLYNotrue applies pending migrations and exits, same as passing --migrate. Used by the migration Job.true
BIND_ADDRNoListen address.0.0.0.0:8080
RUST_LOGNoLog level.info
OUTBOX_INTERVAL_MSNoOutbox processor poll interval.1000
OUTBOX_BATCH_SIZENoMessages dequeued per poll.50
OUTBOX_MAX_ATTEMPTSNoAttempts before a message is dead-lettered.8
OUTBOX_DRAIN_TIMEOUT_SECSNoShutdown drain budget; keep below the pod’s termination grace period.30
OUTBOX_RETRY_BACKOFF_MSNoPause after a failed delivery, doubled per attempt.500
OUTBOX_MAX_RETRY_BACKOFF_SECSNoCeiling for that pause.30
PROVIDER_CIRCUIT_PROBE_TIMEOUT_SECSNoHow long a half-open probe may stay in flight before another is admitted.60
AUTH_TENANT_IDNoDefault tenant for auth context.prod
AUTH_CALLER_IDNoDefault caller id.prod
AP2_TRUSTED_ISSUERSNoComma-separated allowlist for strict AP2 issuer checks.issuer.example

Example .env for local runs (replace with your stub or real URLs):

ENV=production
PUBLIC_BASE_URL=https://orchestrator.example.com
DATABASE_URL=postgres://orchestrator:secret@localhost:5432/orchestrator
AUTH_MODE=static
AUTH_BEARER_TOKEN=dev-token-change-in-prod
CATALOG_BASE_URL=http://localhost:9001
PRICING_BASE_URL=http://localhost:9002
TAX_BASE_URL=http://localhost:9003
GEO_BASE_URL=http://localhost:9004
PAYMENT_BASE_URL=http://localhost:9005
RECEIPT_BASE_URL=http://localhost:9006
UCP_SIGNING_KEY_ID=orch-2026-a
UCP_SIGNING_KEY=$(openssl rand -base64 32)

3. Local Smoke Test (no deployment)

Without ENV=production the orchestrator runs in development mode: it uses built-in mock providers with a demo catalog (demo-tee, demo-mug, demo-cap), accepts unauthenticated calls as tenant dev, and ignores the *_BASE_URL settings. That is enough to try the API (see the README quick start). To smoke-test against your providers, run with ENV=production and the full production configuration from step 2.

  1. Start your six downstream services (or stubs) so they listen on the URLs you set in step 2.
  2. Start local Postgres (or point to an existing instance):
    docker compose up -d postgres
    
  3. Start the orchestrator:
    cargo run -p orchestrator-http --bin orchestrator-server
    
  4. Health:
    curl -s http://localhost:8080/health/live
    curl -s http://localhost:8080/health/ready
    
  5. Create cart and run checkout (use your tenant/merchant IDs and payment token as needed):
    # Create cart
    curl -s -X POST http://localhost:8080/api/v1/cart/commands \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer dev-token-change-in-prod" \
      -d '{"command":{"kind":"create_cart","merchant_id":"m1","currency":"USD"},"cart_id":null}'
    
    # Add item (use cart_id and line IDs from create_cart response)
    # Then start_checkout, then POST /api/v1/checkout/execute with cart_id, cart_version, payment_intent, idempotency_key, etc.
    
    See Consumption guide for full request/response shapes.
  6. Payment lifecycle (after a successful checkout):
    curl -s -X POST http://localhost:8080/api/v1/payments/capture \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer dev-token-change-in-prod" \
      -d '{"tenant_id":"t1","merchant_id":"m1","transaction_id":"<tx_id>","amount_minor":1000,"idempotency_key":"cap-1"}'
    
  7. Ops: Hit POST /api/v1/ops/outbox/process, GET /api/v1/ops/dead-letter, POST /api/v1/ops/reconciliation as needed (see runbooks).

4. Staging Deployment (Kubernetes)

  1. Get the image. Each release tag publishes a multi-arch (linux/amd64, linux/arm64) image to GitHub Container Registry, with an SBOM and build provenance attached. The manifests already reference it:
    docker pull ghcr.io/ancientice/commerce-orchestrator-api:0.13.0
    
    To run your own build instead, build from the repo root, push it to your registry, and override the image in step 5:
    docker build -t <your-registry>/commerce-orchestrator-api:<tag> .
    docker push <your-registry>/commerce-orchestrator-api:<tag>
    
    With Helm, install the chart in deploy/helm/commerce-orchestrator instead of steps 2 to 5; see deployment.
  2. Edit manifests under deploy/kubernetes/:
    • configmap.yaml: Set all six *_BASE_URL to your staging service URLs, plus any optional providers you run (FULFILLMENT_BASE_URL, PAYMENT_DELEGATION_BASE_URL, IDENTITY_LINK_BASE_URL).
    • secret.yaml or create the secret manually: Set DATABASE_URL, auth variables based on AUTH_MODE (AUTH_BEARER_TOKEN or AUTH_JWT_HS256_SECRET), the signing key pair (UCP_SIGNING_KEY_ID, UCP_SIGNING_KEY), and optional AUTH_TENANT_ID, AUTH_CALLER_ID.
  3. Migrate before the new image serves traffic:
    kubectl apply -f deploy/kubernetes/job-migrate.yaml
    kubectl wait --for=condition=complete job/orchestrator-api-migrate --timeout=5m
    
    The Job runs the server image with --migrate, which applies pending migrations and exits. Replicas also migrate on startup under a PostgreSQL advisory lock, so a missed Job is recoverable — but a broken migration then fails once here instead of crash-looping every pod.
  4. Apply (ensure namespace exists):
    kubectl apply -f deploy/kubernetes/
    
  5. Override image to pin a different tag or run your own build:
    kubectl set image deployment/orchestrator-api orchestrator-server=ghcr.io/ancientice/commerce-orchestrator-api:0.13.0
    
  6. Ensure database reachability from the orchestrator pod (network policy, DNS, credentials, and TLS as required by your platform). The shipped NetworkPolicy allows egress to TCP 5432.
  7. Scale safely: the manifests ship two replicas. All durable state is in PostgreSQL, outbox dequeue uses FOR UPDATE SKIP LOCKED, and idempotency keys are stored centrally, so replicas neither double-deliver nor double-charge. Tune the connection pool and database capacity as you scale.
  8. Wire up monitoring: apply servicemonitor.yaml (Prometheus Operator) and import deploy/grafana/orchestrator-dashboard.json. See deployment.

5. Post-Deploy Validation Checklist

Run these after deployment to confirm the system is ready for traffic:

  • Liveness: GET /health/live returns 200.
  • Readiness: GET /health/ready returns 200.
  • Auth: Request without Authorization: Bearer <token> to a protected endpoint returns 401.
  • Cart: Create cart, add item, get cart; responses successful and cart projection looks correct.
  • Checkout: Execute checkout with valid cart and payment intent; response includes transaction_id and success status.
  • Payment lifecycle: Capture (and optionally void/refund) using transaction_id from checkout; responses indicate success.
  • Events: POST /api/v1/events/incoming with a message_id returns 200 (idempotent).
  • Outbox: POST /api/v1/ops/outbox/process with body e.g. {"max_attempts":3} returns 200.
  • Dead-letter: GET /api/v1/ops/dead-letter returns 200 (list may be empty).
  • Reconciliation: POST /api/v1/ops/reconciliation with body {"transaction_ids":["<tx_id>"]} returns 200; check response for mismatches if your payment provider supports state.
  • Metrics: GET /metrics returns Prometheus text and the Grafana dashboard populates.
  • Discovery honesty: GET /.well-known/ucp advertises a signing key you control, and lists dev.ucp.common.identity_linking only if you configured IDENTITY_LINK_BASE_URL.

If any step fails, check server logs, downstream connectivity, and runbooks (e.g. dead-letter handling, reconciliation).

Next Steps