Inspiration
What it does
How we built it
Inspiration
AI assistants can now book services for us. But for repairs, the real price is rarely known until someone opens the cabinet: a $60 plumber visit becomes $105 when the faucet cartridge is cracked. Agent checkouts today charge one fixed amount agreed at booking. When the price changes on site, the customer gets either a surprise charge or a messy second payment. I wanted to see whether PayPal's own payment tools could settle the real bill safely, inside limits the customer agreed to.
What it does
The customer's assistant books a visit through TrueUp's MCP server. TrueUp asks the customer how extra costs should be handled, then places a PayPal hold for the visit price. On site, the technician records a voice note and a photo, and an AI agent turns them into priced items from the business's price list. A plain-code decision engine then picks one of four outcomes:
- Cancelled: the hold is released and nothing is charged.
- Less than booked: only the real amount is charged; the rest of the hold is released.
- Within the limit: charged automatically on the original hold, up to PayPal's limit (115% of the hold, at most $75 more) and the customer's own rule.
- Past the limit: the owner approves first, then the customer approves an itemized PayPal order for the difference, with the photo as evidence.
Every job ends with a receipt showing the items, the reasons, the customer's rule fingerprint, the PayPal ids and a timeline.
How I built it
- PayPal: Orders v2 with intent=AUTHORIZE for the hold, captures on the authorization (partial, multiple, and over-capture up to the limit), void, reauthorize, an itemized intent=CAPTURE order for the extra amount, and verified webhooks. Every call sends a PayPal-Request-Id, with fixed keys per job so a retry can never charge twice. The rule's hash travels in custom_id.
- AI: LangChain 1.x agents. The bill agent uses structured output and price-list tools. Middleware does the safety work: a custom price guard sends the model back when it invents an item, a custom audit log records every call, and the built-in PII, retry, fallback-model and call-limit middleware keep customer details out and the agent reliable. The owner agent uses human-in-the-loop middleware with a SQLite checkpointer. A ledger agent answers the owner's questions with numbers computed in code.
- MCP: a FastMCP server with 10 tools, resources and a prompt. It uses elicitation for the customer's rule and their yes, optional sampling to explain a price change, and progress notifications while waiting for PayPal. It supports both the new and the previous protocol version, with fallbacks for clients that lack a feature.
- App: FastAPI pages for the technician, owner and receipt, a SQLite job store, deployed on Render. 122 automated tests run against a stateful fake of the PayPal endpoints.
Challenges I ran into
- A double charge in testing. The PayPal return page and the customer's assistant tried to finish the same payment at the same moment, and PayPal flagged a duplicate transaction. I added a cross-process claim in the database and fixed request ids per job, so only one finishes and the other reads the result.
- An AI touching amounts. An early owner agent passed the extra amount as a tool argument, and the model formatted it differently from the engine. I removed the amount argument entirely: the model writes words, code supplies the money.
- A changing protocol. The MCP spec changed how elicitation and sampling work this year, so the server supports both versions.
- Sandbox setup. My default sandbox accounts were in India and PayPal rejected USD payments; I moved to US sandbox accounts.
Accomplishments that I'm proud of
The full flow runs live: a real assistant books a visit, a technician reports, the owner approves, and the customer approves the extra at PayPal, all in the sandbox. Every money decision is deterministic code, and every PayPal behavior TrueUp relies on was verified in the sandbox first, including PayPal rejecting a capture past the limit.
What I learned
PayPal already has the pieces for variable-price services: authorizations, over-capture and multiple captures. What was missing was the layer that decides when each is allowed. I also learned to keep AI on the language side of the line: it reads notes and writes messages, and plain code decides what is charged.
What's next
OAuth for the MCP endpoint, Postgres instead of SQLite, vaulted payment methods for repeat customers, and PayPal Payouts for technician commissions.