#!/usr/bin/env elixir # Phase 1 Integration Validation Script # Tests the TransactionProcessor integration with IncomingMessageProcessor Mix.install([]) IO.puts("πŸ”§ Phase 1 Integration Layer Enhancement - Validation") IO.puts("=" <> String.duplicate("=", 60)) # Test 1: Check IncomingMessageProcessor YSP Integration IO.puts("\nπŸ“‹ Test 1: IncomingMessageProcessor YSP Integration") incoming_processor_file = "lib/da_product_app/switch/incoming_message_processor.ex" content = File.read!(incoming_processor_file) tests = [ { "MTI-based routing implemented", Regex.match?(~r/case mti do.*"0200".*TransactionProcessor\.process_sale/s, content) }, { "Reversal routing implemented", Regex.match?(~r/"0400".*TransactionProcessor\.process_reversal/s, content) }, { "Channel context passing", Regex.match?(~r/process_sale\(iso_message, channel_context\)/, content) }, { "Transaction trace ID support", Regex.match?(~r/transaction_trace_id/, content) }, { "YSP transaction detection", Regex.match?(~r/is_ysp_transaction\?/, content) } ] Enum.each(tests, fn {test_name, result} -> status = if result, do: "βœ…", else: "❌" IO.puts(" #{status} #{test_name}") end) # Test 2: Check TransactionProcessor Context Handling IO.puts("\nπŸ”„ Test 2: TransactionProcessor Context Integration") transaction_processor_file = "lib/da_product_app/acquirer/ysp/transaction_processor.ex" txn_content = File.read!(transaction_processor_file) txn_tests = [ { "Context parameter in process_sale", Regex.match?(~r/def process_sale.*context.*%{}/, txn_content) }, { "Context parameter in process_reversal", Regex.match?(~r/def process_reversal.*context.*%{}/, txn_content) }, { "Transaction trace ID extraction", Regex.match?(~r/trace_id.*Map\.get.*transaction_trace_id/, txn_content) }, { "Enhanced logging with trace ID", Regex.match?(~r/trace:.*trace_id/, txn_content) } ] Enum.each(txn_tests, fn {test_name, result} -> status = if result, do: "βœ…", else: "❌" IO.puts(" #{status} #{test_name}") end) # Test 3: Integration Flow Validation IO.puts("\n🌊 Test 3: Integration Flow Validation") flow_tests = [ { "YSP message detection β†’ TransactionProcessor routing", Regex.match?(~r/case DaProductApp\.YSP\.MessageProcessor\.validate_ysp_message.*case mti do.*"0200".*TransactionProcessor/s, content) }, { "Success response handling", Regex.match?(~r/{:ok, switch_response, final_txn}/, content) }, { "Error response handling", Regex.match?(~r/{:error, {:ysp_sale_failed, reason}}/, content) }, { "Fallback to MessageProcessor for other MTIs", Regex.match?(~r/_ ->.*DaProductApp\.YSP\.MessageProcessor\.process_message/s, content) } ] Enum.each(flow_tests, fn {test_name, result} -> status = if result, do: "βœ…", else: "❌" IO.puts(" #{status} #{test_name}") end) # Summary IO.puts("\nπŸ“Š Phase 1 Integration Summary") IO.puts("-" <> String.duplicate("-", 40)) all_tests = tests ++ txn_tests ++ flow_tests passed_tests = Enum.count(all_tests, fn {_, result} -> result end) total_tests = length(all_tests) IO.puts("βœ… Passed: #{passed_tests}/#{total_tests} tests") if passed_tests == total_tests do IO.puts("πŸŽ‰ Phase 1 Integration: COMPLETE") IO.puts(" β€’ TransactionProcessor integrated with IncomingMessageProcessor") IO.puts(" β€’ MTI-based routing implemented (0200β†’sale, 0400β†’reversal)") IO.puts(" β€’ Transaction context tracking enabled") IO.puts(" β€’ Enhanced error handling with trace IDs") IO.puts(" β€’ Backward compatibility maintained for other MTIs") else IO.puts("⚠️ Phase 1 Integration: INCOMPLETE") IO.puts(" Missing #{total_tests - passed_tests} integration components") end # Next Steps IO.puts("\nπŸš€ Next Steps:") IO.puts(" 1. βœ… Phase 1: Transaction Flow Integration (COMPLETED)") IO.puts(" 2. πŸ”„ Phase 2: Async Correlation Integration") IO.puts(" 3. ⏰ Phase 3: Automatic Reversal System") IO.puts(" 4. πŸ’Ύ Phase 4: Database Lifecycle Completion") IO.puts("\n" <> String.duplicate("=", 70))