-
-
Memo-to-Cash: one statement link for B2B buyers. See what you owe across many PayPal invoices and pay them all in one checkout.
-
The buyer’s statement: every memo line kept, returned or still with them, every invoice, and what’s past due. No account needed.
-
Pay $5,000 across several PayPal invoices in one checkout. The split, oldest first, is shown before paying. PayPal, Venmo or Pay Later
-
Ask about the bill. The AI answers only from the buyer’s records, and code checks every figure before it is shown.
-
A buyer’s message becomes a proposal: the AI labels it, code checks it against the records, and the supplier decides.
-
One click on Approve updates the real PayPal invoice: INV-1051 now owes $1,400.00, and the buyer sees the approval.
-
PayPal’s own invoice shows the -$20.00 adjustment the supplier approved. The note links back to the buyer’s statement.
-
Overdue invoice? The AI drafts the reminder, code checks the amount and days, the supplier edits and approves, PayPal sends it.
-
Cheques and wires use the same oldest-first split and are recorded on each PayPal invoice, so PayPal and the statement agree.
-
Measured on 14 held-out messages, 3 passes: the AI agent got 11 to 12 right vs 5 for keyword rules, with 0 unsafe money actions.
-
Proved live: paid on PayPal’s own page, webhook verified in 220 ms, next Pay charged only $4,920.00. Nobody is charged twice.
-
Three Render services, Neon Postgres, PayPal Invoicing and Orders, Meta muse-ember-1.0. The model never calls PayPal.
Inspiration
In B2B trade of physical goods, buyers rarely owe one invoice. They owe many: partial shipments, goods on consignment, returns, credits, deductions. Then they have to work it out by hand. Which order is this invoice for? Did they credit what I sent back? What do I owe across all of these? Only then do they pay, one invoice at a time. Meanwhile the supplier chases by email and phone, then matches the money back to invoices by hand.
The pain is real and measured. More than half of small businesses have invoices unpaid past 30 days, and per Xero's Small Business Insights, small businesses waited 29.3 days on average to get paid in Q2 2026, almost nine days late. On QuickBooks, the request to pay multiple invoices in one payment has 2,125 votes since 2017; Square and Xero users ask for the same. PayPal Invoicing has no statement and no way to pay several invoices together. Enterprises buy receivables portals for this; small suppliers have nothing.
I built the demo around the hardest version of the problem: goods sent on memo (on consignment), where the buyer keeps some pieces, returns the rest, and is invoiced only for what they kept. Jewelry is the demo domain because memo is everyday trade there: in a JA/JBT survey, 39% of US jewelers' store merchandise was memo inventory. Nothing in the product is jewelry-specific: memos, lines, returns and invoices are the same for any physical goods.
What it does
The buyer gets one link. No account, no app.
- See the whole picture. Every memo, line by line: kept (and on which invoice), returned (with the return reference), still with you (and when it's due back). What's owed, how old it is, what's past due.
- Ask about it. "Why is S-102 on my bill?" The AI agent answers from the buyer's own records only, and code checks every number before it's shown.
- Pay many PayPal invoices in one checkout, fully or partly. A preview shows where the money goes. PayPal's buttons offer PayPal, Pay Later, Venmo and card. The receipt shows the split, and each PayPal invoice is updated.
- Tell the supplier something. "S-120 has a scratch, please take $20 off." The agent turns it into a proposal. Nothing changes until the supplier approves.

The supplier sees who owes what across all buyers, payments already split across invoices, and the agent's proposals. One click on Approve updates the real PayPal invoice (or becomes credit if it's already paid). They can record a cheque or wire against the same split, draft a reminder that PayPal sends, and import an ERP export.

