| 1 | # Agentic commerce x402 (local simulation) |
| 2 | |
| 3 | Local-only demonstration of an HTTP **402 Payment Required** → application |
| 4 | approval → synthetic payment proof → receipt / audit loop for ProcureNet / |
| 5 | Omnipay docs. |
| 6 | |
| 7 | > **Safety:** This example never moves real funds. There are no live payment |
| 8 | > gates, no AWS credentials, no Bedrock calls, and no wallet private keys. |
| 9 | > `value_transferred=false` always. Live AgentCore Payments is stubbed to |
| 10 | > `SKIPPED` / `NOT_READY`. |
| 11 | |
| 12 | Adapted from the OpenAI Cookbook example *Controlled agentic commerce with |
| 13 | AgentCore Payments*. See [SOURCE.md](./SOURCE.md) for attribution. |
| 14 | |
| 15 | ## Four responsibilities |
| 16 | |
| 17 | 1. **Agent** — proposes a paid resource fetch (scripted; no live model). |
| 18 | 2. **Application policy** — merchant allowlist, purpose, budgets, human approval. |
| 19 | 3. **Payment session (simulated)** — `LocalPaymentProcessor` mints synthetic proofs. |
| 20 | 4. **Paid API** — `SyntheticMerchant` serves a fictional supplier-risk report. |
| 21 | |
| 22 | ## Setup |
| 23 | |
| 24 | ```bash |
| 25 | cd examples/agentic-commerce-x402 |
| 26 | uv sync |
| 27 | uv run pytest |
| 28 | ``` |
| 29 | |
| 30 | Or with pip: |
| 31 | |
| 32 | ```bash |
| 33 | python -m venv .venv && source .venv/bin/activate |
| 34 | pip install -e ".[dev]" # or: pip install -e . && pip install pytest |
| 35 | pytest |
| 36 | ``` |
| 37 | |
| 38 | ## Quick demo |
| 39 | |
| 40 | ```python |
| 41 | from datetime import UTC, datetime, timedelta |
| 42 | from decimal import Decimal |
| 43 | |
| 44 | from omnipay_x402.demo import build_demo |
| 45 | from omnipay_x402.merchant import RESOURCE_URL |
| 46 | from omnipay_x402.models import ApprovalGrant, PurchaseRequest |
| 47 | |
| 48 | now = datetime.now(UTC) |
| 49 | app, merchant, payments = build_demo(now) |
| 50 | purchase = PurchaseRequest( |
| 51 | request_id="request-001", |
| 52 | resource_url=RESOURCE_URL, |
| 53 | purpose="supplier_due_diligence", |
| 54 | idempotency_key="purchase-001", |
| 55 | ) |
| 56 | grant = ApprovalGrant( |
| 57 | approval_id="approval-001", |
| 58 | request_id=purchase.request_id, |
| 59 | resource_url=purchase.resource_url, |
| 60 | purpose=purchase.purpose, |
| 61 | maximum_amount=Decimal("0.25"), |
| 62 | approved_by="synthetic-reviewer", |
| 63 | approved_at=now, |
| 64 | expires_at=now + timedelta(minutes=10), |
| 65 | ) |
| 66 | result = app.purchase(purchase, approval=grant, now=now) |
| 67 | print(result.status, result.receipt.receipt_id, payments.charge_count) |
| 68 | ``` |
| 69 | |
| 70 | ## Mapping to ProcureNet docs |
| 71 | |
| 72 | See the Mintlify guide: [`guides/agentic-commerce-x402.mdx`](../../guides/agentic-commerce-x402.mdx). |