Detect. Diagnose. Recover. Know when to stop. Developed for the Razorpay Buildathon.
RecoverAI is an enterprise-grade autonomous agent that detects revenue at risk, diagnoses transaction failures, calculates the optimal recovery intervention under strict safety guardrails, and provides an explainable, cryptographically chained audit trail.
- Live Demo Dashboard: https://megha1807.github.io/RecoverAI/
- 5-Minute Pitch & Walkthrough Video: Watch the Video
Below is the workflow loop executed for every transaction failure ingest:
graph TD
A[Razorpay Failure Webhook] --> B[Gemini AI Context Diagnosis]
B --> C[Expected Recovery Value Selector]
C --> D[Policy Engine Safety Check]
D -- Pass / High-Value Gate --> E[Bounded Action Execution]
D -- Fail / Compliance Block --> F[Quarantine / Blocked State]
E --> G[Awaiting Outcome & Customer Responses]
G --> H[SHA256 Chained Audit Trail Ledger]
RecoverAI transitions every incident through a rigid, compliance-first state machine:
DETECTED
β
CONTEXT_BUILT
β
DIAGNOSED
β
ACTION_PROPOSED
β
POLICY_VALIDATED ββ(Blocked)ββββββββββββββββ BLOCKED
β
βββ(High Value Gated)ββββββββββββββββββββ HUMAN_APPROVAL_REQUIRED
β
βΌ
ACTION_EXECUTED
β
AWAITING_OUTCOME
βββ(Customer Paid)βββββββββββββββββββββββ RECOVERED
βββ(Customer Opted-out)ββββββββββββββββββ QUARANTINED
βββ(Max Contacts Met)ββββββββββββββββββββ EXHAUSTED
RecoverAI integrates directly with standard Razorpay webhook payloads and API channels:
| Webhook Event | Failure / Risk Trigger | AI Recovery Action | Razorpay API / Output |
|---|---|---|---|
payment.failed (DOWNTIME) |
Gateway downtime / issuer bank 504 | Exponential silent retry | Auto-retry sequence (No contact) |
payment.failed (INSUFFICIENT) |
Insufficient balance / card limits | Smart Retry scheduling + message | Razorpay Smart Retry + WhatsApp Nudge |
checkout.abandoned |
Checkout session abandoned | Dynamic discount coupon link | Razorpay Payment Links API (/v1/payment_links) |
subscription.halted |
Mandate expired / card rotated | Alternative payment setup guide | Mandate Update workflow links |
invoice.expired |
B2B overdue invoices | Dynamic tone-adjusted B2B notice | Automated PTP Tracker link |
Unlike a basic, static cron job that blindly triggers reminders, RecoverAI makes decisions based on real-time parameters:
- Contextual Tone Modulation: The agent automatically shifts outreach tone based on fatigue and age of the invoiceβmoving from a polite, Hinglish payment nudge on Day 1 to a formal merchant statement by Day 7.
- Smart Channel Routing: Automatically selects the best delivery channel (WhatsApp, SMS, or Email) depending on the failure type and customer segment to maximize recovery probability while saving messaging costs.
- Promise-to-Pay (PTP) Parser: Processes inbound customer messages (e.g., "Salary aayegi kal, tab payment karta hoon") using Gemini AI to extract the promised date. The agent automatically creates a
PTP_HOLDand pauses all recovery reminders until the promised date arrives to avoid customer harassment.
RecoverAI operates on a compliance-first model, isolating probabilistic AI decisions from strict, deterministic safety rules:
| Compliance Area | Enforcement Limit | Enforcement Action | Regulatory / Business Context |
|---|---|---|---|
| Contact Throttling | Max 3 outreach attempts per incident | Outreach sequence terminates immediately | Prevents customer fatigue and spam reports |
| Quiet Hours Protection | No communication between 9 PM and 8 AM | Proposal is blocked/rescheduled | RBI & TRAI telemarketing guidelines |
| Merchant Safety Gate | Transactions > βΉ50,000 | Action is suspended pending manual approval | Prevents high-value billing errors |
| Discount Caps | 0% on Subscriptions/Invoices; max 10% on Checkout | Proposal is rejected or reset to 0% | Protects merchant margin from discount leakage |
| Customer Opt-Out | Text containing "STOP", "unsubscribe", etc. | Flow transitions to QUARANTINED and halts |
DNC (Do Not Call) registry compliance |
RecoverAI provides merchant finance and audit teams with a cryptographically chained, tamper-evident JSON audit trail. Every event hash is computed as sha256(prev_hash + timestamp + event + message + details_json).
{
"recovery_id": "rec_98234j2k",
"payment_id": "pay_O8x92Kd",
"original_amount": 4999.00,
"currency": "INR",
"failure_reason": "INSUFFICIENT_FUNDS",
"state_history": [
{
"timestamp": "2026-08-22T10:00:00Z",
"action": "AI_DIAGNOSIS",
"decision": "Soft decline detected. Scheduled retry for 25th (Salary window). Nudge via WhatsApp.",
"prev_hash": "0000000000000000000000000000000000000000000000000000000000000000",
"hash": "8f3e2b10a9c8d7e6f5432109abcdef0123456789abcdef0123456789abcdef01"
},
{
"timestamp": "2026-08-25T09:30:00Z",
"action": "AUTO_RETRY",
"status": "RECOVERED",
"recovered_amount": 4999.00,
"prev_hash": "8f3e2b10a9c8d7e6f5432109abcdef0123456789abcdef0123456789abcdef01",
"hash": "4a3b2c1d0e9f8a7b6c5d4e3f2a1b0c9d8e7f6a5b4c3d2e1f0a9b8c7d6e5f4a3b"
}
],
"compliance_check": {
"quiet_hours_passed": true,
"attempt_count": 1,
"opt_out_status": false
}
}- Duplicate Recovery Prevention: Enforces idempotency keys (SHA256 of order parameters + incident date) on all webhook event processing. If Razorpay triggers multiple identical failure webhooks, RecoverAI rejects duplicate processing, ensuring the customer is never double-charged or spammed.
- Dispute / Fraud Circuit Breaker: Implements an instant stop trigger. If a chargeback, refund request, or card dispute event is detected in the webhook payload, the agent halts all automated communications immediately and quarantines the transaction for risk team audit.
Below is the comparative audit summary of RecoverAI against naive reminder loops run under identical customer response physics:
| Metric | Baseline (Naive Reminders) | RecoverAI (Adaptive Console) | Outcome / Lift |
|---|---|---|---|
| Recovery Rate (%) | 18.82% | 31.18% | +12.36% Recovery Lift |
| Gross Recovered | INR 486,659.00 | INR 806,355.00 | +INR 319,696.00 Recovered |
| Discount Leakage | INR 0.00 | INR 0.00 | βΉ0 Leakage (100% Compliant) |
| Gateway Fees | INR 9,733.18 | INR 16,127.10 | Normal processing cost |
| Message Delivery Costs | INR 1,255.00 | INR 1,350.00 | 270 contacts vs 251 |
| Net Recovered Value | INR 475,670.82 | INR 788,877.90 | +INR 313,207.08 Net ROI Increase |
| Compliance Violations | 133 violations | 0 violations | 100% Compliant Operations |
Run the simulation locally and inspect the interactive audit dashboard in under 2 minutes:
pip install -r requirements.txtTo enable live Gemini AI diagnosis and live Razorpay sandbox link generation, set:
# Windows PowerShell
$env:GEMINI_API_KEY="your-gemini-api-key"
$env:RAZORPAY_KEY_ID="your-razorpay-key-id"
$env:RAZORPAY_KEY_SECRET="your-razorpay-key-secret"
$env:RAZORPAY_WEBHOOK_SECRET="your-webhook-secret-here"Note: If keys are omitted, RecoverAI automatically falls back to Simulation Mode using mock planners, allowing the simulation to run fully out of the box.
python main.pyAfter running the simulation, double-click the file in your project root to open the interactive, search-filterable UI in Chrome:
audit_dashboard.html
- Local SQLite Storage: Used for simplicity during local simulation. In a production environment, SQLite should be swapped for PostgreSQL to support scalable transactional concurrency.
- ConcurrentTime Locks: The webhook handler processes events atomically but does not lock rows at a database-row level for simultaneous duplicate events beyond the deterministic idempotency checks.
- Hinglish Voice Recovery: Integration with outbound voice agents (using Gemini Multimodal Live API over Twilio) to automatically call and resolve payment failures via interactive Hinglish conversations.


