Inspiration
India's small shops run on trust. Regulars buy on credit ("udhaar"), and the owner writes it in a notebook. "Pay later" is where the money leaks: nobody has time to chase ₹840 from one customer and ₹650 from another, and nobody can say which payments have arrived but never reached the books.
An AI that simply moved money would be dangerous in that shop. An AI that finds the money, drafts the collection, and waits for the owner to approve each step is something a shopkeeper can trust. That's Munshi: the word means the clerk who keeps a merchant's accounts.
What it does
Munshi is an AI back office for a shop that sells, stocks and buys: the counter, stock, purchasing, the books, customer credit and staff. Every night its agents read the books and write a morning brief ranked by the money at stake.
With PayPal, that money gets collected:
- Overdue credit to a PayPal link. "3 customers owe ₹2,350 for more than 30 days." One tap drafts a PayPal invoice for a customer's exact balance. The owner approves it, Munshi creates the invoice on PayPal's sandbox, and the customer gets PayPal's own payer page.
- The message is its own approval. As soon as the link exists, Munshi drafts the WhatsApp message that carries it, in English and Hindi. Nothing goes out until the owner approves that too.
- Orders by message, paid by PayPal. A customer writes "1 Wheat flour 5 kg and 2 Butter 100 g, I'll pay by PayPal." The AI points at the words in the message; the catalogue, not the model, sets the prices; the owner approves the order. Then a PayPal link asks for exactly what the order still needs.
- Paid, then recorded. PayPal's payment notice is signature-verified with PayPal and becomes a finding: "Paid on PayPal, not yet in the books." Only an approved "Record this payment" writes the ledger.
- The PayPal desk (AG Grid + AG Charts): everyone who owes, how late, the reminder sent, the PayPal link's state and the next move. Charts by lateness and by link state filter the grid, and every figure opens the row it came from.
- Ask the books. "Which PayPal payments are not in the books yet?" in English or Hindi, by voice or text. The answer, "₹542 for an order and ₹650 for credit", links each number to the stored row. If the books can't support an answer, Munshi says "Cannot verify" instead of guessing.
The one guarantee
Nothing changes the books without a named person's approval, and every number shown traces to a ledger row.
This isn't a UI promise; the database enforces it:
- The agents' database role has no write grant. Agents can only propose drafts.
- A book row is written only by a person's own command, or by an approved draft executed under the approver's identity in one transaction with its audit entry. PostgreSQL itself checks that the approval exists, belongs to this shop, was made in this transaction, and was made by someone allowed to approve it.
- Every amount in a PayPal draft is a reference to a stored cell, never a typed or generated number. A validator rejects any digit in model prose that isn't a stored cell.
- Row-level security is enabled and forced on every table; tenant and actor context is set only inside the transaction.
How we built it
- App: Next.js 16 and React 19 (installable on a phone), a framework-free TypeScript core, PostgreSQL 17 on Supabase, hosted on Vercel.
- PayPal developer platform (sandbox): the Invoicing API v2 (create, send for the payer link, read, cancel,
search), OAuth 2.0 client credentials, webhook signature verification (
verify-webhook-signature) and idempotentPayPal-Request-Ids, all behind one adapter. A jobs sweep makes approved links at PayPal and drafts their messages. The sandbox account can't invoice in INR, so a sandbox currency map sends the shop's rupee digits in USD and says so on the invoice; the books stay in rupees. - AI: a provider layer maps roles to models. Meta's Muse Spark routes questions, reasons and reads photos; Meta's open model narrates; Gemini is the fallback; Sarvam's Bulbul reads answers aloud in Hindi and English. Agents read the books only through named, role-checked reads that store a snapshot, so every figure they cite is a cell.
- AG Grid Community + AG Charts: the PayPal desk, themed to the app, with React cell renderers that link each figure to its source and charts that drive the grid's filter.
- Bryntum Scheduler: a salon's day of bookings, stylists by branch. Moving a booking is the person's own command.
- Render:
render.yamlruns the agents' clock as a cron job (munshi-tick, every 10 minutes: watchers, briefs, PayPal sweeps) and the always-on chat relay as a worker. - APIMatic: generates TypeScript and Python SDKs and a docs portal from Munshi's OpenAPI description
(
pnpm apimatic:sdk,pnpm apimatic:portal). - Postman: a collection with three folders: Munshi's read-only integration feed, the public API v1 (generated from the OpenAPI), and the exact PayPal sandbox calls Munshi makes (token → invoice → send → read → cancel), each with tests, run with Newman.
- Zapier: a Zapier app with read-only triggers ("PayPal payment waiting to be recorded", "New PayPal link made", "New finding"), so an owner can route them to Slack, Sheets or email. Zapier can watch the books but can't change them.
- Tests: 292 test files and 1,916 red-proof cases: each guarded rule is broken on purpose, and its test must fail. Tests run against a real PostgreSQL, never a mock, because RLS and the approval guard are the things under test.
Challenges
- Making "AI + money" safe. Every PayPal step (the link, the message, the record) is a separate draft with its own approval, and the amount is always a pointer to a stored cell. We had to design the database guard so even a compromised agent process couldn't write a ledger row.
- INR on the sandbox. The sandbox merchant account refuses INR invoices, so we built a currency map that keeps the books in rupees and labels the USD invoice honestly.
- One module, many copies. Next.js loads the core once per server bundle, so the PayPal adapter wired at boot was invisible to the copy running the sweep, and approved links waited forever. We found it running live against the sandbox and fixed it with a test that loads two copies of the module.
- A model that admits it doesn't know. A live model sometimes answers "Cannot verify" to a question it answered a minute ago. We kept that behaviour. A wrong number in a shop's books is worse than no number.
What we learned
That the most useful thing an AI can do with money is prepare the decision, not make it. And that PayPal's invoicing and webhook verification fit that model well: the customer pays on PayPal's page, and Munshi only records what PayPal confirms.
What's next
Live PayPal for real merchants (two real businesses, a salon and a boutique, already appear in the demo with sample data), refunds and disputes as approval drafts, and PayPal's agent tooling behind the same one-approval rule.
Built With
- ag-charts
- ag-grid
- apimatic
- bryntum
- gemini
- llama
- meta-muse-spark
- newman
- next.js
- node.js
- openapi
- paypal
- paypal-invoicing-api
- paypal-webhooks
- postgresql
- postman
- react
- render
- sarvam-ai
- supabase
- typescript
- vercel
- zapier
- zod