The Idea Behind PayPilot
AI can already understand what we want, compare products, and make recommendations. But what happens when we allow it to actually spend money?
That question was the starting point of PayPilot.
I wanted to explore how conversational AI could be connected to real payment infrastructure without giving an AI model direct control over financial transactions. A system that simply connects an LLM to a payment API might work in a demo, but handling real payment workflows introduces much harder problems: incorrect recommendations, unauthorized purchases, duplicate transactions, network failures, and interrupted payment operations.
I built PayPilot, an AI-assisted payment orchestration platform that turns natural-language purchase requests into controlled PayPal transactions.
What PayPilot Does
A user can simply describe what they want to purchase in a conversation. PayPilot interprets the request using AI, discovers relevant products, compares recommendations, and evaluates the purchase against a deterministic spending policy.
Once the user explicitly approves the purchase, PayPilot handles the payment workflow through PayPal.
The platform supports two purchase flows:
- Catalog purchases: Product discovery, recommendation, policy evaluation, approval, and payment execution.
- External purchases: Third-party product discovery, AI-ranked comparison, server-controlled adoption, live product revalidation, and guarded purchase execution.
It also supports transaction tracking, payment capture, refunds, webhook verification, and interrupted transaction recovery.
The Engineering Behind It
One architectural decision shaped the entire project:
AI recommends. Policy authorizes. Humans approve. PayPal executes.
Instead of relying on prompts to prevent unsafe financial decisions, I implemented a deterministic policy engine with seven first-match rules. It operates independently of AI providers and network calls.
AI-generated outputs cannot directly authorize payments. Product prices and transaction amounts are resolved using server-side data, while strict Pydantic validation rejects unexpected fields.
I integrated three AI providers — Google Gemini, Groq, and Anthropic Claude — and connected the platform to PayPal REST APIs for order creation, payment capture, full refunds, OAuth authentication, and webhook signature verification.
The backend uses Python and FastAPI, with SQLite for persistent transaction management. The frontend is built using React, TypeScript, Vite, and Tailwind CSS.
The Hardest Part: Making Payments Recoverable
The most challenging part wasn't connecting PayPal. It was handling everything that could go wrong after a payment request had started.
For example, imagine the application creates a PayPal order successfully, but crashes before saving the response locally. Retrying the request carelessly could create a duplicate order.
To address this, I implemented:
- Durable reservations:Transaction records are committed before external payment calls.
- Idempotency: PayPal request identifiers allow safe retries without unintentionally creating duplicate orders.
- Multi-stage recovery: The system reconciles existing provider state before considering a replay or requiring manual review.
- Concurrency control:Atomic database updates prevent conflicting recovery operations.
- Ownership tokens:UUID-based recovery claim tokens ensure that a stale worker cannot release another worker's active recovery claim.
I also implemented desynchronization-aware error handling so the system does not incorrectly report a failed payment when PayPal may already have processed it.
The external purchase workflow introduced another challenge: product information can change between discovery and purchase. I addressed this through server-controlled adoption, exact external identifier matching, fresh evidence validation, and mandatory human approval.
Testing and Results
Testing became a major part of the development process because payment workflows cannot be treated like ordinary CRUD operations.
I built a comprehensive automated test suite covering policy evaluation, payment lifecycle transitions, recovery mechanisms, concurrency controls, authentication boundaries, webhook verification, and external product safety.
The final reported results were:
- 2,339 backend tests passing
- 182 frontend tests passing
- 2,521 total tests passing with zero failures
- More than 30 REST API endpoints
- Two complete purchase workflows
- Three integrated AI providers
PayPal Sandbox was also used to manually verify payment workflows. Automated payment-provider tests use mocked external calls, so these are reported separately.
What I Learned
Building PayPilot changed how I think about AI-powered applications. Connecting an AI model to an external API is relatively straightforward; designing the system around failures, retries, authorization, and consistency is where much of the real engineering work happens.
I learned a great deal about payment lifecycles, idempotency, database concurrency, distributed transaction recovery, API security, and the importance of deterministic boundaries around AI systems.
PayPilot is currently a technically substantive prototype, not a production-ready financial platform. It still needs improvements such as multi-user authentication, scalable database infrastructure, rate limiting, and monitoring.
But the central idea is something I am particularly proud of: AI can make financial workflows more convenient without being given unchecked control over money.