Buy Now Pay Later risk scoring engine — makes approve/decline decisions at checkout in under 100ms.
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
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}| Risk Score | Decision | Action |
|---|---|---|
| < 0.15 | ✅ Approved | Instant approval |
| 0.15 – 0.35 | Request OTP/2FA | |
| > 0.35 | ❌ Declined | Show decline reason |
FastAPI + Pydantic → API & validation
Supabase → Audit log, customer profile store
LightGBM/XGBoost → Risk scoring model
Redis (optional) → Feature cache for <100ms latency
pip install -r requirements.txt
uvicorn app.main:app --reload
# API docs at http://localhost:8000/docs