Inspiration
Online merchants lose $20+ billion annually to payment fraud and chargebacks. Most fraud detection happens after payment capture, meaning merchants have already lost the funds before fraud is detected. We built PayGuard AI to solve this by analyzing transactions before PayPal captures payment, giving merchants a chance to prevent fraud in real-time.
What it does
PayGuard AI is a pre-capture fraud detection platform that:
- Analyzes PayPal transactions in under 40ms using XGBoost machine learning
- Provides real-time risk scores (GREEN/YELLOW/RED) before payment capture
- Explains every decision using SHAP values for transparency
- Automatically blocks high-risk orders, saving merchants from chargebacks
- Integrates seamlessly with PayPal's Checkout API
Merchants can review flagged transactions, see detailed risk breakdowns, and make informed decisions before accepting payments.
How we built it
Tech Stack:
- Frontend: Next.js 16 with React 19, Tailwind CSS v4, Recharts for analytics
- Backend: Fastify 5.1 API with TypeScript, PostgreSQL 18, Redis 5
- ML Engine: Python FastAPI service with XGBoost 2.1.2 and SHAP explainability
- Integration: PayPal v2 Checkout API with webhook support
ML Model: Trained on 590,000 real fraud transactions from the IEEE-CIS dataset, achieving 89.98% AUC-ROC with 120 engineered features. The model processes 5 categories: transaction amount, card details, device fingerprinting, behavioral patterns, and email domain reputation.
Challenges we ran into
Sub-40ms Latency Requirement: Pre-capture fraud detection must be fast to avoid checkout abandonment. We optimized feature engineering and model inference to stay under 40ms.
Explainable Predictions: Merchants need to understand why transactions are flagged. We integrated SHAP TreeExplainer to provide real-time feature importance for every prediction.
PayPal Sandbox Limitations: Sandbox accounts have restrictions that don't exist in production. We documented workarounds and built comprehensive testing scripts.
Multi-Tenant Architecture: Supporting multiple merchants with isolated data required careful database schema design and API key management.
Accomplishments that we're proud of
- 89.98% AUC-ROC on fraud detection with only 5% false positive rate
- Sub-40ms inference time enabling real-time pre-capture analysis
- 100% test pass rate across 18 blackbox integration scenarios
- Full PayPal integration with order creation, capture, and webhooks
- Explainable predictions using SHAP values for transparency
- Production-ready with multi-tenant support, JWT auth, and Redis caching
What we learned
- Pre-capture prevention is key: Detecting fraud after payment capture is too late
- Explainability matters: Merchants won't trust a black box system
- Speed is critical: Every millisecond of latency impacts conversion rates
- Feature engineering over model complexity: 120 well-crafted features outperform complex architectures
- Real-world testing is challenging: Sandbox limitations require creative workarounds
What's next for PayGuard AI
- 3D Secure (SCA) integration for European merchants
- Stripe payment support to expand beyond PayPal
- Real-time alert webhooks to Slack, Email, and PagerDuty
- Dispute management dashboard to track chargebacks
- A/B testing framework for optimizing risk thresholds
- Mobile app (React Native) for on-the-go fraud monitoring
- Advanced analytics API for custom reporting and integrations
Built With
- axios
- docker
- drizzle-orm
- fastapi
- fastify
- fraud-detection
- jwt
- machine-learning
- next.js
- node.js
- paypal
- postgresql
- python
- react
- recharts
- redis
- shap
- tailwind-css
- typescript
- xgboost
