Refactor payment service, fix DB session, and consolidate endpoints
- Fix critical NameError in database.py by restoring Session factory - Refactor payment_service.py and crud.py to use shared constants.py and utils.py - Deduplicate state mapping and input sanitization logic - Move transaction amount calculation logic from CRUD to Router layer - Enforce type safety in schemas using IntEnum for TransactionType/Status - Move capture endpoint from transaction.py to payment.py (now /payments/capture) - Update create_customer_profile signature for clarity
This commit is contained in:
47
config.py
47
config.py
@@ -1,24 +1,55 @@
|
||||
import os
|
||||
|
||||
def load_config(mode=os.environ.get('MODE')):
|
||||
# Authorize.net Configuration
|
||||
from authorizenet.constants import constants
|
||||
|
||||
def load_config(mode=os.environ.get('MODE')):
|
||||
"""
|
||||
Load the application configuration based on the environment mode.
|
||||
Sets up Authorize.net environment variables on the config object.
|
||||
"""
|
||||
config_class = None
|
||||
|
||||
try:
|
||||
if mode == 'PRODUCTION':
|
||||
from settings_prod import ApplicationConfig
|
||||
return ApplicationConfig
|
||||
config_class = ApplicationConfig
|
||||
|
||||
elif mode == 'LOCAL':
|
||||
from settings_local import ApplicationConfig
|
||||
return ApplicationConfig
|
||||
config_class = ApplicationConfig
|
||||
|
||||
elif mode == 'DEVELOPMENT':
|
||||
|
||||
from settings_dev import ApplicationConfig
|
||||
return ApplicationConfig
|
||||
config_class = ApplicationConfig
|
||||
else:
|
||||
pass
|
||||
# Default to dev if unknown mode
|
||||
from settings_dev import ApplicationConfig
|
||||
config_class = ApplicationConfig
|
||||
|
||||
except ImportError:
|
||||
|
||||
# Fallback
|
||||
from settings_dev import ApplicationConfig
|
||||
return ApplicationConfig
|
||||
config_class = ApplicationConfig
|
||||
|
||||
# Set Authorize.net specific settings on the config class
|
||||
if config_class.CURRENT_SETTINGS == 'PRODUCTION':
|
||||
config_class.ENVIRONMENT = constants.PRODUCTION
|
||||
config_class.VALIDATION_MODE = "liveMode"
|
||||
elif config_class.CURRENT_SETTINGS == 'LOCAL':
|
||||
config_class.ENVIRONMENT = constants.PRODUCTION
|
||||
config_class.VALIDATION_MODE = "liveMode"
|
||||
else:
|
||||
config_class.ENVIRONMENT = constants.SANDBOX
|
||||
config_class.VALIDATION_MODE = "testMode"
|
||||
|
||||
return config_class
|
||||
|
||||
# Load the configuration once
|
||||
ApplicationConfig = load_config()
|
||||
|
||||
# Export variables for compatibility with imports in other files
|
||||
ENVIRONMENT = ApplicationConfig.ENVIRONMENT
|
||||
VALIDATION_MODE = ApplicationConfig.VALIDATION_MODE
|
||||
API_LOGIN_ID = ApplicationConfig.API_LOGIN_ID
|
||||
TRANSACTION_KEY = ApplicationConfig.TRANSACTION_KEY
|
||||
|
||||
Reference in New Issue
Block a user