STripe Paymen and PK payemtns and many othe rbacekd and froentened issues

This commit is contained in:
IGNY8 VPS (Salman)
2026-01-07 05:51:36 +00:00
parent 87d1662a18
commit 0386d4bf33
24 changed files with 1079 additions and 174 deletions

View File

@@ -0,0 +1,42 @@
"""
Utility views for miscellaneous API endpoints
"""
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import permissions
class GeoDetectView(APIView):
"""
Detect user's country from request headers.
Uses Cloudflare's CF-IPCountry header if behind Cloudflare,
otherwise falls back to checking X-Country-Code or other headers.
This endpoint is used by the frontend to determine which signup page
to show (/signup for global, /signup/pk for Pakistan).
"""
permission_classes = [permissions.AllowAny]
def get(self, request):
# Try Cloudflare header first (most reliable when behind CF)
country_code = request.META.get('HTTP_CF_IPCOUNTRY', '')
# Fallback to X-Country-Code header (can be set by load balancer/CDN)
if not country_code:
country_code = request.META.get('HTTP_X_COUNTRY_CODE', '')
# Fallback to GeoIP2 if available (Django GeoIP2 middleware)
if not country_code:
country_code = getattr(request, 'country_code', '')
# Default to empty string (frontend will treat as global)
country_code = country_code.upper() if country_code else ''
return Response({
'success': True,
'data': {
'country_code': country_code,
'detected': bool(country_code),
}
})