๐Ÿ’ก Inspiration

Small-to-medium enterprises (SMEs), hardware startups, and distributed engineering teams lose hundreds of operational hours every quarter to fragmented micro-procurement ($500 โ€“ $10,000 requisitions).

When an operations manager needs to outfit 5 remote engineers or set up an office studio, they face three expensive bottlenecks:

  1. Manual Multi-Vendor Sourcing: Comparing unit prices, USB-C power-delivery specs, and commercial warranties across dozens of fragmented tabs.
  2. Spreadsheet-to-Invoice Drift: Approved spreadsheet quantities rarely sync cleanly with payment links, leading to budget overruns and manual CFO approvals.
  3. Upfront B2B Payment Risk: Buyers paying invoices upfront absorb fulfillment risk, while suppliers struggle with delayed net-30 settlements.

We built PayEscrow AI to turn B2B procurement from a fragmented, risky manual chore into a single autonomous, budget-guarded, and carrier-verified PayPal escrow workflow.


๐Ÿš€ What It Does

PayEscrow AI is an autonomous B2B micro-procurement and milestone-escrow command center that bridges product discovery, spreadsheet-grade financial controls, and programmable PayPal payments:

  • 1. Autonomous Requisition Decomposition (AI SDK + Gemini 2.5 Flash): Buyers enter a natural language hardware specification and a hard USD policy budget cap (e.g., "Outfit 5 remote software engineers with 27-inch 4K USB-C monitors and ergonomic mesh chairs under $3,500"). The AI agent decomposes the prompt into structured category queries, target fleet quantities, and unit-price ceilings.
  • 2. Live Commercial Discovery (Channel3 Product Graph API): The agent queries the Channel3 Semantic Search API (/v1/search) across each required category, retrieving verified commercial SKUs, merchant metadata, unit prices, and product links, and computes an AI Fit Score (0โ€“100) based on unit economics.
  • 3. Interactive B2B Evaluation Matrix (AG Grid v33): Instead of trapping financial data inside a text chat bubble, PayEscrow AI populates an interactive AG Grid workspace. Operations teams can double-click quantities to edit inline, toggle line items, filter suppliers, export one-click CSV compliance reports, and watch the Pinned Bottom CFO Summary Row recalculate budget variance in real time.
  • 4. Schema-Guarded PayPal Sandbox Escrow (@paypal/agent-toolkit & Orders v2): Clicking Approve & Create PayPal Escrow Order validates the payload against APIMatic's PayPal Orders v2 specification and dispatches an itemized checkout creation call (/v2/checkout/orders). It immediately returns a verifiable PayPal Sandbox Order ID and a live PayPal Sandbox Checkout URL.
  • 5. Carrier-Verified Escrow Release (PayPal Shipping Trackers v1): Funds remain held in milestone escrow until fulfillment is verified. Triggering carrier verification invokes PayPal's /v1/shipping/trackers-batch endpoint, attaches a verified UPS Tracking Number (DELIVERED), releases the escrow lock, and logs the transaction to our Supabase PostgreSQL audit ledger.

๐Ÿงฎ Quantitative Budget Guardrail & Utility Scoring Model

To ensure the autonomous agent strictly respects CFO policy ceilings, PayEscrow AI enforces a hard allocation constraint across $N$ candidate line items:

$$\text{Total Allocated Spend} = \sum_{i=1}^{N} x_i \cdot (p_i \cdot q_i) \le B_{\text{cap}}, \quad x_i \in {0, 1}$$

where $p_i$ is the verified Channel3 unit price, $q_i$ is the editable AG Grid fleet quantity, $x_i$ is the binary inclusion state, and $B_{\text{cap}}$ is the policy budget guardrail. Each candidate SKU is ranked by a composite utility function:

$$U_i = w_1 \left(1 - \frac{p_i}{P_{\max}}\right) + w_2 \cdot S_{\text{merchant}} + w_3 \cdot S_{\text{spec}}$$


