Skip to content
megha1807Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

RecoverAI - Autonomous Revenue Recovery Console

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 & Walkthrough


1. Architecture & State Machine Loop

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]
Loading

Bounded State Machine

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

2. Razorpay Webhook & API Mapping

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

3. The "Why AI?" Factor: Intervention Decision Matrix

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_HOLD and pauses all recovery reminders until the promised date arrives to avoid customer harassment.

4. Stopping Rules & Compliance Matrix

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

5. Cryptographic Audit Trail Schema

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
  }
}

6. Edge Cases & Safety Guardrails

  • 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.

7. Batch Results / ROI Summary (100-Incident Benchmark)

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

8. Quickstart / Demo Run

Run the simulation locally and inspect the interactive audit dashboard in under 2 minutes:

Step 1: Install Dependencies

pip install -r requirements.txt

Step 2: Configure Keys (Optional)

To 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.

Step 3: Run the Simulation

python main.py

Step 4: Open the Audit Dashboard

After running the simulation, double-click the file in your project root to open the interactive, search-filterable UI in Chrome:

audit_dashboard.html

9. Dashboard UI Previews

1. Executive ROI Summary & Compliance Guardrails

Executive Summary

2. Multi-Source Performance & Yield Analytics

Analytics & Charts

3. Search-Filterable Incident Audit Logs

Incident Audit Logs


10. Known Limitations

  1. Local SQLite Storage: Used for simplicity during local simulation. In a production environment, SQLite should be swapped for PostgreSQL to support scalable transactional concurrency.
  2. 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.

11. Future Directions

  • 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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages