#!/usr/bin/env elixir # Terminal Database Debug Script # Checks if the terminal exists in the database Mix.install([ {:myxql, "~> 0.6.0"} ]) # Connect to database {:ok, conn} = MyXQL.start_link([ hostname: "localhost", username: "root", password: "", database: "mercury_middlelayer" ]) IO.puts("šŸ” Checking Terminal Database Records") IO.puts("=" <> String.duplicate("=", 50)) # Check acquirer_terminal table {:ok, result} = MyXQL.query(conn, "SELECT COUNT(*) as count FROM acquirer_terminal") terminal_count = result.rows |> List.first() |> List.first() IO.puts("Total terminals in database: #{terminal_count}") if terminal_count > 0 do # Show existing terminals {:ok, result} = MyXQL.query(conn, "SELECT id, tid, mid, status FROM acquirer_terminal LIMIT 5") IO.puts("\nExisting terminals:") IO.puts("ID | TID | MID | Status") IO.puts("-" <> String.duplicate("-", 30)) Enum.each(result.rows, fn [id, tid, mid, status] -> IO.puts("#{id} | #{tid} | #{mid} | #{status}") end) else IO.puts("āŒ No terminals found in database!") IO.puts("Need to create a terminal record for testing.") end # Check for specific terminal from the transaction {:ok, result} = MyXQL.query(conn, "SELECT * FROM acquirer_terminal WHERE tid = ? AND mid = ?", ["12345673", "123456789012345"] ) IO.puts("\nLooking for terminal TID=12345673, MID=123456789012345:") if length(result.rows) > 0 do IO.puts("āœ… Terminal found!") [row] = result.rows IO.inspect(row, label: "Terminal data") else IO.puts("āŒ Terminal NOT found!") IO.puts("This is why the transaction is failing.") end MyXQL.stop(conn) IO.puts("\nšŸ”§ Solution:") IO.puts("1. Create a terminal record in the database") IO.puts("2. Or update the test transaction to use an existing terminal ID")