Inspiration

We browse online stores all the time. We add things to the cart, get excited, and then at the very last moment the full price appears on the checkout page... and we freeze.

It's not that we don't want it. It's that a dozen questions suddenly hit at once, with no answers. How much will this one payment take out of my balance? Will I still have enough for groceries, transport and daily expenses this month? What happens to the money I'm saving for something bigger? Most of the time we close the tab. When we do buy, we spend the next few weeks second-guessing it.

I realised the checkout page is exactly where this decision happens, and it's the one place that gives you no help at all. It only asks one thing: can you pay the full amount right now? Budgeting apps don't fix this either: they show up after the money is gone, usually to tell you what you did wrong.

So I built the opposite: something that sits inside PayPal checkout, before you pay, and calmly answers "can I afford this, and how?", without guilt, and with numbers you can trust.

What it does

PayPal Pace is an AI affordability agent that lives inside a merchant's PayPal checkout.

  1. Solve: a deterministic solver simulates every PayPal payment plan (pay in full, Pay in 4, Pay Monthly) combined with every subscription you could pause, against your real savings goal and deadline.
  2. Propose: Gemma 2, running locally through Ollama, picks the plan that fits your priority (Career Growth, Balanced or Goal Shield) and explains it in plain, non-judgmental language.
  3. Verify: a numeric firewall checks every number the AI wrote against the solver's output. Hallucinated figures are replaced with verified ones before you see them, and advice to cancel a protected subscription is blocked.
  4. Pay: you check out with a real PayPal sandbox order, created and captured server-side through the Orders v2 API, using PayPal Smart Buttons and Pay Later.
  5. Keep pace: after checkout, the dashboard guards your next installment, logs every agent action in a timeline, finds subscriptions worth hibernating, and checks impulse buys against your goal.

There's also an Agent Lab, where you can run the same agent on any product and price, and a "glass box" that shows every plan the solver scored and why one was chosen. You can even click Inject Hallucination to plant a fake claim and watch the firewall catch it live.

How we built it

  • Next.js 16 (App Router), React 19, TypeScript and Tailwind CSS 4, with Zod validating every API request.
  • PayPal: OAuth 2.0 client-credentials with token caching, Orders v2 (create, capture, details), the PayPal JavaScript SDK (Smart Buttons with PayPal, Pay Later and card funding), Pay Later messaging, and a webhook receiver with signature verification.
  • AI: Gemma 2 (2B) served by Ollama on 127.0.0.1, called with a JSON schema so the model has to return structured output: a recommendation, plus a title and rationale for each plan card.
  • AG Grid for the plan-scoring table, expense rebalancer and subscription value audit; AG Charts for the goal trajectory.

The core rule is that the AI never does the money math. The solver ranks every candidate plan with a weighted objective (lower is better):

$$\text{score} = w_d \cdot \text{delayDays} + w_i \cdot \text{interest} + \text{lifestylePain} - w_r \cdot \text{recovered}_{\$/\text{mo}}$$

The goal impact of a purchase \( P \), with \( R \) left to save over \( D \) days, is

$$\Delta D = \frac{P \cdot D}{R}$$

The firewall then pulls every number out of Gemma's text and accepts it only if it matches a solver fact \( a \):

$$|n - a| \le \max(1,\ 0.02\,|a|)$$

Anything that fails, contradicts the plan, or suggests pausing a protected subscription is rejected and replaced with engine-written text. Gemma's pick is accepted only if it stays within guardrails of the solver's optimum.

Challenges we ran into

  • Small models make up numbers. A 2B model running on a laptop writes fluent text and confidently wrong figures. That's what led to our solve → propose → verify design: let the model do judgment and language, and never trust it with arithmetic.
  • CPU inference is slow. One structured response takes about 30 seconds on CPU. We added request de-duplication, a 10-minute result cache, model pre-warming, and a full deterministic fallback, so the app keeps working even when Ollama isn't running.
  • Keeping the demo reproducible. Goal deadlines are relative to today, so the comparison between plans never drifts over time. Date maths also had to move to the client to work with Next.js 16 prerendering.
  • PayPal SDK lifecycle in React. Re-rendering the buttons for a new plan or funding source meant handling the SDK replacing window.paypal and tearing down components that were already rendered.

Accomplishments that we're proud of

  • A live, explainable hallucination firewall: you can see every AI sentence checked, and inject a fake claim yourself.
  • Real PayPal sandbox payments, with real order and capture IDs, from inside an AI-guided checkout.
  • AI inference that runs entirely on-device: the only model call goes to localhost, so no financial data leaves the machine.
  • A checkout that helps both sides: the shopper gets clarity instead of anxiety, and the merchant gets a cart that doesn't get abandoned.

What I learned

Trustworthy AI in finance is mostly an architecture problem, not a prompting problem. Splitting the work into deterministic math, model judgment and a verifier between them made a small local model genuinely useful. I also learned that tone matters as much as numbers: people make better money decisions when they're shown options, not judged.

What's next for PayPal Pace: AI Affordability Agent for Checkout

  • Let the agent take action: suspend and reactivate subscriptions through the PayPal Subscriptions API, not only in the simulation.
  • A hosted demo with a cloud model option alongside local Gemma.
  • Real transaction history through PayPal Transaction Search, in place of the seeded demo profile.
  • Daily-expense awareness: factor upcoming bills and everyday spending into each plan, so Pace answers "will I still be okay this month?" as well as "what happens to my goal?".
  • Merchant insights: show stores how affordability guidance affects conversion on high-ticket items.

Hackathon prototype built for "Build What's Next with PayPal and AI". Not an official PayPal product. All store brands and products are fictional.

Built With

  • ag-charts
  • ag-grid
  • claude
  • gemma
  • next.js
  • node.js
  • ollama
  • paypal
  • paypal-javascript-sdk
  • paypal-orders-api
  • paypal-pay-later
  • paypal-webhooks
  • react
  • tailwindcss
  • typescript
  • zod
Share this project:

Updates

Submission history