#!/usr/bin/env elixir # Test script to verify the Ecto.CastError fix # This simulates the transaction creation with proper atom keys Mix.install([ {:jason, "~> 1.4"}, {:decimal, "~> 2.0"} ]) defmodule TestTransactionParams do @moduledoc """ Test the parameter structure to ensure no mixed keys """ def test_temp_transaction_params do IO.puts("๐Ÿงช Testing temp transaction parameter structure...") # Simulate the parameters that would be created by the fixed function temp_txn_params = %{ s_tid: "12345671", s_mid: "123456789012345", s_tid_stan: "000075", total_amount: Decimal.new(6800), b_tid_date: "0917", b_tid_time: "145824", currency_code: "840", acquirer_id: 1, status: "PENDING", mti: "0200", proc_code: "000000", entry_mode: "021", condition_code: "00", encrypted_track2: "4854980600736740=31052060011790", metadata: Jason.encode!(%{ "2" => "4854980600736740", "3" => "000000", "4" => "000000006800", "11" => "000075", "41" => "12345671", "42" => "123456789012345" }), created_by: "YSP_EVENT_LISTENER", updated_by: "YSP_EVENT_LISTENER" } IO.puts("โœ… Parameters structure:") IO.inspect(temp_txn_params, pretty: true, limit: :infinity) # Check that all keys are atoms all_atoms = Enum.all?(temp_txn_params, fn {key, _value} -> is_atom(key) end) if all_atoms do IO.puts("โœ… SUCCESS: All keys are atoms - no mixed key issue") else IO.puts("โŒ ERROR: Found non-atom keys") Enum.each(temp_txn_params, fn {key, _value} -> if not is_atom(key) do IO.puts(" - Non-atom key: #{inspect(key)} (#{typeof(key)})") end end) end # Simulate what happens when Acquirer.create_temp_transaction adds timestamps IO.puts("\n๐Ÿงช Testing with timestamp merge (simulating Acquirer.create_temp_transaction)...") now = DateTime.utc_now() merged_params = Map.merge(temp_txn_params, %{created_dateTime: now, updated_dateTime: now}) IO.puts("โœ… Merged parameters with timestamps:") IO.inspect(Map.take(merged_params, [:s_tid, :total_amount, :created_dateTime, :updated_dateTime]), pretty: true) # Check final structure all_atoms_final = Enum.all?(merged_params, fn {key, _value} -> is_atom(key) end) if all_atoms_final do IO.puts("โœ… SUCCESS: Final parameters have consistent atom keys") IO.puts("โœ… This should NOT cause Ecto.CastError anymore") else IO.puts("โŒ ERROR: Mixed keys found in final parameters") end merged_params end defp typeof(value) do cond do is_atom(value) -> :atom is_binary(value) -> :string is_integer(value) -> :integer is_list(value) -> :list is_map(value) -> :map true -> :other end end end # Run the test TestTransactionParams.test_temp_transaction_params() IO.puts("\n๐ŸŽ‰ Test completed - The Ecto.CastError should be resolved!")