#!/usr/bin/env elixir # Test script to verify YSP custom framing integration # Load the configuration and modules Mix.install([]) Code.eval_file("config/config.exs") Code.eval_file("config/upstream_networks.exs") # Required aliases alias DaProductApp.Switch.MessageFraming alias DaProductApp.Acquirer.YSP.YspMessageFraming IO.puts("๐Ÿงช Testing YSP Custom Framing Integration") IO.puts("=" <> String.duplicate("-", 50)) # Test 1: Verify YSP network configuration IO.puts("\n1๏ธโƒฃ Testing YSP Network Configuration...") upstream_networks = Application.get_env(:da_product_app, :upstream_networks, %{}) # Check ysp_plain configuration ysp_plain_config = Map.get(upstream_networks, :ysp_plain) if ysp_plain_config do network_name = Map.get(ysp_plain_config, :network_name, "unknown") message_framing = Map.get(ysp_plain_config, :message_framing) IO.puts("โœ… YSP Plain config found:") IO.puts(" Network name: #{network_name}") IO.puts(" Framing type: #{inspect(Map.get(message_framing, :type))}") IO.puts(" Custom framer: #{inspect(Map.get(message_framing, :custom_framer))}") IO.puts(" Custom unframer: #{inspect(Map.get(message_framing, :custom_unframer))}") else IO.puts("โŒ YSP Plain config not found") end # Test 2: Test YSP message framing directly IO.puts("\n2๏ธโƒฃ Testing YSP Message Framing...") # Sample ISO8583 data (simulated) sample_iso_data = <<0x02, 0x00, 0x70, 0x3c, 0x27, 0x80, 0x28, 0xc0, 0x82, 0x04, 0x16, 0x40, 0x59, 0x88, 0x06, 0x01, 0x60, 0x28, 0x05, 0x00>> # Test framing case YspMessageFraming.frame_message(sample_iso_data, %{}) do {:ok, framed_data} -> IO.puts("โœ… YSP Framing successful:") IO.puts(" Original data: #{byte_size(sample_iso_data)} bytes") IO.puts(" Framed data: #{byte_size(framed_data)} bytes") IO.puts(" Framed hex: #{Base.encode16(framed_data) |> String.slice(0, 40)}...") # Test unframing case YspMessageFraming.unframe_message(framed_data, %{}) do {:ok, {unframed_data, remaining}} -> IO.puts("โœ… YSP Unframing successful:") IO.puts(" Unframed data matches: #{unframed_data == sample_iso_data}") IO.puts(" Remaining bytes: #{byte_size(remaining)}") {:error, reason} -> IO.puts("โŒ YSP Unframing failed: #{inspect(reason)}") end {:error, reason} -> IO.puts("โŒ YSP Framing failed: #{inspect(reason)}") end # Test 3: Test integration with generic MessageFraming IO.puts("\n3๏ธโƒฃ Testing MessageFraming Integration...") framing_config = %{ type: :custom, custom_framer: {DaProductApp.Acquirer.YSP.YspMessageFraming, :frame_message}, custom_unframer: {DaProductApp.Acquirer.YSP.YspMessageFraming, :unframe_message} } case MessageFraming.frame_message(sample_iso_data, framing_config) do {:ok, framed_data} -> IO.puts("โœ… Generic MessageFraming with YSP custom framer successful:") IO.puts(" Framed data: #{byte_size(framed_data)} bytes") case MessageFraming.unframe_message(framed_data, framing_config) do {:ok, {unframed_data, remaining}} -> IO.puts("โœ… Generic MessageFraming with YSP custom unframer successful:") IO.puts(" Data matches: #{unframed_data == sample_iso_data}") {:error, reason} -> IO.puts("โŒ Generic MessageFraming unframing failed: #{inspect(reason)}") end {:error, reason} -> IO.puts("โŒ Generic MessageFraming framing failed: #{inspect(reason)}") end IO.puts("\nโœ… YSP Custom Framing Integration Test Complete!") IO.puts("\n๐Ÿ“‹ Summary:") IO.puts(" โ€ข YSP networks configured to use custom framing") IO.puts(" โ€ข YspMessageFraming compatible with MessageFraming interface") IO.puts(" โ€ข Packet structure: Length(2) + ADR+CB(3022) + TPDU + ISO8583") IO.puts(" โ€ข Integration ready for event-driven transaction processing")