๐Ÿ› ๏ธ How We Built It (Tools, AI Models & Sponsor Integrations)

  • PayPal Agent Toolkit (@paypal/agent-toolkit) & PayPal Sandbox REST APIs: Central to our execution engine (src/lib/paypal.ts). We integrated @paypal/agent-toolkit alongside direct OAuth2 calls to PayPal Orders v2 (/v2/checkout/orders) for itemized B2B bundle creation and PayPal Shipping Trackers v1 (/v1/shipping/trackers-batch) for automated delivery verification and escrow settlement.
  • AI Model & Structured Reasoning (ai SDK + @ai-sdk/google Gemini 2.5 Flash): Implemented in src/lib/ai-agent.ts using generateObject and Zod schemas to translate unstructured B2B procurement requests into deterministic hardware search vectors and CFO risk summaries (paired with an instant deterministic fallback so local evaluators can run the app even without an external LLM key).
  • AG Grid (ag-grid-react v33 + AllCommunityModule): Built inside src/components/ProcurementGrid.tsx using the dark Quartz theme (themeQuartz). We implemented custom cell renderers for SKU thumbnails, external supplier verification links, and AI Fit Score badges; inline numeric cell editing (agNumberCellEditor) with live state callbacks; quick-filter search; one-click CSV audit exports (exportDataAsCsv); and a pinned bottom summary row (pinnedBottomRowData) that flags budget compliance in real time.
  • Channel3 Product Graph (https://api.trychannel3.com/v1/search): Integrated in src/lib/channel3.ts to query real-time commercial hardware listings, brand metadata, pricing, and images, backed by a resilient B2B catalog cache so rate limits never interrupt evaluation.
  • APIMatic Context Plugin & OpenAPI Validation (.mcp.json + src/lib/apimatic.ts): Configured @apimatic/paypal-context-mcp during development and built a strict pre-flight Zod validator enforcing ISO-4217 currency formatting, 127-character PayPal SKU limits, and exact item_total breakdowns before any PayPal API call is fired.
  • Next.js 15 (App Router, TypeScript), Tailwind CSS & Supabase PostgreSQL: Full-stack architecture with real-time state persistence in Supabase (requisitions, procurement_items, agent_logs) and automatic Local Session Mode fallback.

๐Ÿงฉ Challenges We Ran Into

  1. Preventing PayPal Orders v2 AMOUNT_MISMATCH Errors on Live Edits: When users edited quantities inline inside AG Grid, floating-point rounding across multiple line items could cause a 1-cent discrepancy between amount.value and breakdown.item_total.value in PayPal Orders v2. We solved this by building our APIMatic Pre-Flight Validator (src/lib/apimatic.ts) to normalize unit prices to two decimal places and deterministically compute the exact item breakdown prior to calling PayPal.
  2. Synchronizing AG Grid Pinned Totals with React State: In AG Grid v33, editing a cell via agNumberCellEditor mutates row data locally. We wired onCellValueChanged directly into a reactive useMemo pipeline that instantaneously recalculates both the pinned bottom CFO summary row and the top-level Net Savings KPI card.
  3. Zero-Friction Local Reproducibility for Judges: We wanted judges to be able to clone and run the repo locally in under 60 seconds without hitting crashes if optional keys (like Supabase) were omitted. We engineered graceful fallbacks across every service layer so npm run dev boots cleanly every time.

๐Ÿ† Accomplishments That We're Proud Of

  • Real End-to-End Financial State Changes: Moving beyond chat wrappersโ€”every click in PayEscrow AI produces a real, verifiable PayPal Sandbox Order ID (#...) that opens directly on sandbox.paypal.com with the exact itemized SKUs from AG Grid.
  • Enterprise-Grade UX: Combining natural language AI sourcing with the tactile precision of an editable AG Grid spreadsheet and a live Tool-Call Telemetry Console.
  • Carrier-Linked Escrow Automation: Demonstrating how PayPal's Shipping Trackers API can serve as a programmable oracle for B2B escrow release.

๐Ÿ“š What We Learned

  • How to combine PayPal's Agent Toolkit and Orders v2 / Shipping Trackers v1 endpoints to build multi-step B2B payment state machines.
  • How APIMatic's OpenAPI specification guardrails eliminate runtime API rejections when bridging probabilistic LLM outputs with strict financial endpoints.
  • How AG Grid v33's modular architecture (ModuleRegistry) and pinned summary rows can transform AI outputs into an auditable financial workspace.

๐Ÿ”ฎ What's Next for PayEscrow AI

  • Multi-Party Split Payouts: Integrating the PayPal Payouts API to automatically split settled escrow funds across multiple underlying wholesale merchants simultaneously upon delivery verification.
  • Automated Dispute Mediation: Using the PayPal Disputes API to let the AI agent automatically submit carrier proof-of-delivery logs when a shipment discrepancy arises.
  • ERP & Accounting Webhooks: Direct two-way sync with QuickBooks, NetSuite, and Slack approval channels.

Built With

Share this project:

Updates

Submission history