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:
2026-02-01 12:31:42 -05:00
parent 449eb74279
commit 97261f6c51
13 changed files with 335 additions and 428 deletions

28
app/utils.py Normal file
View 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]