Try it: open the live demo, click Start the demo, and you get a private copy with three buyers and real PayPal sandbox invoices. The sandbox buyer login is on the page.
How I built it
PayPal does the real work:
| PayPal | What it does here |
|---|---|
| Invoicing v2: create + send | Every ERP invoice becomes a real PayPal invoice; kept memo lines are line items |
| Orders v2 + JS SDK | One checkout for many invoices, with the split as items and the app's payment id as custom_id |
| Invoicing v2: record payment | The money is recorded on each PayPal invoice, so PayPal's due amounts match the app's |
| Invoicing v2: update | An approved deduction adds a negative line, even on a partly paid invoice |
| Invoicing v2: remind | An approved reminder is sent by PayPal itself |
| Webhooks | A payment made on PayPal's own invoice page reaches the app's ledger about a second later, signature verified |
The AI: the model labels, code decides, a person approves. One agent with three jobs on Meta's muse-ember-1.0 (Meta Model API): answering questions about a statement, turning buyer messages into proposals, and drafting payment reminders. Each job is one structured (json_schema) call with a 7.5 s budget. The model never touches money. Plain code (actions.py) picks every action from the buyer's records: a deduction must be no more than the item's price, a repeat request is answered "already sent", dates are resolved by code. A validator rejects any answer whose money figures, day counts or record references aren't in the records. Buyer text goes in as quoted data, and the model has no tools, so a prompt injection has nothing to call. The agent never calls PayPal. It proposes, the supplier approves, and only then does my code update the invoice.
Stack: Next.js and FastAPI on Render (web, api and a background worker from one Blueprint), Neon Postgres. Built with Claude Code, and the APIMatic Context Plugin for every PayPal Orders call.
APIMatic: 9 logged lookups (docs/APIMATIC.md), and two of them changed the design. PayPal keeps a PayPal-Request-Id for only 6 hours, so retries never rely on it; recording searches for its own note token instead. application_context is deprecated, so checkout uses experience_context. Its context doesn't cover Invoicing or webhooks, so I proved those in the sandbox with probe scripts.
Render: three services from one render.yaml. The health check skips the database so Neon can sleep, and the worker checks every 30 s while something is happening and every 60 min when idle.
Challenges I ran into
Never charging anyone twice. A buyer can pay on the statement or straight on PayPal's invoice page, and PayPal can deliver the webhook seconds or minutes later. If they pay both ways, the money is captured twice. So there are three layers: the webhook takes the PayPal-page payment into the ledger; just before the Pay button charges, it asks PayPal about every invoice it's about to pay; and if both still happen, the duplicate is reduced and held as credit with a card telling the supplier. Every money write takes a per-buyer Postgres lock, every PayPal write is idempotent, and every recorded payment carries a token so a timeout never records twice.
I proved it live on Render: I paid INV-1038 on PayPal's own page. The webhook was verified in 220 ms and the payment was in the ledger about a second later. The next Pay charged only the other two invoices, $4,920.00. No duplicate, no stray credit.
Three real buyers per demo copy without a slow start. Seven PayPal invoices created in parallel queued up in the sandbox (p95 9.8 s locally). The demo now waits only for the first buyer; the other two are set up in the background and can't be paid until they're on PayPal. Demo start on Render: p50 2.1 s, p95 2.8 s.

Accomplishments that I'm proud of
- An agent with a measured result. Agent: 11 to 12 of 14 correct in each pass. Keyword rules: 5 of 14. Unsafe money actions: 0. That's 14 held-out buyer messages I wrote and never used in development, 3 passes, with prompts and code frozen before the run; every miss became a message for the supplier, never a wrong money action. Raw model outputs are in the repo.
- One checkout for many PayPal invoices, with each invoice updated on PayPal afterwards.
- 658 Python tests against real Postgres, property tests for the split, and CI on every push.
- Every PayPal behaviour I depend on is proved in the sandbox with a script, not assumed.
What I learned
Things about PayPal I'd tell the next team:
- A payment you record on an invoice shows "Marked as paid", not "Paid", and a checkout capture id is rejected as its payment id.
- Updating a partly paid invoice works, right down to exactly $0.00 due.
- Webhook simulator events can't be verified by PayPal's verify endpoint. Only real deliveries can, so test with a real sandbox payment.
- The sandbox doesn't enforce the 2-reminders-a-day limit, so your own code has to.
And about AI: writing the held-out test before tuning was the most useful thing I did. It caught a date the code couldn't read ("end of nxt week") that every dev test missed.
What's next for Memo-to-Cash
- A pilot with a real memo supplier, importing their actual ERP export.
- Cheque overpayments held as credit (refused for now, because it's a new money path).
- Beyond memo: the same statement for any supplier with many invoices per customer: distributors, wholesalers, parts suppliers. Anything that can export a CSV can be imported.
Built With
- alembic
- apimatic
- claude-code
- fastapi
- github-jobs
- hypothesis
- meta-model-api
- muse-ember-1.0
- neon
- next.js
- paypal
- paypal-js-sdk
- paypal-orders
- paypal-webhooks
- postgresql
- pydantic
- pytest
- python
- react
- render
- sqlalchemy
- tailwindcss
- typescript
- venmo