Files
eamco_authorize/app/utils.py
Edwin Eames 97261f6c51 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
2026-02-01 12:31:42 -05:00

29 lines
780 B
Python

"""
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]