Inspiration
The inspiration for RegretGuard came from a collision of two data points: the staggering cost of e-commerce returns, and PayPal's own research into why they happen. The Scale of the Problem: Returns are not just an operational nuisance; they are a financial haemorrhage. In 2025, global refund volumes grew by 18.1%, and for every $1 million refunded to a customer, retailers absorb approximately $1.3 million in total costs due to reverse logistics, inventory depreciation, and fraud. The problem is particularly acute in fashion, where online return rates frequently exceed 30% of all sales. The Behavioural Root Cause: PayPal Australia's Bedtime Browsing Report (2026) identified a phenomenon they dubbed "Sleepy Shopping." Their research found that 25% of late-night shoppers admit they are more likely to buy impulsively, and 18% buy items they later regret. This aligns with a large-scale academic study (N = 1,625,472) published in Acta Psychologica Sinica, which found that consumers who shop after midnight have a significantly higher probability of returning an item (hazard ratio = 1.2144), driven by ego depletion and impaired decision-making. The Gap We Identified: Despite this clear behavioural pattern, the existing solutions are paternalistic. Retailers either block the purchase or bury the user in a guilt-inducing returns process. We saw an opportunity to use agentic AI on the PayPal payment rail to intervene after the purchase is captured but before the regret crystallizes—offering a cost-recovery exit that respects user autonomy instead of shaming them. RegretGuard turns a documented behavioural flaw into a seamless financial recovery loop.
What it does
RegretGuard is a PayPal-native AI agent that intervenes at the exact moment of post-purchase regret. We built a system that doesn't lecture or block a user from making a purchase, but instead offers a smart, frictionless way to recover their money.
Here is the step-by-step flow of how it works:
Real-Time Signal Capture The journey begins when a user (our persona, Maya) makes a late-night purchase. The moment the transaction is captured, PayPal fires a PAYMENT.CAPTURE.COMPLETED webhook to our backend. The AI agent immediately wakes up, ingesting the transaction metadata without needing any browser extensions or retailer scraping.
Explainable Regret Scoring The AI evaluates the purchase across three dimensions: Temporal (the time of night), Transactional (the high-return fashion category), and Behavioral (Maya's personal historical return rate of 72% for this pattern). It calculates an overall risk score. Rather than a mysterious "black box," the dashboard displays the exact reasoning—for example, showing that the late-night timing contributed +25% to the overall 82% risk score.
The Non-Judgmental Nudge & Human-in-the-Loop If the score is high, RegretGuard doesn't automatically list the item. Instead, it acts as an assistant. It uses AI to draft a complete resale listing (title, price, and description based on market data) and presents it to Maya. She is given complete control: she can click "No Thanks" to dismiss the draft and keep her purchase, or click "Post Listing" to approve the resale.
Cost-Recovery Settlement If Maya approves, the backend securely integrates with the PayPal Orders v2 API to create a real checkout order. A new buyer can then purchase the item. The funds route directly back to Maya's PayPal account, effectively erasing the financial burden of her late-night impulse before the item even ships.
The Core Value: RegretGuard proves that AI can be a helpful, privacy-preserving financial safety net. It shifts the paradigm from "retail returns" to "proactive cost-recovery," solving a multi-billion dollar problem for both consumers and merchants without compromising user autonomy
How we built it
RegretGuard was built as a full-stack application designed to process financial events in real-time while remaining strictly privacy-preserving.
The Backend & Webhook Ingestion (Python / FastAPI) We built a lightweight FastAPI server to handle incoming webhooks from the PayPal Developer platform. When a PAYMENT.CAPTURE.COMPLETED event fires, the server receives the JSON payload. We designed the architecture so that the AI scoring is triggered immediately upon ingestion, before the item even has a chance to ship.
The AI Scoring Engine (Explainable Heuristics) Instead of using a "black-box" neural network, we engineered a transparent, heuristic logistic model. The engine parses the transaction data (timestamp, amount, merchant category) and combines it with the user's historical return data (simulated for the demo). It calculates a weighted risk score and outputs a JSON payload containing the exact percentage contribution of each feature (e.g., "Late Night: +25%"). This ensures the AI is fully explainable to the user.
The PayPal REST API Integration (OAuth 2.0 / Orders v2) We integrated the real PayPal REST API using a custom Python client. The backend handles secure OAuth 2.0 token generation and uses the Orders v2 API to create the resale checkout order. When the order is created, PayPal returns an approval_url, which the frontend uses to redirect the buyer.
The Frontend & UX (HTML / Tailwind CSS / Vanilla JS) We built a clean, mobile-first dashboard using Tailwind CSS. The UI is entirely dynamic: it does not use hardcoded results. The JavaScript sends fetch requests to the backend, receives the AI's JSON output, and dynamically injects the explainability metrics, the risk percentage, and the resale listing data into the DOM. We also implemented a state machine to handle the "Hero → Dashboard → Draft → Checkout → Success" user journey.
Handling the Sandbox Limitations Due to strict regional compliance blocks in the PayPal Sandbox, the final buyer checkout API call fails for our region. To ensure a working demo, we built a simulated checkout UI. However, the backend still makes the real API calls to generate the order, and the UI is driven by the real webhook logic.
Challenges we ran into
The PayPal Developer Sandbox enforces strict regional compliance blocks. During testing, transactions originating from certain regions are declined with an international regulations error. To ensure judges can evaluate the full end-to-end flow, we fully implemented the real OAuth and Order Creation APIs (paypal_client.py), but built a simulated checkout UI for the final video demo to bypass the regional sandbox bug.
Accomplishments that we're proud of
A true payment-rail architecture: We built RegretGuard to be completely privacy-preserving. We did not use retailer scraping, browser extensions, or cookie tracking. The entire AI prediction and resale loop operates solely on the PayPal webhook and API data. This proves that highly personalized AI can exist without compromising user privacy.
Explainable, non-paternalistic AI: We are incredibly proud of the human-in-the-loop design. Instead of autonomously listing the user's item, the AI acts as an assistant that drafts the listing and explains its reasoning. The user retains full control with a simple "No Thanks" or "Post Listing" choice. It is agentic commerce that respects human autonomy.
Overcoming the Sandbox Compliance Block: We successfully integrated the real PayPal OAuth 2.0 and Orders v2 APIs. However, we hit a hard regional compliance block in the PayPal Developer Sandbox. Instead of giving up, we engineered a hybrid solution: the backend makes real API calls to create the order, but we built a simulated checkout UI to bypass the regional bug for the demo. This demonstrates our ability to build production-ready integrations and navigate real-world API limitations.
Dynamic UI driven by backend logic: The frontend doesn't use hardcoded results. When the webhook fires, the backend calculates the exact risk score, and the UI dynamically renders the icons, percentages, and explainability metrics in real-time based on the JSON payload.
What we learned
AI agents need a "brake" built into their design: Building a system that predicts regret taught us that the most critical part of an agent is not its ability to take action, but its ability to stop and ask for permission. Designing the "Draft → Review → Approve/Decline" flow was a masterclass in human-in-the-loop engineering. We learned that AI should never autonomously execute financial actions—it must present options, explain its reasoning, and respect a user's decision to say "No Thanks."
Payment rails are the ultimate data source for behavioral AI: We learned that the PayPal webhook payload is richer than it appears at first glance. Timestamps, merchant categories, and transaction values provide a surprising amount of signal without ever needing to scrape a retailer's website. We discovered that the payment rail is the most privacy-preserving place to run behavioral analysis.
Real-world APIs throw curveballs that no tutorial prepares you for: We spent significant time debugging the international regulations compliance error in the PayPal Sandbox—something completely outside our code. We learned how to read API error codes, isolate the root cause (regional restrictions), and engineer a fallback (simulated checkout) without sacrificing the integrity of the real backend integration.
Explainable AI is a UX problem, not just a math problem: Displaying "0.82" to a user is meaningless. We learned how to break down a logistic model's weights into a natural-language explanation ("Late Night +25%, Fashion +20%") and present it visually on the dashboard. This taught us that the true value of an AI model is only realized when its reasoning is communicated clearly to the end user.
What's next for RegretGuard
The current MVP uses a transparent, heuristic scoring model to prove the concept. We chose an explainable rule-based system rather than a black-box neural network because it allows judges and users to see exactly why a transaction was flagged (e.g., "Late Night +25%, Fashion +20%").
However, the true power of RegretGuard lies in its future feedback loop. Our next milestone is to train the model on real, anonymized PayPal return data and live user interactions.
Here is how that loop works:
Positive Signal (User clicks "Post Listing"): The AI correctly predicted regret. The system records this as a confirmed pattern and reinforces the model's weights for that specific user behavior.
Negative Signal (User clicks "No Thanks"): The AI was wrong; the user actually wanted the item. The system logs this as a false positive and adjusts the model to lower the regret score for that specific pattern in the future.
By treating every user decision as training data, RegretGuard transitions from a static rule-based engine into a personalized, self-improving agent that learns each user's unique "sleepy shopping" patterns over time.
Ultimately, this feedback loop creates a financial safety net that protects consumers from their own late-night impulses while saving retailers billions in reverse logistics.
Built With
- ai
- fastapi
- javascript
- paypal
- paypal-rest-api
- python
- tailwind-css
Log in or sign up for Devpost to join the conversation.