Inspiration
B2B purchasing for SMBs is still stuck in email threads, WhatsApp quotes and spreadsheets. Three things hurt: buyers don't know the true landed cost until after they've committed (duties, import VAT, freight, brokerage, payment fees), nobody can enforce a hard budget or per-item cap, and there's no clean audit trail of who authorized what. On top of that, delegating spending usually means sharing a card or account credentials — which is exactly how fraud happens. We asked a simple question: what if you could delegate money instead of credentials? That became Pay2Win B2B — an agentic procurement platform where a buyer signs a single QR mandate that grants a budget, a per-item cap and an objective to a supervisor agent, and money only moves after a human approves the PayPal order.
What it does
A buyer signs a QR mandate — an HS256-signed JWT that encodes the objective, total budget, per-item spending cap, currency, financing preference and which subagents are allowed to run. Scanning it hands that budget to a supervisor agent, which dispatches a team of specialized subagents one at a time:
- procurement — sources real products and stock (Channel3), enforces the per-item cap, adjusts quantity to available stock
- customs — HS classification, duties, import VAT, brokerage, permits
- logistics — carrier/mode, freight, ETA, multi-supplier consolidation
- compliance — sanctions screening, restricted origins, export-permit flags, risk score (can block the whole run)
- treasury — consolidates the full landed cost, enforces the budget guardrail, builds the payment schedule
- payments — creates the PayPal order and returns the approval URL Then the workflow interrupts for human approval. The buyer approves inside PayPal — the platform never sees their credentials — and only after PayPal reports the order APPROVED/COMPLETED does the backend capture it and verify the final state. Every delegation, subagent decision, PayPal event and webhook is persisted to a ledger and surfaced in a live React + AG Grid dashboard.
How we built it
Orchestration: LangGraph StateGraph with a supervisor router, a first-class human-approval interrupt, and a checkpointer (Postgres in production, SQLite locally) so a run survives restarts by thread_id.
- Intent extraction: LangChain + Groq (ChatGroq with structured output) turns free-text into a mandate (objective, items, quantities, budget, per-item cap, financing), with a regex heuristic fallback when no key is configured.
- Sourcing: Channel3 live product search, normalized into offers and augmented with B2B trade attributes (HS code, duty rate, weight, origin), with a deterministic local wholesale catalog as an offline fallback.
- Payments: the PayPal Agent Toolkit creates the checkout order through the existing ReAct agent, and a deterministic PayPal REST client handles token caching, order status and capture (POST /v2/checkout/orders/{id}/capture + status verification).
- Backend: FastAPI + Uvicorn, with endpoints for QR creation, chat-to-mandate, run, approve, orders, PayPal webhooks and live order status.
- Persistence: a ledger layer over Postgres/SQLite that stores every delegation, its subagent trace, PayPal events and aggregates.
- Frontend: React + Vite + AG Grid (community) with custom SVG analytics, polling /api/b2b/orders so agent progress and payment state update in place.
- Deploy: a two-service Render blueprint with health checks. We also built a simulated payment mode: if PayPal credentials are missing or a real order fails, the flow generates a sandbox-looking order id and approval link so the entire mandate → approval → capture narrative still demos offline.
Challenges we ran into
Making human-in-the-loop survive restarts. The approval is an interrupt, not a blocking sleep — getting the checkpointer to resume the exact run from a thread_id after a server restart took real care. Truthful landed cost. Combining goods, duties, VAT, freight, brokerage and the payment fee into one number that treasury can compare against the budget, while keeping the financing schedule informational rather than multiple captures. Trust boundaries in payments. We had to enforce that capture only happens when PayPal actually reports APPROVED or COMPLETED (returning HTTP 409 otherwise), instead of trusting our own state. Parsing the Agent Toolkit output. Extracting a reliable 17-character order id and approval link from an LLM-driven ReAct agent meant regex validation plus a graceful fallback when the output didn't match. Demo reliability. Live sourcing and live payments can fail; we built deterministic fallbacks (local catalog, simulated orders) so the story never breaks on stage. Webhook correctness. Verifying the PayPal transmission signature and still keeping local demos working when PAYPAL_WEBHOOK_ID isn't configured.
Accomplishments that we're proud of
A full end-to-end agentic procurement run — QR mandate → sourcing → customs → logistics → compliance → treasury → PayPal order → human approval → capture — with no real money moved in sandbox. Hard guardrails enforced by agents, not trust: platform delegation limit ($250k), mandate TTL, per-item cap, budget check in treasury, and compliance able to block the entire delegation. Landed cost before payment, so the buyer sees the real total before anything is created. A complete audit trail — every subagent decision, PayPal operation and webhook event is persisted and visible in the dashboard. A polished live console with AG Grid tables, KPI cards, revenue/traffic analytics and a per-subagent activity feed. Graceful degradation everywhere: missing PayPal, Groq or Channel3 keys never break the flow.
What we learned
Agents need guardrails, not just prompts. The most valuable part of the system is the deterministic enforcement layer around the LLM — caps, budget checks and payment state verification. LangGraph interrupts are the right primitive for human approval in money flows; keeping approval as first-class state made the whole design simpler and safer. The trust boundary belongs in PayPal. Letting the buyer approve inside PayPal and only capturing what was authorized is a much stronger model than storing credentials. Fallbacks are a feature. Deterministic offline data and simulated payments turned a fragile demo into a reliable one. Landed cost is the real product insight — SMBs care less about the sticker price and more about the total that actually hits the budget.
What's next for pay2win b2b
Go live on PayPal production — real credentials, production webhooks and proper reconciliation. Multi-tenant organizations with roles, approval policies and team-level budgets. Real supplier integrations beyond Channel3 — direct feeds, negotiated pricing and contract catalogs. Deeper compliance — live sanctions/PEP lists, KYC and permit workflows instead of heuristics. Smarter financing — actual PayPal Pay Later / installment products tied to the treasury schedule. Learning from history — use past delegations to recommend suppliers, consolidate orders and predict landed cost more accurately. Embeddable "buy with agents" API for marketplaces and fintechs that want delegated, policy-controlled B2B spending without rebuilding sourcing, compliance and payments.
Built With
- ag-grid
- channel3
- fastapi
- groq
- langchain
- langgraph
- paypal-agent-toolkit
- paypal-rest-api
- paypal-webhooks
- postgresql
- psycopg
- pyjwt
- python
- qrcode
- react
- sqlite
- svg
- uvicorn
- vite