Inspiration

Small shops hold their customers' money all the time: a climbing gym's class packs, a cafe's house tabs, any balance that is topped up now and spent later. The money moves through PayPal, but the shop's own record of who is owed what lives somewhere else, and the two drift apart in ordinary ways. A payment request times out after the card was already charged. Someone refunds a customer by hand in the PayPal dashboard and never tells the books. Nobody notices until a customer does.

Banks deal with exactly this every night: outcome-unknown transactions, a ledger that must agree with an outside record, corrections that need two people. Small shops get none of it. Backed brings that discipline to a prepaid balance that runs on PayPal.

What it does

  • Top-ups charge a card through PayPal and credit the customer's balance in a double-entry ledger, booking PayPal's fee from the amounts PayPal reports.
  • A timeout is not a failure. If PayPal's answer is lost, the top-up is held as "in doubt", the customer is told not to pay again, a second top-up is refused, and the outcome is settled by re-sending the same PayPal-Request-Id. The customer is credited once.
  • Spending at the counter is a single conditional database update, so a balance cannot go below zero even with concurrent sales.
  • Cash-outs pay a balance back to the cards it came from, split across the original captures. Each refund is its own step with its own stored request id; if one step fails, only that step is sent again.
  • The day close reads every order back from PayPal and compares captures and refunds with the ledger. Three checks must pass: every entry balances, customer balances equal the control account, and the ledger's PayPal cash equals what PayPal's records say. A refund PayPal has that the ledger does not know becomes a break.
  • The AI investigator reads the evidence for a break: PayPal's refund with its note to the payer, the customer's ledger history, and the customer's messages to the shop. It decides what the refund was. "Sorry the coffee was cold" is goodwill: the customer keeps the balance and the shop bears the cost. "Closing my tab" is balance returned. A fixed rule cannot tell these apart, and they lead to different journal entries.
  • Code, not the model, writes the entry. The model picks a treatment and must quote the evidence word for word. Code derives the amounts from PayPal's data and validates the draft. The day close takes the breaks one at a time; each card shows what the AI read, and the books before and after the suggested entry, with a switch to the treatment it turned down and the effect of each on the customer and on the shop.
  • Maker and checker. The person who asked for the correction cannot approve it. A second person approves it from the day close; the entry is then posted on the next business date and the close runs again.

How we built it

Java 21 and Spring Boot with plain SQL on PostgreSQL. PayPal Orders v2 and Payments v2 through the PayPal Java Server SDK, against the sandbox: single-step card capture, refunds with a note to the payer, and order and capture lookups for the close. The SDK's own retries are switched off so the application is the only place that decides whether to retry, and every write carries a request id that was stored before the call.

The ledger is append-only. A deferred constraint trigger in the database rejects any entry that does not balance, and another makes updates and deletes fail. Customer balances carry a CHECK (balance >= 0) constraint. The investigator is one structured-output model call per break behind a small interface, so the provider can be swapped; the demo runs on OpenAI.

Challenges we ran into

  • A 5xx from a payment API does not prove nothing happened. Our first version treated it as "not charged", which would have let a customer pay twice. It is now held as in doubt, like a timeout.
  • A refund step that failed after an unknown outcome must not be given back to the customer's balance, because the refund may already have gone through. Those steps wait instead of compensating.
  • Keeping the model away from the numbers. It never supplies an amount or an id; every quote it gives is checked as a verbatim substring of the evidence before a draft is accepted.

Accomplishments that we're proud of

  • The demo runs against the real PayPal sandbox end to end, including the lost-response case and refunds made outside the ledger.
  • The guarantees are tests, not claims: twenty threads spending from one balance, a capture accepted with the response lost, a cash-out resumed after a failed step, the same webhook delivered twice, a self-approval refused.

What we learned

Most of the work in a payment integration is in the paths where the answer is not known yet. Naming that state and refusing to guess removed most of the ways money could be counted twice.

What's next for Backed

Hosted card fields or vaulted cards instead of a server-side test card, PayPal payouts for cash-outs to customers who did not pay by card, and webhook-driven breaks so a problem shows up before the nightly close.

Which AI tools were used, and how

  • OpenAI API (structured output, one call per break): the investigator that decides how an unexplained PayPal refund should be treated in the books and cites the evidence it used. The code also supports the Claude API for the same role.
  • Claude Code (AI coding agent): wrote and reviewed most of the application code and tests under our direction.
  • PayPal Java Server SDK, generated by APIMatic: every PayPal call in the application.

Built With

Share this project:

Updates

Submission history