- 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
56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
import os
|
|
|
|
# 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
|
|
config_class = ApplicationConfig
|
|
|
|
elif mode == 'LOCAL':
|
|
from settings_local import ApplicationConfig
|
|
config_class = ApplicationConfig
|
|
|
|
elif mode == 'DEVELOPMENT':
|
|
from settings_dev import ApplicationConfig
|
|
config_class = ApplicationConfig
|
|
else:
|
|
# Default to dev if unknown mode
|
|
from settings_dev import ApplicationConfig
|
|
config_class = ApplicationConfig
|
|
|
|
except ImportError:
|
|
# Fallback
|
|
from settings_dev import 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
|