Inspiration In an Indian housing society, forty flats buy the same rice, dal, oil and eggs every week, one by one, at retail. Wholesalers would charge 10 to 30% less, but only above a minimum order no single flat reaches. A volunteer usually pools orders in a WhatsApp group, chases payments and fronts the money. It breaks at about fifteen households, and the volunteer carries the risk.
What it does Collective does the volunteer's job with an AI agent and moves the money risk to PayPal.
Residents type a list or photograph a handwritten one; the AI turns it into products and blocks anything that can't be sold (alcohol, tobacco, medicines). Each product becomes a pool. Local suppliers bid a ladder of prices that fall as the order grows. Suppliers see totals only, never who ordered what. Code ranks the bids on price, the supplier's verified track record and whether the minimum is reachable, so the cheapest supplier doesn't win by default. The AI explains each ranking to the society captain. Each resident approves one PayPal hold for the highest price their items could cost. As neighbours join, the price falls for everyone in the pool. Money on the table: the Society Secretary, an AI agent, tells each winning supplier how many households and dollars are already authorized in PayPal and asks for a lower price at that quantity. Prices can only go down. At cutoff PayPal captures only the price the building unlocked; the rest of every hold goes back. A pool that misses its minimum is released and nobody pays for it. A declined card affects only that flat. If something is missing or damaged, the Secretary refunds it through PayPal itself, within limits set in code; bigger claims go to the captain. Suppliers are paid with PayPal Payouts after a 24-hour window for problems, minus commission and refunds. How we built it PayPal: Orders v2 with intent=AUTHORIZE, authorization, partial capture with final_capture, void, get authorization, refunds, Payouts, Subscriptions (catalog and plans) for supplier plans, and verified webhooks. Orders and Payments run on PayPal's official Server SDK, generated by APIMatic. Every POST carries a PayPal-Request-Id, so a retry never charges twice. A double-entry ledger records every charge, fee, refund, commission and payout and must balance to the cent. AI: one tool-using agent (the Society Secretary) with eight tools, plus agents for reading lists and photos, explaining bids, suggesting supplier price ladders, assessing complaints, and an AI analyst in AG Studio. Gemini runs first and Groq takes over if Gemini is rate-limited or down. Every reply is validated JSON and every decision is logged with the model that made it. Safety by construction: no agent can capture, void or pay out; only the engine does. The Secretary's refund tool is checked in code ($10 maximum, never above what was charged, a limited number per flat). A supplier's new price can only be lower, never below its floor, and never changes the first price the holds were sized on, so every capture fits inside its hold. Trust: supplier scores come from verified deliveries and upheld complaints, smoothed for small samples and weighted to recent weeks. Bids are scored price 40, trust 45, reachable minimum 15. Stack: Next.js 16, React 19, TypeScript, Drizzle on Postgres (PGlite locally, Neon for the hosted demo), deployed on Render. Reliability: 57 automated tests, including a full week, a second week after reset, a failed void not blocking cutoff, idempotent re-runs, restart recovery and the guided tour end to end. The whole week also runs on the real PayPal sandbox (npm run sandbox:week). With no keys at all it runs on a PayPal stand-in and rule-based AI, so anyone can try it. Design One calm interface for four people: resident, society captain, supplier and operator. A guided tour walks the whole week with one button per step, spotlights the part of the page each step is about, says what could go wrong, and at the edge cases lets you choose what happens. The receipt shows approved, paid and released, with the PayPal ID of each step and a "Check this with PayPal" button.
Potential impact Households save on staples they buy anyway; the volunteer stops fronting money; small local suppliers get funded, consolidated orders and a reputation they earn by delivering. The same pattern (approve a maximum, pay what the group unlocked) works for any community purchase: school supplies, maintenance, solar.
What's new The PayPal hold is the agent's budget: the spending limit lives in the payment rail, not in a prompt. Money on the table: an agent negotiates with funds that are already authorized. Trust beats cheap: suppliers are ranked on verified payment and delivery facts, not star ratings. Challenges, what we learned, what's next Making partial capture, void and refund safe to retry and safe after a crash, and keeping PayPal calls fast without letting database writes overlap. Learned: a declined sandbox card comes back as a successful response with a DENIED authorization, not an error, so a hold has to be checked, not assumed. Retail-price search needs a same-product check, or "jasmine rice" matches rice cookers. Next: PayPal Multiparty so suppliers are paid directly with platform_fees; pools across several societies; a local payment partner for rupee payments in India. Honest limits PayPal sandbox only; no real money moves. The Pune demo runs in US dollars because PayPal doesn't process domestic rupee payments. The hosted demo is one shared building on a free server.
Built With
- ag-grid
- ag-studio
- apimatic
- bryntum
- channel3
- drizzle
- gemini
- groq
- neon
- next.js
- paypal
- paypal-orders-v2
- paypal-payouts
- paypal-server-sdk
- paypal-subscriptions
- paypal-webhooks
- pglite
- postgresql
- react
- render
- typescript
- zod