django-cfg 1.2.22__py3-none-any.whl → 1.2.25__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. django_cfg/__init__.py +1 -1
  2. django_cfg/apps/knowbase/tasks/archive_tasks.py +6 -6
  3. django_cfg/apps/knowbase/tasks/document_processing.py +3 -3
  4. django_cfg/apps/knowbase/tasks/external_data_tasks.py +2 -2
  5. django_cfg/apps/knowbase/tasks/maintenance.py +3 -3
  6. django_cfg/apps/payments/admin/__init__.py +23 -0
  7. django_cfg/apps/payments/admin/api_keys_admin.py +347 -0
  8. django_cfg/apps/payments/admin/balance_admin.py +434 -0
  9. django_cfg/apps/payments/admin/currencies_admin.py +186 -0
  10. django_cfg/apps/payments/admin/filters.py +259 -0
  11. django_cfg/apps/payments/admin/payments_admin.py +142 -0
  12. django_cfg/apps/payments/admin/subscriptions_admin.py +227 -0
  13. django_cfg/apps/payments/admin/tariffs_admin.py +199 -0
  14. django_cfg/apps/payments/config/__init__.py +65 -0
  15. django_cfg/apps/payments/config/module.py +70 -0
  16. django_cfg/apps/payments/config/providers.py +115 -0
  17. django_cfg/apps/payments/config/settings.py +96 -0
  18. django_cfg/apps/payments/config/utils.py +52 -0
  19. django_cfg/apps/payments/decorators.py +291 -0
  20. django_cfg/apps/payments/management/__init__.py +3 -0
  21. django_cfg/apps/payments/management/commands/README.md +178 -0
  22. django_cfg/apps/payments/management/commands/__init__.py +3 -0
  23. django_cfg/apps/payments/management/commands/currency_stats.py +323 -0
  24. django_cfg/apps/payments/management/commands/populate_currencies.py +246 -0
  25. django_cfg/apps/payments/management/commands/update_currencies.py +336 -0
  26. django_cfg/apps/payments/managers/currency_manager.py +65 -14
  27. django_cfg/apps/payments/middleware/api_access.py +294 -0
  28. django_cfg/apps/payments/middleware/rate_limiting.py +216 -0
  29. django_cfg/apps/payments/middleware/usage_tracking.py +296 -0
  30. django_cfg/apps/payments/migrations/0001_initial.py +125 -11
  31. django_cfg/apps/payments/models/__init__.py +18 -0
  32. django_cfg/apps/payments/models/api_keys.py +2 -2
  33. django_cfg/apps/payments/models/balance.py +2 -2
  34. django_cfg/apps/payments/models/base.py +16 -0
  35. django_cfg/apps/payments/models/events.py +2 -2
  36. django_cfg/apps/payments/models/payments.py +112 -2
  37. django_cfg/apps/payments/models/subscriptions.py +2 -2
  38. django_cfg/apps/payments/services/__init__.py +64 -7
  39. django_cfg/apps/payments/services/billing/__init__.py +8 -0
  40. django_cfg/apps/payments/services/cache/__init__.py +15 -0
  41. django_cfg/apps/payments/services/cache/base.py +30 -0
  42. django_cfg/apps/payments/services/cache/simple_cache.py +135 -0
  43. django_cfg/apps/payments/services/core/__init__.py +17 -0
  44. django_cfg/apps/payments/services/core/balance_service.py +447 -0
  45. django_cfg/apps/payments/services/core/fallback_service.py +432 -0
  46. django_cfg/apps/payments/services/core/payment_service.py +576 -0
  47. django_cfg/apps/payments/services/core/subscription_service.py +614 -0
  48. django_cfg/apps/payments/services/internal_types.py +297 -0
  49. django_cfg/apps/payments/services/middleware/__init__.py +8 -0
  50. django_cfg/apps/payments/services/monitoring/__init__.py +22 -0
  51. django_cfg/apps/payments/services/monitoring/api_schemas.py +222 -0
  52. django_cfg/apps/payments/services/monitoring/provider_health.py +372 -0
  53. django_cfg/apps/payments/services/providers/__init__.py +22 -0
  54. django_cfg/apps/payments/services/providers/base.py +137 -0
  55. django_cfg/apps/payments/services/providers/cryptapi.py +273 -0
  56. django_cfg/apps/payments/services/providers/cryptomus.py +310 -0
  57. django_cfg/apps/payments/services/providers/nowpayments.py +293 -0
  58. django_cfg/apps/payments/services/providers/registry.py +103 -0
  59. django_cfg/apps/payments/services/security/__init__.py +34 -0
  60. django_cfg/apps/payments/services/security/error_handler.py +637 -0
  61. django_cfg/apps/payments/services/security/payment_notifications.py +342 -0
  62. django_cfg/apps/payments/services/security/webhook_validator.py +475 -0
  63. django_cfg/apps/payments/services/validators/__init__.py +8 -0
  64. django_cfg/apps/payments/signals/__init__.py +13 -0
  65. django_cfg/apps/payments/signals/api_key_signals.py +160 -0
  66. django_cfg/apps/payments/signals/payment_signals.py +128 -0
  67. django_cfg/apps/payments/signals/subscription_signals.py +196 -0
  68. django_cfg/apps/payments/tasks/__init__.py +12 -0
  69. django_cfg/apps/payments/tasks/webhook_processing.py +177 -0
  70. django_cfg/apps/payments/urls.py +5 -5
  71. django_cfg/apps/payments/utils/__init__.py +45 -0
  72. django_cfg/apps/payments/utils/billing_utils.py +342 -0
  73. django_cfg/apps/payments/utils/config_utils.py +245 -0
  74. django_cfg/apps/payments/utils/middleware_utils.py +228 -0
  75. django_cfg/apps/payments/utils/validation_utils.py +94 -0
  76. django_cfg/apps/payments/views/payment_views.py +40 -2
  77. django_cfg/apps/payments/views/webhook_views.py +266 -0
  78. django_cfg/apps/payments/viewsets.py +65 -0
  79. django_cfg/apps/support/signals.py +16 -4
  80. django_cfg/apps/support/templates/support/chat/ticket_chat.html +1 -1
  81. django_cfg/cli/README.md +2 -2
  82. django_cfg/cli/commands/create_project.py +1 -1
  83. django_cfg/cli/commands/info.py +1 -1
  84. django_cfg/cli/main.py +1 -1
  85. django_cfg/cli/utils.py +5 -5
  86. django_cfg/core/config.py +18 -4
  87. django_cfg/models/payments.py +546 -0
  88. django_cfg/models/revolution.py +1 -1
  89. django_cfg/models/tasks.py +51 -2
  90. django_cfg/modules/base.py +12 -6
  91. django_cfg/modules/django_currency/README.md +104 -269
  92. django_cfg/modules/django_currency/__init__.py +99 -41
  93. django_cfg/modules/django_currency/clients/__init__.py +11 -0
  94. django_cfg/modules/django_currency/clients/coingecko_client.py +257 -0
  95. django_cfg/modules/django_currency/clients/yfinance_client.py +246 -0
  96. django_cfg/modules/django_currency/core/__init__.py +42 -0
  97. django_cfg/modules/django_currency/core/converter.py +169 -0
  98. django_cfg/modules/django_currency/core/exceptions.py +28 -0
  99. django_cfg/modules/django_currency/core/models.py +54 -0
  100. django_cfg/modules/django_currency/database/__init__.py +25 -0
  101. django_cfg/modules/django_currency/database/database_loader.py +507 -0
  102. django_cfg/modules/django_currency/utils/__init__.py +9 -0
  103. django_cfg/modules/django_currency/utils/cache.py +92 -0
  104. django_cfg/modules/django_email.py +42 -4
  105. django_cfg/modules/django_unfold/dashboard.py +20 -0
  106. django_cfg/registry/core.py +10 -0
  107. django_cfg/template_archive/__init__.py +0 -0
  108. django_cfg/template_archive/django_sample.zip +0 -0
  109. {django_cfg-1.2.22.dist-info → django_cfg-1.2.25.dist-info}/METADATA +11 -6
  110. {django_cfg-1.2.22.dist-info → django_cfg-1.2.25.dist-info}/RECORD +113 -50
  111. django_cfg/apps/agents/examples/__init__.py +0 -3
  112. django_cfg/apps/agents/examples/simple_example.py +0 -161
  113. django_cfg/apps/knowbase/examples/__init__.py +0 -3
  114. django_cfg/apps/knowbase/examples/external_data_usage.py +0 -191
  115. django_cfg/apps/knowbase/mixins/examples/vehicle_model_example.py +0 -199
  116. django_cfg/apps/payments/services/base.py +0 -68
  117. django_cfg/apps/payments/services/nowpayments.py +0 -78
  118. django_cfg/apps/payments/services/providers.py +0 -77
  119. django_cfg/apps/payments/services/redis_service.py +0 -215
  120. django_cfg/modules/django_currency/cache.py +0 -430
  121. django_cfg/modules/django_currency/converter.py +0 -324
  122. django_cfg/modules/django_currency/service.py +0 -277
  123. {django_cfg-1.2.22.dist-info → django_cfg-1.2.25.dist-info}/WHEEL +0 -0
  124. {django_cfg-1.2.22.dist-info → django_cfg-1.2.25.dist-info}/entry_points.txt +0 -0
  125. {django_cfg-1.2.22.dist-info → django_cfg-1.2.25.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,199 @@
1
+ """
2
+ Admin interface for tariffs.
3
+ """
4
+
5
+ from django.contrib import admin
6
+ from django.utils.html import format_html
7
+ from django.contrib.humanize.templatetags.humanize import naturaltime
8
+ from unfold.admin import ModelAdmin
9
+ from unfold.decorators import display
10
+
11
+ from ..models import Tariff, TariffEndpointGroup
12
+
13
+
14
+ @admin.register(Tariff)
15
+ class TariffAdmin(ModelAdmin):
16
+ """Admin interface for tariffs."""
17
+
18
+ list_display = [
19
+ 'tariff_display',
20
+ 'price_display',
21
+ 'limit_display',
22
+ 'status_display',
23
+ 'endpoint_groups_count',
24
+ 'created_at_display'
25
+ ]
26
+
27
+ list_display_links = ['tariff_display']
28
+
29
+ search_fields = ['name', 'display_name', 'description']
30
+
31
+ list_filter = ['is_active', 'created_at']
32
+
33
+ readonly_fields = ['created_at', 'updated_at']
34
+
35
+ fieldsets = [
36
+ ('Tariff Information', {
37
+ 'fields': ['name', 'display_name', 'description']
38
+ }),
39
+ ('Pricing & Limits', {
40
+ 'fields': ['monthly_price', 'request_limit']
41
+ }),
42
+ ('Settings', {
43
+ 'fields': ['is_active']
44
+ }),
45
+ ('Timestamps', {
46
+ 'fields': ['created_at', 'updated_at'],
47
+ 'classes': ['collapse']
48
+ })
49
+ ]
50
+
51
+ @display(description="Tariff")
52
+ def tariff_display(self, obj):
53
+ """Display tariff name and description."""
54
+ return format_html(
55
+ '<strong>{}</strong><br><small>{}</small>',
56
+ obj.display_name,
57
+ obj.description[:50] + '...' if len(obj.description) > 50 else obj.description
58
+ )
59
+
60
+ @display(description="Price")
61
+ def price_display(self, obj):
62
+ """Display price with free indicator."""
63
+ if obj.monthly_price == 0:
64
+ return format_html(
65
+ '<span style="background: #28a745; color: white; padding: 2px 6px; border-radius: 3px; font-size: 11px;">FREE</span>'
66
+ )
67
+ else:
68
+ return format_html(
69
+ '<strong>${:.2f}</strong>/month',
70
+ obj.monthly_price
71
+ )
72
+
73
+ @display(description="Request Limit")
74
+ def limit_display(self, obj):
75
+ """Display request limit."""
76
+ if obj.request_limit == 0:
77
+ return format_html(
78
+ '<span style="color: #28a745; font-weight: bold;">Unlimited</span>'
79
+ )
80
+ else:
81
+ return format_html(
82
+ '<strong>{:,}</strong>/month',
83
+ obj.request_limit
84
+ )
85
+
86
+ @display(description="Status")
87
+ def status_display(self, obj):
88
+ """Display status badge."""
89
+ if obj.is_active:
90
+ return format_html(
91
+ '<span style="background: #28a745; color: white; padding: 2px 6px; border-radius: 3px; font-size: 11px;">Active</span>'
92
+ )
93
+ else:
94
+ return format_html(
95
+ '<span style="background: #dc3545; color: white; padding: 2px 6px; border-radius: 3px; font-size: 11px;">Inactive</span>'
96
+ )
97
+
98
+ @display(description="Endpoint Groups")
99
+ def endpoint_groups_count(self, obj):
100
+ """Display count of endpoint groups."""
101
+ count = obj.endpoint_groups.filter(is_enabled=True).count()
102
+ total = obj.endpoint_groups.count()
103
+
104
+ if total == 0:
105
+ return format_html('<span style="color: #6c757d;">No groups</span>')
106
+
107
+ return format_html(
108
+ '<strong>{}</strong> active<br><small>{} total</small>',
109
+ count,
110
+ total
111
+ )
112
+
113
+ @display(description="Created")
114
+ def created_at_display(self, obj):
115
+ """Display creation date."""
116
+ return naturaltime(obj.created_at)
117
+
118
+
119
+ @admin.register(TariffEndpointGroup)
120
+ class TariffEndpointGroupAdmin(ModelAdmin):
121
+ """Admin interface for tariff endpoint group associations."""
122
+
123
+ list_display = [
124
+ 'association_display',
125
+ 'tariff_display',
126
+ 'endpoint_group_display',
127
+ 'status_display',
128
+ 'created_at_display'
129
+ ]
130
+
131
+ list_display_links = ['association_display']
132
+
133
+ search_fields = [
134
+ 'tariff__name',
135
+ 'tariff__display_name',
136
+ 'endpoint_group__name',
137
+ 'endpoint_group__display_name'
138
+ ]
139
+
140
+ list_filter = ['is_enabled', 'tariff', 'endpoint_group', 'created_at']
141
+
142
+ readonly_fields = ['created_at', 'updated_at']
143
+
144
+ fieldsets = [
145
+ ('Association', {
146
+ 'fields': ['tariff', 'endpoint_group', 'is_enabled']
147
+ }),
148
+ ('Timestamps', {
149
+ 'fields': ['created_at', 'updated_at'],
150
+ 'classes': ['collapse']
151
+ })
152
+ ]
153
+
154
+ @display(description="Association")
155
+ def association_display(self, obj):
156
+ """Display association ID."""
157
+ return format_html(
158
+ '<strong>#{}</strong><br><small>{} → {}</small>',
159
+ str(obj.id)[:8],
160
+ obj.tariff.name,
161
+ obj.endpoint_group.name
162
+ )
163
+
164
+ @display(description="Tariff")
165
+ def tariff_display(self, obj):
166
+ """Display tariff information."""
167
+ price_text = 'FREE' if obj.tariff.monthly_price == 0 else f'${obj.tariff.monthly_price:.2f}/mo'
168
+
169
+ return format_html(
170
+ '<strong>{}</strong><br><small>{}</small>',
171
+ obj.tariff.display_name,
172
+ price_text
173
+ )
174
+
175
+ @display(description="Endpoint Group")
176
+ def endpoint_group_display(self, obj):
177
+ """Display endpoint group information."""
178
+ return format_html(
179
+ '<strong>{}</strong><br><small>{}</small>',
180
+ obj.endpoint_group.display_name,
181
+ obj.endpoint_group.description[:30] + '...' if len(obj.endpoint_group.description) > 30 else obj.endpoint_group.description
182
+ )
183
+
184
+ @display(description="Status")
185
+ def status_display(self, obj):
186
+ """Display status badge."""
187
+ if obj.is_enabled:
188
+ return format_html(
189
+ '<span style="background: #28a745; color: white; padding: 2px 6px; border-radius: 3px; font-size: 11px;">Enabled</span>'
190
+ )
191
+ else:
192
+ return format_html(
193
+ '<span style="background: #dc3545; color: white; padding: 2px 6px; border-radius: 3px; font-size: 11px;">Disabled</span>'
194
+ )
195
+
196
+ @display(description="Created")
197
+ def created_at_display(self, obj):
198
+ """Display creation date."""
199
+ return naturaltime(obj.created_at)
@@ -0,0 +1,65 @@
1
+ """
2
+ Universal Payment Configuration.
3
+
4
+ Modular configuration system for the payments module.
5
+ """
6
+
7
+ # Core configuration classes
8
+ from .settings import PaymentsSettings
9
+
10
+ # Import unified settings from models.payments
11
+ from django_cfg.models.payments import (
12
+ SecuritySettings,
13
+ RateLimitSettings,
14
+ NotificationSettings,
15
+ SubscriptionSettings
16
+ )
17
+
18
+ # Provider configurations - import from models.payments
19
+ from django_cfg.models.payments import (
20
+ PaymentProviderConfig,
21
+ NowPaymentsConfig,
22
+ StripeConfig,
23
+ CryptAPIConfig
24
+ )
25
+
26
+ # Local provider configs (additional to models.payments)
27
+ from .providers import CryptomusConfig
28
+
29
+ # Configuration module
30
+ from .module import PaymentsCfgModule
31
+
32
+ # Utility functions
33
+ from .utils import (
34
+ get_payments_config,
35
+ get_provider_config,
36
+ is_payments_enabled
37
+ )
38
+
39
+ # Backwards compatibility exports
40
+ payments_config = PaymentsCfgModule()
41
+
42
+ __all__ = [
43
+ # Core settings
44
+ 'PaymentsSettings',
45
+ 'SecuritySettings',
46
+ 'RateLimitSettings',
47
+ 'NotificationSettings',
48
+ 'SubscriptionSettings',
49
+
50
+ # Provider configurations
51
+ 'PaymentProviderConfig',
52
+ 'NowPaymentsConfig',
53
+ 'StripeConfig',
54
+ 'CryptAPIConfig',
55
+ 'CryptomusConfig',
56
+
57
+ # Configuration module
58
+ 'PaymentsCfgModule',
59
+ 'payments_config',
60
+
61
+ # Utility functions
62
+ 'get_payments_config',
63
+ 'get_provider_config',
64
+ 'is_payments_enabled',
65
+ ]
@@ -0,0 +1,70 @@
1
+ """
2
+ Payment configuration module.
3
+
4
+ Handles loading and managing payment configurations from project settings.
5
+ """
6
+
7
+ from typing import Optional
8
+ import logging
9
+
10
+ from django_cfg.modules.base import BaseCfgModule
11
+ from .settings import PaymentsSettings
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+
16
+ class PaymentsCfgModule(BaseCfgModule):
17
+ """Payment configuration module for django-cfg."""
18
+
19
+ def __init__(self):
20
+ super().__init__()
21
+ self.settings_class = PaymentsSettings
22
+ self._settings_cache = None
23
+
24
+ def get_config(self) -> PaymentsSettings:
25
+ """Get payments configuration."""
26
+ if self._settings_cache is None:
27
+ project_config = super().get_config()
28
+ if project_config:
29
+ self._settings_cache = self.load_from_project_config(project_config)
30
+ else:
31
+ self._settings_cache = PaymentsSettings()
32
+ return self._settings_cache
33
+
34
+ def reset_cache(self):
35
+ """Reset configuration cache."""
36
+ self._settings_cache = None
37
+
38
+ def load_from_project_config(self, config) -> PaymentsSettings:
39
+ """Load payments configuration from main project config."""
40
+
41
+ # Load from new PaymentsConfig if available
42
+ if hasattr(config, 'payments') and config.payments:
43
+ # Convert List[PaymentProviderConfig] to Dict[str, PaymentProviderConfig]
44
+ providers = {}
45
+ for provider in config.payments.providers:
46
+ providers[provider.name] = provider
47
+
48
+ return PaymentsSettings(
49
+ enabled=config.payments.enabled,
50
+ debug_mode=getattr(config, 'debug', False),
51
+ providers=providers,
52
+ security=config.payments.security,
53
+ rate_limits=config.payments.rate_limits,
54
+ notifications=config.payments.notifications,
55
+ subscriptions=config.payments.subscriptions,
56
+ enable_crypto_payments=config.payments.enable_crypto_payments,
57
+ enable_fiat_payments=config.payments.enable_fiat_payments,
58
+ enable_subscription_system=config.payments.enable_subscription_system,
59
+ enable_balance_system=config.payments.enable_balance_system,
60
+ enable_api_key_system=config.payments.enable_api_key_system,
61
+ enable_webhook_processing=config.payments.enable_webhook_processing,
62
+ enable_billing_utils=config.payments.enable_billing_utils
63
+ )
64
+ else:
65
+ # Fallback: Return default settings if no PaymentsConfig found
66
+ logger.warning("No PaymentsConfig found, using default settings")
67
+ return PaymentsSettings(
68
+ enabled=False,
69
+ debug_mode=getattr(config, 'debug', False)
70
+ )
@@ -0,0 +1,115 @@
1
+ """
2
+ Payment provider configurations.
3
+
4
+ Defines configuration classes for different payment providers.
5
+ """
6
+
7
+ from typing import Dict, Any, Optional
8
+ from pydantic import BaseModel, Field, SecretStr
9
+
10
+
11
+ class PaymentProviderConfig(BaseModel):
12
+ """Base configuration for payment providers."""
13
+ enabled: bool = True
14
+ sandbox: bool = Field(default=True, description="Use sandbox mode")
15
+ api_key: SecretStr = Field(description="Provider API key")
16
+ timeout: int = Field(default=30, description="Request timeout in seconds")
17
+ max_retries: int = Field(default=3, description="Maximum retry attempts")
18
+
19
+ def get_config_dict(self) -> Dict[str, Any]:
20
+ """Get configuration as dictionary for provider initialization."""
21
+ return {
22
+ 'api_key': self.api_key.get_secret_value(),
23
+ 'sandbox': self.sandbox,
24
+ 'timeout': self.timeout,
25
+ 'max_retries': self.max_retries
26
+ }
27
+
28
+
29
+ class NowPaymentsConfig(PaymentProviderConfig):
30
+ """NowPayments provider configuration."""
31
+ public_key: Optional[SecretStr] = Field(default=None, description="NowPayments public key")
32
+ callback_url: Optional[str] = Field(default=None, description="Webhook callback URL")
33
+ success_url: Optional[str] = Field(default=None, description="Payment success URL")
34
+ cancel_url: Optional[str] = Field(default=None, description="Payment cancel URL")
35
+
36
+ def get_config_dict(self) -> Dict[str, Any]:
37
+ """Get configuration as dictionary for provider initialization."""
38
+ config = super().get_config_dict()
39
+ config.update({
40
+ 'callback_url': self.callback_url,
41
+ 'success_url': self.success_url,
42
+ 'cancel_url': self.cancel_url,
43
+ })
44
+ return config
45
+
46
+
47
+ class StripeConfig(PaymentProviderConfig):
48
+ """Stripe provider configuration."""
49
+ publishable_key: Optional[SecretStr] = Field(default=None, description="Stripe publishable key")
50
+ webhook_secret: Optional[SecretStr] = Field(default=None, description="Stripe webhook secret")
51
+
52
+ def get_config_dict(self) -> Dict[str, Any]:
53
+ """Get configuration as dictionary for provider initialization."""
54
+ config = super().get_config_dict()
55
+ config.update({
56
+ 'publishable_key': self.publishable_key.get_secret_value() if self.publishable_key else None,
57
+ 'webhook_secret': self.webhook_secret.get_secret_value() if self.webhook_secret else None,
58
+ })
59
+ return config
60
+
61
+
62
+ class CryptAPIConfig(PaymentProviderConfig):
63
+ """CryptAPI provider configuration."""
64
+ own_address: str = Field(description="Your crypto address where funds will be sent")
65
+ callback_url: Optional[str] = Field(default=None, description="Webhook callback URL")
66
+ convert_payments: bool = Field(default=True, description="Auto-convert payments to your address currency")
67
+ multi_token: bool = Field(default=True, description="Enable multi-token support")
68
+ priority: str = Field(default='default', description="Transaction priority (default, economic, priority)")
69
+
70
+ def get_config_dict(self) -> Dict[str, Any]:
71
+ """Get configuration as dictionary for provider initialization."""
72
+ config = super().get_config_dict()
73
+ config.update({
74
+ 'own_address': self.own_address,
75
+ 'callback_url': self.callback_url,
76
+ 'convert_payments': self.convert_payments,
77
+ 'multi_token': self.multi_token,
78
+ 'priority': self.priority,
79
+ })
80
+ return config
81
+
82
+
83
+ class CryptomusConfig(PaymentProviderConfig):
84
+ """Cryptomus provider configuration."""
85
+ merchant_uuid: str = Field(description="Cryptomus merchant UUID")
86
+ callback_url: Optional[str] = Field(default=None, description="Webhook callback URL")
87
+ success_url: Optional[str] = Field(default=None, description="Payment success URL")
88
+ fail_url: Optional[str] = Field(default=None, description="Payment fail URL")
89
+ network: Optional[str] = Field(default=None, description="Default network for payments")
90
+
91
+ def get_config_dict(self) -> Dict[str, Any]:
92
+ """Get configuration as dictionary for provider initialization."""
93
+ config = super().get_config_dict()
94
+ config.update({
95
+ 'merchant_uuid': self.merchant_uuid,
96
+ 'callback_url': self.callback_url,
97
+ 'success_url': self.success_url,
98
+ 'fail_url': self.fail_url,
99
+ 'network': self.network,
100
+ })
101
+ return config
102
+
103
+
104
+ # Provider registry for easy access
105
+ PROVIDER_CONFIGS = {
106
+ 'nowpayments': NowPaymentsConfig,
107
+ 'stripe': StripeConfig,
108
+ 'cryptapi': CryptAPIConfig,
109
+ 'cryptomus': CryptomusConfig,
110
+ }
111
+
112
+
113
+ def get_provider_config_class(provider_name: str) -> Optional[type]:
114
+ """Get provider configuration class by name."""
115
+ return PROVIDER_CONFIGS.get(provider_name)
@@ -0,0 +1,96 @@
1
+ """
2
+ Universal payments module settings.
3
+
4
+ Core settings for the payments system - now using unified models from django_cfg.models.payments.
5
+ """
6
+
7
+ from typing import Dict, List
8
+ from pydantic import BaseModel, Field
9
+
10
+ # Import unified types from models/payments.py
11
+ from django_cfg.models.payments import (
12
+ PaymentProviderConfig,
13
+ SecuritySettings,
14
+ RateLimitSettings,
15
+ NotificationSettings,
16
+ SubscriptionSettings
17
+ )
18
+
19
+
20
+ class PaymentsSettings(BaseModel):
21
+ """Universal payments module settings - unified with PaymentsConfig."""
22
+
23
+ # General settings
24
+ enabled: bool = Field(default=True, description="Enable payments module")
25
+ debug_mode: bool = Field(default=False, description="Enable debug mode for payments")
26
+
27
+ # Component settings - using unified models
28
+ security: SecuritySettings = Field(default_factory=SecuritySettings)
29
+ rate_limits: RateLimitSettings = Field(default_factory=RateLimitSettings)
30
+ notifications: NotificationSettings = Field(default_factory=NotificationSettings)
31
+ subscriptions: SubscriptionSettings = Field(default_factory=SubscriptionSettings)
32
+
33
+ # Provider configurations - now accepts List instead of Dict
34
+ providers: Dict[str, PaymentProviderConfig] = Field(
35
+ default_factory=dict,
36
+ description="Payment provider configurations (Dict for backwards compatibility)"
37
+ )
38
+
39
+ # Feature flags - copied from PaymentsConfig for consistency
40
+ enable_crypto_payments: bool = Field(default=True, description="Enable cryptocurrency payments")
41
+ enable_fiat_payments: bool = Field(default=True, description="Enable fiat currency payments")
42
+ enable_subscription_system: bool = Field(default=True, description="Enable subscription system")
43
+ enable_balance_system: bool = Field(default=True, description="Enable user balance system")
44
+ enable_api_key_system: bool = Field(default=True, description="Enable API key system")
45
+ enable_webhook_processing: bool = Field(default=True, description="Enable webhook processing")
46
+ enable_billing_utils: bool = Field(default=True, description="Enable billing utility functions")
47
+
48
+ # Backwards compatibility properties
49
+ @property
50
+ def auto_create_api_keys(self) -> bool:
51
+ """Backwards compatibility for auto_create_api_keys."""
52
+ return self.security.auto_create_api_keys
53
+
54
+ @property
55
+ def require_api_key(self) -> bool:
56
+ """Backwards compatibility for require_api_key."""
57
+ return self.security.require_api_key
58
+
59
+ @property
60
+ def min_balance_threshold(self) -> float:
61
+ """Backwards compatibility for min_balance_threshold."""
62
+ return float(self.security.min_balance_threshold)
63
+
64
+ @property
65
+ def requests_per_hour(self) -> int:
66
+ """Backwards compatibility for requests_per_hour."""
67
+ return self.rate_limits.requests_per_hour
68
+
69
+ @property
70
+ def webhook_timeout(self) -> int:
71
+ """Backwards compatibility for webhook_timeout."""
72
+ return self.notifications.webhook_timeout
73
+
74
+ # Utility methods
75
+ def is_provider_enabled(self, provider_name: str) -> bool:
76
+ """Check if a specific provider is enabled."""
77
+ provider = self.providers.get(provider_name)
78
+ return provider and provider.enabled if provider else False
79
+
80
+ def get_enabled_providers(self) -> List[str]:
81
+ """Get list of enabled provider names."""
82
+ return [name for name, config in self.providers.items() if config.enabled]
83
+
84
+ def get_provider_config(self, provider_name: str) -> PaymentProviderConfig:
85
+ """Get configuration for a specific provider."""
86
+ return self.providers.get(provider_name)
87
+
88
+
89
+ __all__ = [
90
+ 'PaymentsSettings',
91
+ 'SecuritySettings',
92
+ 'RateLimitSettings',
93
+ 'NotificationSettings',
94
+ 'SubscriptionSettings',
95
+ 'PaymentProviderConfig'
96
+ ]
@@ -0,0 +1,52 @@
1
+ """
2
+ Configuration utility functions.
3
+
4
+ Helper functions for working with payment configurations.
5
+ """
6
+
7
+ from typing import Optional
8
+ import logging
9
+
10
+ from .module import PaymentsCfgModule
11
+ from .settings import PaymentsSettings
12
+ from django_cfg.models.payments import PaymentProviderConfig
13
+
14
+ logger = logging.getLogger(__name__)
15
+
16
+ # Global payments configuration instance
17
+ _payments_config = PaymentsCfgModule()
18
+
19
+
20
+ def get_payments_config() -> PaymentsSettings:
21
+ """Get current payments configuration."""
22
+ return _payments_config.get_config()
23
+
24
+
25
+ def get_provider_config(provider_name: str) -> Optional[PaymentProviderConfig]:
26
+ """Get configuration for specific payment provider."""
27
+ config = get_payments_config()
28
+ return config.providers.get(provider_name)
29
+
30
+
31
+ def is_payments_enabled() -> bool:
32
+ """Check if payments module is enabled."""
33
+ try:
34
+ config = get_payments_config()
35
+ return config.enabled
36
+ except Exception as e:
37
+ logger.warning(f"Failed to check payments status: {e}")
38
+ return False
39
+
40
+
41
+ def reset_config_cache():
42
+ """Reset configuration cache."""
43
+ global _payments_config
44
+ _payments_config.reset_cache()
45
+
46
+
47
+ __all__ = [
48
+ 'get_payments_config',
49
+ 'get_provider_config',
50
+ 'is_payments_enabled',
51
+ 'reset_config_cache'
52
+ ]