File size: 3,429 Bytes
3e8a166
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# management/urls.py
# -*- coding: utf-8 -*-
from django.urls import path, include
from rest_framework_simplejwt.views import TokenRefreshView
from rest_framework.routers import DefaultRouter
from .views import (
    CustomTokenObtainPairView,
    LogoutAPIView, 
    TelegramWebhookView,
    PushSubscriptionAPIView,
    GenerateTelegramTokenAPIView,
    VerifyTelegramTokenAPIView,
    PanelViewSet,
    LicenseViewSet,
    MarzbanAdminViewSet,
    PlanViewSet,
    EndUserViewSet,
    SubscriptionViewSet,
    PaymentViewSet,
    PaymentReceiptUploadAPIView,
    # New views for payment system
    PaymentMethodViewSet,
    PaymentDetailAPIView,
    EndUserPaymentOptionsAPIView,
    # New views that were recently added
    AdminLevel3SubscriptionViewSet,
    PurchaseSubscriptionForUserAPIView,
)

# Create a router and register our viewsets with it.
router = DefaultRouter()
router.register(r'panels', PanelViewSet, basename='panel')
router.register(r'licenses', LicenseViewSet, basename='license')
router.register(r'plans', PlanViewSet, basename='plan')
router.register(r'endusers', EndUserViewSet, basename='enduser')
router.register(r'subscriptions', SubscriptionViewSet, basename='subscription')
router.register(r'payments', PaymentViewSet, basename='payment')
# New: ViewSet for managing payment methods by Admin Level 2
router.register(r'payment-methods', PaymentMethodViewSet, basename='payment-method')
# New: ViewSet for Admin Level 3 to manage subscriptions
router.register(r'admin/subscriptions', AdminLevel3SubscriptionViewSet, basename='admin-subscription')

# The MarzbanAdminViewSet is a custom ViewSet, so we define its paths manually.
marzban_admin_list = MarzbanAdminViewSet.as_view({
    'get': 'list',
    'post': 'create'
})
marzban_admin_detail = MarzbanAdminViewSet.as_view({
    'delete': 'destroy'
})

urlpatterns = [
    # API endpoints
    path('api/token/', CustomTokenObtainPairView.as_view(), name='token_obtain_pair'),
    path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
    path('api/logout/', LogoutAPIView.as_view(), name='logout'),
    # Use the router to handle all ViewSet API endpoints
    path('api/', include(router.urls)),
    # Marzban Admin Management (manual routing for a custom ViewSet)
    path('api/marzban-admins/', marzban_admin_list, name='api_marzban_admin_list'),
    path('api/marzban-admins/<str:pk>/', marzban_admin_detail, name='api_marzban_admin_detail'),
    # Telegram & Push notifications
    path('telegram-webhook/<str:bot_token>/', TelegramWebhookView.as_view(), name='telegram_webhook'),
    path('api/push-subscription/', PushSubscriptionAPIView.as_view(), name='push_subscription'),
    path('api/telegram-token/', GenerateTelegramTokenAPIView.as_view(), name='generate_telegram_token'),
    path('api/verify-telegram-token/', VerifyTelegramTokenAPIView.as_view(), name='verify_telegram_token'),
    path('api/upload-receipt/', PaymentReceiptUploadAPIView.as_view(), name='upload_receipt'),
    # New: Payment System URLs
    path('api/admin/payment-details/', PaymentDetailAPIView.as_view(), name='admin_payment_details'),
    path('api/enduser/payment-options/', EndUserPaymentOptionsAPIView.as_view(), name='enduser_payment_options'),
    # New: URL for EndUser to purchase subscriptions for other users
    path('api/purchase-subscription/', PurchaseSubscriptionForUserAPIView.as_view(), name='purchase_subscription'),
]