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:
28
app/utils.py
Normal file
28
app/utils.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""
|
||||
Utility functions shared across the EAMCO Authorize service.
|
||||
"""
|
||||
import re
|
||||
|
||||
def sanitize_input(text, max_len, allow_spaces=False, is_zip=False):
|
||||
"""
|
||||
Sanitize input string by removing invalid characters.
|
||||
|
||||
Args:
|
||||
text: Input text/number/value
|
||||
max_len: Maximum length of the output string
|
||||
allow_spaces: If True, allows spaces in the output
|
||||
is_zip: If True, allows hyphens (for ZIP+4)
|
||||
|
||||
Returns:
|
||||
Sanitized string truncated to max_len
|
||||
"""
|
||||
if not text:
|
||||
return ""
|
||||
|
||||
if is_zip:
|
||||
pattern = r'[^a-zA-Z0-9-]'
|
||||
else:
|
||||
pattern = r'[^a-zA-Z0-9]' if not allow_spaces else r'[^a-zA-Z0-9\s]'
|
||||
|
||||
sanitized = re.sub(pattern, '', str(text))
|
||||
return sanitized.strip()[:max_len]
|
||||
Reference in New Issue
Block a user