#!/usr/bin/env python3 """ Payment Processing Script (New Architecture) This script provides backward-compatible CLI for the refactored payment processing system. It maintains the same command-line interface as the original query_mysql.py while using the new modular architecture under the hood. Usage: python query_mysql.py [mode] [live] Modes: batch, payintent, payplan, refund The new architecture provides: - Separation of concerns with dedicated modules - Thread-safe database operations - Improved error handling and logging - Better testability and maintainability """ import sys import logging from config import Config from app import create_app from orchestration import PaymentOrchestrator # Configure logging logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', handlers=[ logging.FileHandler('payment_processing.log'), logging.StreamHandler(sys.stdout) ] ) logger = logging.getLogger(__name__) def main(): """ Main entry point - maintains backward compatibility with original CLI. """ # Parse command-line arguments (original format) running_mode = "payintent" # Default mode process_live = False try: if len(sys.argv) > 1: mode_arg = sys.argv[1].lower() if mode_arg in ["batch", "payintent", "payplan", "refund"]: running_mode = mode_arg else: logger.error(f"Invalid running mode: {sys.argv[1]}") logger.info("Valid modes: batch, payintent, payplan, refund") sys.exit(1) if len(sys.argv) > 2: if sys.argv[2].lower() == "live": process_live = True else: logger.warning(f"Unknown environment argument: {sys.argv[2]}. Using test mode.") except IndexError: logger.info("No running mode specified, defaulting to 'payintent'") # Log execution details env_display = "LIVE" if process_live else "SANDBOX" logger.info("=" * 80) logger.info(f"Payment Processing System (Refactored)") logger.info(f"Mode: {running_mode.upper()} - Environment: {env_display}") logger.info("=" * 80) try: # Create Flask application app = create_app() # Create and run orchestrator orchestrator = PaymentOrchestrator( app=app, config=Config, process_live=process_live ) result = orchestrator.run(running_mode) # Log results if result.get('success'): logger.info("=" * 80) logger.info("SUCCESS: Processing completed successfully") logger.info("=" * 80) sys.exit(0) else: logger.error("=" * 80) logger.error(f"FAILED: Processing failed: {result.get('error', 'Unknown error')}") logger.error("=" * 80) sys.exit(1) except KeyboardInterrupt: logger.warning("\n\nWARNING: Processing interrupted by user") sys.exit(130) except Exception as e: logger.error(f"Fatal error: {e}", exc_info=True) sys.exit(1) if __name__ == "__main__": main()