-
-
AR3 (Assess, then Retry, Reroute or Refuse) decides what to do when a PayPal payment fails, and acts only after a person approves.
-
The sandbox buyer approves a real $49.99 PayPal order created by AR3 through the Orders API v2.
-
PayPal returns the buyer to AR3’s return page: the order is approved and ready to capture.
-
The capture fails with a real PayPal 500 error, forced with PayPal’s negative testing (PayPal-Mock-Response).
-
AR3 decides: retry now, safely. The rule table matched, all ten safety checks passed, and a PayPal-Request-Id was created.
-
A named person approves. The same retry is sent twice with one PayPal-Request-Id: PayPal replays it, and there is one capture.
-
No rule for this card error. Two Nemotron Nano reads disagreed, so Nemotron Ultra broke the tie: expired card on a subscription, so stop.
-
A scripted MCP client stands in for an AI shopping agent and asks AR3 before retrying: refused, stop. Server error, retry. Captured, stop.
Inspiration
When a payment fails, someone has to decide what happens next: retry now, retry later, ask the buyer to pay another way, or never retry. PayPal's error tells you what failed. It doesn't make that decision for you, and more and more, the "someone" is an AI agent paying on a customer's behalf. A wrong call either loses a sale a safe retry would have saved, or retries something it never should: a refused or suspected-fraud payment, an order already captured, or the same capture twice.
I first built AR3 (Assess, then Retry, Reroute or Refuse) in October 2026 for failed UPI and card payments in India (Razorpay AI Buildathon, then the Nebius × NVIDIA hackathon). For this hackathon I asked: what would it take for AR3 to sit on top of PayPal, and be safe enough that an agent could ask it before retrying?
What it does
- A PayPal capture fails. In the live demo this is a real PayPal sandbox order, and the failure is a real PayPal error forced with PayPal's negative testing (
PayPal-Mock-Response). - AR3 diagnoses it and picks one of five next steps: retry now, retry later, ask the buyer to fix it or pay another way, stop, or send to a person. Every decision shows its reason, who decided (rule table or Nemotron), and every safety check it passed.
- Nothing happens until a named person approves. Then AR3 acts through the PayPal Orders API: it retries the capture with a
PayPal-Request-Id, sends the buyer back to PayPal, or stops. - A repeated retry doesn't capture twice. The demo sends the same approved retry twice with the same
PayPal-Request-Id; PayPal replays the first result instead of capturing again, and the order shows exactly one capture.
There is also a batch recovery queue (AG Grid) and an MCP tool, decide_failed_payment, so an AI shopping agent can ask AR3 "my PayPal payment failed, what now?" before it retries (demonstrated with a scripted MCP client, agent_demo.py).
How I built it
- PayPal Orders API v2 (sandbox): OAuth, create order (with Pay Now and a return page), capture, show order details,
PayPal-Request-Idfor idempotent retries, andPayPal-Mock-Responsefor real failures on demand. - Rules first: 17 PayPal error cases are decided by a rule table, instantly and for free.
- NVIDIA Nemotron on Nebius Token Factory for errors no rule covers. Nemotron Nano reads each error twice, reasoning off and then on. If both reads name the same cause, AR3 uses it; if they disagree, Nemotron Ultra must pick one; if it can't, a person decides.
- The model diagnoses, code decides. The model names the cause and answers one question: could a later retry work without anyone acting? AR3's code turns that into the action, so the model can't pick an action that contradicts its own diagnosis.
- Ten independent safety checks can overrule any decision.
- Python, Pydantic, Streamlit, AG Grid, MCP Python SDK, httpx, hosted on Render. 74 tests run without API keys.
Challenges I ran into
- A model's confidence is not evidence. Nemotron called a bare HTTP 403 "fraud" with 0.9 confidence. What worked was measuring uncertainty: two independent reads, and a tie-breaker only when they disagree.
- The model sometimes chose an action that contradicted its own diagnosis. The fix was to stop asking it for the action.
- Asking the right question. Recurring payments that failed for low balance were stopped instead of retried later, because the model was asked "must the customer act?". Asking "could a later retry work without anyone acting?" fixed it without adding a single keyword.
- Not overfitting. Every fix had to be a general design change, not a rule for a failing test case.
Accomplishments that I'm proud of
- On 31 PayPal failures that no rule covers (labels written before any model run): 97% and 94% correct across two runs, 0 unsafe actions. Retrying everything once gets 8 of 31 right and makes 11 unsafe retries; rules alone get 5 of 31.
- On the original 150 UPI and card payments: 99% correct, 0 unsafe, 11% sent to a person (not a held-out set: fixes were found on it).
- A live end-to-end PayPal sandbox flow with human approval and a single capture.
- Reporting the whole history honestly, including the first held-out PayPal run (77-81%).
What I learned
Safety in payment AI comes less from a bigger model than from structure: rules for what's known, measured disagreement for what isn't, code for the decision itself, and a person before money moves.
What changed since Oct 1
AR3 began in October 2026 as a UPI and card decision engine; that version is unchanged on the main branch. Built during this hackathon, on the paypal branch: PayPal Orders API v2 integration (orders, captures, negative testing, return page); human-approved actions; idempotent retries with PayPal-Request-Id; PayPal error codes in the rule table and a PayPal adapter; the second Nemotron read and "the model diagnoses, code decides"; a 31-case held-out PayPal evaluation; an MCP tool for AI agents; an AG Grid recovery queue; Render hosting; a new app design. Tests: 45 → 74.
Known limitations
- Sandbox only; not run on live PayPal traffic or real merchant data.
- Orders API only. PayPal Subscriptions already retries failed subscription payments on its own schedule; AR3 doesn't replace that.
- Scheduled retries are recorded, not run.
- The PayPal eval is small (31 cases), written by me, and was viewed while fixing; 1-2 cases still get the wrong action, none unsafe.
- Three of the eight demo failures are simulated PayPal-style errors (labelled in the app). The MCP demo uses a scripted client, not an LLM agent. Approval is a typed name, not real authentication.
What's next
Run scheduled retries for real; PayPal webhooks as input; Subscriptions support with approval; pair AR3 with PayPal's own MCP server and Agent Toolkit; a larger evaluation on real outcomes.