Inspiration
Most AI payment agents demand custody or write-access keys and rely on system prompts for safety. A prompt is not a security boundary. Freelancers and small merchants do not need AI holding their funds; they need help with the repetitive work around every payment — verifying arrivals, splitting tax reserves, chasing late invoices, and reconciling records. We built Payus so agents handle all of that while remaining structurally incapable of moving a cent.
What it does
Payus divides operations into twelve seats: six deterministic code modules on the money path, and six Claude agents that only propose or draft.
Four ways to get paid. Signed @username profiles, fixed/open payment links with QR codes, one-off and recurring invoices, and customizable storefronts — plus a checkout API and single-script embed widget. Every flow converges on one idempotent writer (recordCapture()).
Double-entry ledger & splits. Transactions post in integer minor units (trialBalance() === 0n), keyed deterministically so replayed webhooks write nothing. Incoming funds split automatically across owner-defined targets (tax reserves, savings pots) using largest-remainder math. Refunds reverse directly from original settlement entries to the exact cent.
Six AI seats that think and stop:
| Seat | Role |
|---|---|
| Allocator | Proposes how arriving revenue should be split |
| Payer | Proposes payouts and selects the source pot |
| Reporter | Summarizes balances strictly from handed figures |
| Builder | Generates storefront config and block layouts from a prompt |
| Collector | Drafts follow-up reminders for overdue invoices |
| Advisor | Answers book questions backed by database rows |
Deterministic Guardian. Every money movement enters as a proposal evaluated by a pure policy function (allow, ask, or refuse). Approvals are bound to the SHA-256 hash of the proposal payload; any edit voids prior consent. Owners approve or refuse in the dashboard or via Telegram.
Live Canvas Storefront. The Builder writes structured blocks rather than raw HTML, rendered in a sandboxed preview beside block/HTML/inline editors.
How we built it
Built with Next.js 15 (App Router), React 19, tRPC 11, Drizzle ORM, PostgreSQL, PayPal Orders v2 + Web SDK v6, Claude (Anthropic API / Amazon Bedrock), Tailwind CSS v4, Zod, and Vitest.
Three core architectural decisions enforce safety:
- Agents propose; pure code decides. Models never see policy limits or hold execution keys.
decide.tsevaluates every proposal, including the owner's manual Release flow. - Ledger facts only.
unknownNumbers()rejects any Reporter output containing unprovided figures. The Advisor selects one of six predefined queries by enum and displays the backing rows alongside its answer. - Closed agent vocabulary. The Builder outputs fifteen structured block types mapped through
toHtml()and selects payment targets by key rather than writing raw URLs or markup.
Idempotency is enforced across capture:<id>, sender_batch_id, webhook event_id primary keys, and FOR UPDATE SKIP LOCKED job claiming.
Challenges we ran into
- Dangling prompt separators: A blank trailing arrow in our page describer caused the model to loop until hitting 12,000 tokens; trimming empty separators dropped the same run to 287 tokens.
- Schema over prompting: Missing headings persisted across prompt rewrites until
textwas added torequiredin the JSON schema. - Bedrock JSON Schema limits: Array/numeric bounds trigger 400 errors on Bedrock, so bounds were moved into Zod validation and documented in field descriptions.
- Ghost editor rows & stripped links: Inert tags (
<style>,<meta>) caused block count mismatches, andhttp://dev links were stripped by thehttps/mailtosanitiser. Both were fixed by content-based inert detection and explicit sanitiser reporting. - Cross-runtime DOM parsing: Passed
DOMParserin the browser andlinkedomon the server to share one block reader without dual parsers. - Pointer-based reordering: Replaced HTML5 drag-and-drop with pointer events for reliable automation and touch support while retaining keyboard move controls.
- Pre-deadline security fix: Closed a missing secret check on the Telegram webhook and added timing-safe verification backed by regression tests.
- Unapproved Payouts permission: Rather than faking live payouts, releases record transparently as
payout.simulatedand probe PayPal permissions proactively.
Accomplishments that we're proud of
- All twelve seats implemented with clear separation between deterministic money code and proposal-only AI.
- 484 tests across 71 files running against real PostgreSQL for ledger, money-path, and migration guarantees.
- Balanced double-entry books (
0ntrial balance), idempotent captures, and cent-exact proportional refund reversals. - Hash-bound approval logs (
SHA-256) that void consent automatically if a proposal changes. - Unified storefront editor supporting blocks, raw HTML, and direct on-page editing over a single field.
What we learned
- Prompts are code inputs: capture and replay exact inputs instead of guessing model behavior.
- Enforce validation once at shared boundaries (Zod schemas, single sanitiser, single renderer) rather than duplicating checks in agents.
- JSON schema constraints outperform prompt phrasing for structural reliability.
- Never let a model audit its own output; compute deterministic checks first and pass findings by ID.
- Surface unsupported capabilities honestly (
payout.simulated) rather than hiding gaps.
What's next for Payus
- Enable live PayPal Payouts (
PAYPAL_PAYOUTS_ENABLED=true) once account permissions clear. - Add additional payment rails behind existing
invoices,paymentLinks, andcheckoutsservices. - Multi-currency ledger settlement with explicit FX rate policies.
- Unified cross-seat audit thread linking Builder and Advisor histories.
- Non-scope: custody, yield, or embedded wallets — Payus moves funds strictly between PayPal accounts and a verifiable ledger.
Built With
- ag-grid
- amazon-bedrock
- anthropic
- claude
- drizzle-orm
- ed25519
- nextjs
- paypal
- paypal-orders-v2
- paypal-web-sdk-v6
- postgresql
- privy
- react
- resend
- tailwindcss
- trpc
- typescript
- vitest
- zod