添加后台支付成功记录列表
This commit is contained in:
@@ -12,11 +12,13 @@ from web.services.ops_api import (
|
||||
get_ops_logs,
|
||||
get_ops_truth_history,
|
||||
get_ops_weekly_leaderboard,
|
||||
get_ops_user_subscriptions,
|
||||
grant_ops_points,
|
||||
grant_ops_subscription,
|
||||
list_ops_memberships,
|
||||
list_ops_payment_incidents,
|
||||
resolve_ops_payment_incident,
|
||||
list_ops_payments,
|
||||
search_ops_users,
|
||||
update_ops_config,
|
||||
)
|
||||
@@ -64,6 +66,11 @@ async def ops_resolve_payment_incident(request: Request, event_id: int):
|
||||
return resolve_ops_payment_incident(request, event_id)
|
||||
|
||||
|
||||
@router.get("/api/ops/payments")
|
||||
async def ops_payments(request: Request, limit: int = 50):
|
||||
return list_ops_payments(request, limit=limit)
|
||||
|
||||
|
||||
@router.post("/api/ops/users/grant-points")
|
||||
async def ops_grant_points(request: Request, body: GrantPointsRequest):
|
||||
return grant_ops_points(request, body)
|
||||
@@ -134,6 +141,11 @@ async def ops_subscription_extend(request: Request):
|
||||
return extend_ops_subscription(request, email=email, additional_days=days)
|
||||
|
||||
|
||||
@router.get("/api/ops/subscriptions/user")
|
||||
async def ops_user_subscriptions(request: Request, email: str = ""):
|
||||
return get_ops_user_subscriptions(request, email=email)
|
||||
|
||||
|
||||
# ── Logs ────────────────────────────────────────────────────────────
|
||||
|
||||
@router.get("/api/ops/logs")
|
||||
|
||||
@@ -191,6 +191,41 @@ def resolve_ops_payment_incident(request: Request, event_id: int) -> Dict[str, A
|
||||
return {"ok": True, "incident": resolved}
|
||||
|
||||
|
||||
def list_ops_payments(
|
||||
request: Request,
|
||||
limit: int = 50,
|
||||
) -> Dict[str, Any]:
|
||||
"""List successful payment records from Supabase."""
|
||||
_require_ops(request)
|
||||
import os
|
||||
import requests as _requests
|
||||
|
||||
supabase_url = str(os.getenv("SUPABASE_URL") or "").strip().rstrip("/")
|
||||
service_role_key = str(os.getenv("SUPABASE_SERVICE_ROLE_KEY") or "").strip()
|
||||
if not supabase_url or not service_role_key:
|
||||
raise HTTPException(status_code=503, detail="Supabase not configured")
|
||||
|
||||
headers = {
|
||||
"apikey": service_role_key,
|
||||
"Authorization": f"Bearer {service_role_key}",
|
||||
}
|
||||
safe_limit = max(1, min(int(limit or 50), 200))
|
||||
resp = _requests.get(
|
||||
f"{supabase_url}/rest/v1/payments",
|
||||
headers=headers,
|
||||
params={
|
||||
"select": "id,user_id,amount,currency,chain,tx_hash,status,created_at",
|
||||
"order": "created_at.desc",
|
||||
"limit": str(safe_limit),
|
||||
},
|
||||
timeout=10,
|
||||
)
|
||||
rows = resp.json() if resp.ok and resp.content else []
|
||||
if not isinstance(rows, list):
|
||||
rows = []
|
||||
return {"payments": rows, "total": len(rows)}
|
||||
|
||||
|
||||
def grant_ops_points(request: Request, body: GrantPointsRequest) -> Dict[str, Any]:
|
||||
admin = _require_ops(request) or {}
|
||||
db = DBManager()
|
||||
|
||||
Reference in New Issue
Block a user