Skip to content

Gblack98/bnpl-risk-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

💳 BNPL Real-Time Risk Engine

FastAPI Supabase BNPL Latency

Buy Now Pay Later risk scoring engine — makes approve/decline decisions at checkout in under 100ms.

How It Works

Customer clicks "Pay Later" at checkout
    ↓
POST /bnpl/assess  (with order details + pre-fetched customer features)
    ↓
[Rule Engine]  → instant decline if: 2+ defaults, 3+ active plans, payment_rate < 60%
    ↓
[ML Score]  → gradient boosting model → risk_score (0–1)
    ↓
risk < 0.15 → approved
0.15–0.35  → step_up (2FA required)
> 0.35     → declined
    ↓
Response in <100ms with decision + explanation

API Usage

import httpx

response = httpx.post("https://api.your-domain.com/bnpl/assess", json={
    "customer_id": "C-12345",
    "merchant_id": "M-789",
    "order_amount_usd": 150.0,
    "product_category": "electronics",
    "installments": 3,
    "customer_age_days": 180,
    "previous_bnpl_count": 2,
    "previous_defaults": 0,
    "payment_success_rate": 0.95,
})

print(response.json())
# {"decision": "approved", "risk_score": 0.08, "latency_ms": 12.3}

Decision Logic

Risk Score Decision Action
< 0.15 ✅ Approved Instant approval
0.15 – 0.35 ⚠️ Step-up Request OTP/2FA
> 0.35 ❌ Declined Show decline reason

Stack

FastAPI + Pydantic    → API & validation
Supabase              → Audit log, customer profile store
LightGBM/XGBoost      → Risk scoring model
Redis (optional)      → Feature cache for <100ms latency

Setup

pip install -r requirements.txt
uvicorn app.main:app --reload
# API docs at http://localhost:8000/docs

Author

Ibrahima Gabar DiopGitHub · Kaggle

About

Buy Now Pay Later real-time risk scoring engine — FastAPI + Supabase + ML model serving

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages