#!/usr/bin/env elixir import Bitwise # Test script for Mercury ISO8583 implementation Code.require_file("lib/da_product_app.ex") Code.require_file("lib/da_product_app/mercury_iso8583/utils.ex") Code.require_file("lib/da_product_app/mercury_iso8583/formats.ex") Code.require_file("lib/da_product_app/mercury_iso8583/message.ex") Code.require_file("lib/da_product_app/mercury_iso8583/mti.ex") Code.require_file("lib/da_product_app/mercury_iso8583/bitmap.ex") Code.require_file("lib/da_product_app/mercury_iso8583/data_types.ex") Code.require_file("lib/da_product_app/mercury_iso8583/decoder.ex") Code.require_file("lib/da_product_app/mercury_iso8583/encoder.ex") Code.require_file("lib/da_product_app/mercury_iso8583.ex") alias DaProductApp.MercuryISO8583 # Test sample Mercury message (similar to what we were debugging) sample_data = <<0x60, 0x00, 0x78, 0x20, 0x00, # TPDU 0x01, 0x00, # MTI: 0100 (BCD encoded) 0x70, 0x20, 0x05, 0x82, 0x80, 0x00, 0x00, 0x00, # Primary bitmap "000000000100", # Field 2: PAN (12 digits) "000001", # Field 3: Processing code "000000000000">> # Field 4: Amount IO.puts("Testing Mercury ISO8583 implementation...") IO.puts("Sample data: #{Base.encode16(sample_data)}") # Test decode case MercuryISO8583.decode(sample_data) do {:ok, message} -> IO.puts("Successfully decoded message!") IO.inspect(message, label: "Decoded Message") # Test getting specific fields mti = MercuryISO8583.get(message, "0") pan = MercuryISO8583.get(message, "2") proc_code = MercuryISO8583.get(message, "3") amount = MercuryISO8583.get(message, "4") IO.puts("MTI: #{mti}") IO.puts("PAN: #{pan}") IO.puts("Processing Code: #{proc_code}") IO.puts("Amount: #{amount}") # Test encode back case MercuryISO8583.encode(message) do {:ok, encoded} -> IO.puts("Successfully encoded back!") IO.puts("Original: #{Base.encode16(sample_data)}") IO.puts("Encoded: #{Base.encode16(encoded)}") if sample_data == encoded do IO.puts("✅ Perfect round-trip!") else IO.puts("⚠️ Round-trip mismatch - this might be expected due to field formatting") end {:error, reason} -> IO.puts("❌ Encode failed: #{inspect(reason)}") end {:error, reason} -> IO.puts("❌ Decode failed: #{inspect(reason)}") end # Test creating a new message IO.puts("\nTesting message creation...") new_message = MercuryISO8583.new("0200") new_message = MercuryISO8583.set(new_message, "2", "4111111111111111") new_message = MercuryISO8583.set(new_message, "3", "000000") new_message = MercuryISO8583.set(new_message, "4", "000000001000") case MercuryISO8583.encode(new_message) do {:ok, encoded} -> IO.puts("✅ Successfully created and encoded new message!") IO.puts("New message: #{Base.encode16(encoded)}") {:error, reason} -> IO.puts("❌ New message encode failed: #{inspect(reason)}") end IO.puts("\nTest completed!")