Pledge — Project Story
Inspiration
Freelancing is built on trust - and trust breaks down at payment time.
We kept hearing the same story from designers, developers, and writers in our network: they'd agree a job over WhatsApp, deliver the work, and then the client would go quiet. No marketplace involved, no contract, no recourse. The Freelancers Union puts a number on it: 71% of freelancers have had trouble getting paid, and the average disputed invoice is around $6,000.
The problem isn't the relationship - the client and freelancer already found each other. The problem is that the moment work starts, there's no structure around it. We wanted to fix exactly that moment, without forcing anyone into a marketplace they don't need.
The idea: what if you could drop in the WhatsApp chat where you agreed the job, and in two minutes have a milestone plan both sides could act on - with the first payment already secured via PayPal before work starts?
What We Built
Pledge is a lightweight tool that sits between the freelance agreement (wherever it happened) and the first payment. It is not a marketplace, not an escrow service, and not another invoicing tool. It is specifically designed for deals that were already agreed in a chat.
The core flow
- Freelancer uploads chat screenshots (or types the details). AI reads the conversation and builds a milestone plan - with to-dos, due dates, workload weights, and a note of any gaps the chat didn't settle.
- Code splits the total by workload weight using a largest-remainder allocation so the parts always sum exactly to the agreed total (no rounding errors, even in JPY).
- The freelancer reviews and edits, then shares a WhatsApp link. The client opens the plan - no account required - and approves it. On approval, they create an account, tick an auto-release consent, and secure the first milestone with PayPal.
- PayPal places an authorization hold (not a charge) on the client's account. The money goes directly to the freelancer's PayPal when released - Pledge never touches the funds.
- The freelancer works, ticks to-dos, and submits a delivery. AI checks every deliverable against the milestone to-dos before the client sees it.
- The client reviews watermarked previews, sees the AI check result, and approves. PayPal captures the hold, the files unlock, and the next milestone opens.
- If the client goes quiet for 72 hours after delivery - and only because they consented to this upfront — payment auto-releases.
The Deal Agent
A per-deal feed watches the state of every deal and proposes actions:
- Delivery passes AI check → proposes "Release £140 to Riya"
- Client asks for extra work → scope guard fires, proposes a paid add-on with its own hold
- Hold approaches expiry → auto-reauthorizes via PayPal and reports it
- Renewal fails → proposes "Ask client to re-secure"
Every action card shows what it noticed, what it wants to do, and Approve / Dismiss buttons. Only routine renewals and consented auto-releases run without a human click.
How We Built It
Stack
| Concern | Choice |
|---|---|
| App + API | Next.js 16 (App Router), TypeScript strict |
| Database + Auth | Supabase (Postgres + RLS, email OTP, Storage) |
| Payments | PayPal REST v2 (Orders + Payments), sandbox, server-side only |
| AI | Google Gemini (vision model for screenshots, fast model for checks) |
| Deployment | Vercel |
| Validation | Zod on every API input, response, and AI output |
| Tests | Vitest |
Money handling
Money is always stored and calculated as whole numbers in the smallest unit of a currency (such as paise, cents, or pence), along with its ISO-4217 currency code. This helps avoid decimal calculation errors.
The total amount is divided among milestones based on their workload. The formula is:
Milestone Amount = (Total Amount × Milestone Workload) ÷ Total Workload
Any remaining amount after rounding is distributed to the milestones with the largest leftover fractions. This ensures that the total allocated amount exactly matches the original amount, without losing any money.
Every milestone receives at least one minor unit. The logic is fully unit-tested, including JPY (which has no decimal places) and uneven workload distributions.
PayPal integration
Every PayPal call is real (sandbox). Key design decisions:
- Intent: AUTHORIZE - the client is never charged at approval time. The hold is captured only after the client explicitly approves the delivery (or auto-release fires).
- Payee on the order - the freelancer's PayPal email is set as
payeeon the purchase unit, so PayPal moves money directly from client to freelancer. Pledge has no financial role. - Idempotency keys - every POST carries a
PayPal-Request-Idderived frommilestoneId:action:attempt. Network retries are safe. - Race condition prevention -
releaseMilestonedoes a conditional database update fromcapture_claim = NULLto a unique claim key before calling PayPal. If two callers race (e.g. client clicks "Approve" while auto-release fires), exactly one wins the claim and captures. The other gets aCONFLICTand stops. Tested. - Webhook deduplication - each PayPal event ID is stored on first receipt. Duplicate deliveries are silently acknowledged.
AI guardrails
- AI never sets amounts. It returns workload weights; code runs
allocate(). - Chat screenshots and client messages are treated as untrusted data - the system prompt instructs the model to extract facts only and ignore any instructions inside them.
- Every AI output is JSON-schema-constrained with Zod. One retry with the validation errors, then a clear user error.
- Every call is logged to
ai_runswith token counts and latency.
Challenges
1. PayPal sandbox account geography
PayPal's sandbox blocks payments between two Indian accounts (UNSUPPORTED_PAYEE). Since our demo freelancer (Riya) is in India, the demo client's sandbox account had to be a US Personal account. We hit this only during live testing - the API creates the order fine, the error surfaces only when the buyer tries to log into the checkout popup.
2. OneDrive + node_modules
Developing inside OneDrive causes npm install to corrupt node_modules during the sync process (concurrent file writes + cloud sync = missing or truncated packages). We worked around this by pushing to GitHub and letting Vercel build in a clean environment.
3. Capture race condition
The simultaneous approve + auto-release scenario required careful design. A simple status check before calling PayPal is not enough- two server instances can pass the check at the same time. The solution was a capture_claim column with a conditional update (WHERE capture_claim IS NULL), which the database enforces atomically.
4. Hold renewal limits
PayPal authorizations expire after 29 days, with a 3-day "honor period" for reauthorization. The first reauth attempt within that window succeeds; subsequent attempts are rejected with REAUTH_NOT_ALLOWED. The scheduled tick job tracks honor_expires_at and only attempts renewal when needed, and the Deal Agent surfaces failures immediately.
5. Keeping AI out of money decisions
It's tempting to ask the AI to suggest amounts directly. We deliberately kept it out of that path — the AI gives weights (1–100), the allocate() function gives amounts. This means a hallucinated weight can shift proportions slightly but can never produce an amount the freelancer didn't review and agree to.
What We Learned
- PayPal's Orders v2 + Payments v2 APIs are well-designed for this exact use case - an authorize-capture flow with a third-party payee is natively supported, no platform fees or partner onboarding required for the sandbox.
- Zod at every boundary (API input, API response, AI output, environment variables) catches an entire class of bugs at the edges rather than deep in business logic.
- The hardest part of an agentic system is not the AI - it's defining exactly what the agent is not allowed to do autonomously, and making those boundaries visible to the user.
- Supabase RLS is powerful but requires careful migration ordering. Every table needs a policy before any data can be written from the client, and missing a policy produces a silent empty result rather than an error.
What's Next
- Live mode - PayPal's partner (Multiparty) onboarding for platform fees and proper KYC
- WhatsApp Business API - send the plan link directly from Pledge instead of copy-pasting
- Multi-currency FX - real-time indicative rates are already shown; post-capture actuals from PayPal's
seller_receivable_breakdownare already stored - Dispute flow - structured change requests with revision rounds are built; a formal dispute escalation path is not
Built With
- gemini
- next.js
- paypal
- postgresql
- react
- typescript
- vercel