Inspiration
It's crazy that I got my inspiration from one of the stand-up comedy videos. So, there's a comedian named Manik Manha, and he's a great comedian with a lot of unpredictable humor. I was watching one of his videos online and he was making fun of the verfication done on E-commerce website and it all happened on the very same day I read the problem statement for this hackathon. So what next? I quickly searched it on Gemini of how is my idea for this particular hackathon. After getting some add-ons from gemini, I was ready to build this idea into a project.
What it does
Evidentia is an autonomous legal defense agent for PayPal merchants. The moment a dispute is lodged, Evidentia springs into action:
- It intercepts the incoming PayPal dispute webhook in real-time.
- It queries internal merchant databases via Elastic (orders, ERP systems, carrier delivery confirmations, and CRM chat logs).
- It passes the collected evidence and PayPal reason code to Google Gemini.
- Gemini reasons over the dispute, cross-references PayPal's Merchant Protection guidelines, drafts an airtight defense narrative, and strictly formats the response to PayPal's evidence JSON schema.
- It submits the evidence directly to the PayPal Disputes API (POST/v1/customer/disputes/{id}/provide-evidence).
- It displays the entire audit trail on a high-density AG Grid merchant dashboard with a live terminal event stream. Zero manual intervention. Zero missed deadlines. Sub-10 second resolution.
How we built it
1. Backend & Asynchronous Microservices Python 3.10+ & FastAPI: Powers the core API. FastAPI's asynchronous architecture handles incoming PayPal webhooks without thread-blocking, returning an instant 200 OK acknowledgment to PayPal while dispatching the dispute resolution pipeline as an asynchronous background task. Pydantic v2: Enforces strict validation and serialization across internal data structures, PayPal webhook payloads, and Gemini output models. HTTPX (Async Client): Asynchronous HTTP client configured with connection pooling, keep-alive, and automated OAuth2 token caching for communication with the PayPal REST API.
2. Artificial Intelligence & Legal Reasoning Google Gemini (Gemini 2.0 Flash & Gemini 1.5 Pro): Ingests multi-source evidence documents retrieved from Elasticsearch (carrier delivery receipts, signed GPS coordinates, CRM support chats, and store return policies). Synthesizes a compelling, legally persuasive defense statement that directly addresses the specific dispute reason code (e.g., MERCHANDISE_OR_SERVICE_NOT_RECEIVED, UNAUTHORISED). Enforces structured JSON schema decoding, ensuring output fields precisely match PayPal's required evidence_type and evidence_info specifications.
3. Vector Search & Retrieval-Augmented Generation (RAG) Elasticsearch / Elastic Cloud (Sponsor Integration): Indexes merchant enterprise operational data across multiple indices: merchant_orders: Purchase records, item SKUs, buyer billing/shipping addresses, and invoice IDs. carrier_tracking: FedEx, UPS, and USPS tracking events, geo-coordinates, and signature proofs of delivery. merchant_crm_chats: Customer support transcripts, timestamps, and customer delivery confirmations. merchant_policies: Merchant terms of service, refund rules, and cancellation policies. Enables lightning-fast keyword and semantic vector search, giving the AI agent immediate access to ground-truth evidence records.
4. Frontend & Enterprise Data Grid React 18 & Vite: Provides a high-speed Single-Page Application (SPA) with hot-module reloading and modular component architecture. AG Grid (Sponsor Integration): Serves as the merchant dispute command center. Delivers enterprise-grade capabilities: multi-column sorting, granular filtering, responsive column pinning, status badges (🟢 Auto-Defended, 🟡 Processing, 🔴 Manual Review Needed), and instant row inspection. TailwindCSS & Lucide Icons: Provides an enterprise dark-mode interface with glassmorphic cards, clear visual hierarchy, and intuitive status iconography.
5. Real-Time Telemetry & Event Streaming Server-Sent Events (SSE): Implements a persistent, unidirectional HTTP event stream from FastAPI to the React client. As the pipeline progresses through webhook reception, Elastic querying, Gemini synthesis, and PayPal submission, micro-step logs stream live into the UI terminal with sub-second latency.
6. Payment Platform & Webhooks PayPal Disputes REST API (/v1/customer/disputes): Automates dispute detail retrieval (GET /v1/customer/disputes/{id}) and evidence package dispatch (POST /v1/customer/disputes/{id}/provide-evidence). PayPal Webhooks API: Listens for CUSTOMER.DISPUTE.CREATED events to initiate autonomous dispute defense in real-time. PayPal OAuth2 Engine: Handles secure token retrieval and automatic refresh against PayPal Sandbox servers.
7. Cloud Deployment & DevOps Render (Sponsor Integration): Deploys the FastAPI service with automated TLS/SSL certificate provisioning, providing the public HTTPS URL required for PayPal Sandbox webhook ingestion. Docker & Docker Compose: Containerizes the application for uniform, reproducible execution across local development and cloud production environments.
Challenges we ran into
I was having a few deployment issues at first but fixed it in a few hours and later it was an uptime issue for backend since I was using free software - Render, and the uptime limit for it was around 15 minutes. But it was again solved used a free tool which sends requests to the website and manages the total uptime for a smoother functioning.
Accomplishments that we're proud of
--
What we learned
--
What's next for Evidentia
If Evidentia was to be launched at a lower level through E-commerce platforms then I would be happy to help our small businesses and MSMEs so that they do not run into bankruptcy due to our faults especially in India where it is seen more during festivals. Also, I would be happy to simulate real people's responses rather than dummy entries.
Built With
- docker
- elasticsearch
- fastapi
- gemini2.0
- httpx
- paypaldisputesrest-apis
- pydantic
- python
- react
- render