#!/usr/bin/env elixir # Test the IFB_AMOUNT fix Code.prepend_path("lib") require Logger Logger.configure(level: :debug) alias DaProductApp.MercuryISO8583.Packagers.FieldPackagers.IFB_AMOUNT alias DaProductApp.MercuryISO8583.Packagers.ISO87BPackager IO.puts("=== Testing IFB_AMOUNT Fix ===") # Test 1: Create IFB_AMOUNT packager and verify it has all required fields IO.puts("\n1. Testing IFB_AMOUNT struct creation:") packager = IFB_AMOUNT.new(9, "Settlement Processing Fee", false) IO.puts("IFB_AMOUNT struct: #{inspect(packager)}") IO.puts("Has padder field: #{Map.has_key?(packager, :padder)}") IO.puts("Padder value: #{inspect(packager.padder)}") # Test 2: Check ISO87B packager field definition IO.puts("\n2. Testing ISO87B field packager:") field_packager = ISO87BPackager.get_field_packager(30) # Settlement Processing Fee IO.puts("Field 30 packager: #{inspect(field_packager)}") if field_packager do IO.puts("Field 30 has padder: #{Map.has_key?(field_packager, :padder)}") IO.puts("Field 30 padder: #{inspect(Map.get(field_packager, :padder))}") end # Test 3: Test packing and unpacking IO.puts("\n3. Testing pack/unpack operations:") test_value = "C000012345" # Credit amount 123.45 try do case IFB_AMOUNT.pack_with_packager(test_value, packager) do {:ok, packed} -> IO.puts("✅ Pack successful: #{Base.encode16(packed)}") # Test unpack case IFB_AMOUNT.unpack_with_packager(nil, packed, 0, packager) do {:ok, {component, _offset}} -> unpacked_value = Map.get(component, :value) IO.puts("✅ Unpack successful: #{inspect(unpacked_value)}") IO.puts("Values match: #{test_value == unpacked_value}") {:error, reason} -> IO.puts("❌ Unpack failed: #{reason}") end {:error, reason} -> IO.puts("❌ Pack failed: #{reason}") end rescue e -> IO.puts("❌ Exception: #{Exception.message(e)}") end IO.puts("\n4. Testing with actual ISO message unpacking:") # Create a sample binary that would trigger the error # This simulates the binary data that was causing the original error sample_hex = "30000000000000000000" # Sample field data sample_binary = Base.decode16!(sample_hex) try do case IFB_AMOUNT.unpack_with_packager(%{}, sample_binary, 0, packager) do {:ok, {component, offset}} -> IO.puts("✅ Binary unpack successful: #{inspect(component)} at offset #{offset}") {:error, reason} -> IO.puts("❌ Binary unpack failed: #{reason}") end rescue e -> IO.puts("❌ Exception during binary unpack: #{Exception.message(e)}") end IO.puts("\n=== Test completed ===")