From 2525916c086b8a83ba3aca2447f7495f9070930a Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Tue, 28 Jul 2026 22:12:12 +0530 Subject: [PATCH] Add diagnostic to inspect raw consent_request response behind generic HTTP 400 error --- check_consent_request_400.php | 94 +++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 check_consent_request_400.php diff --git a/check_consent_request_400.php b/check_consent_request_400.php new file mode 100644 index 0000000..4fe47a6 --- /dev/null +++ b/check_consent_request_400.php @@ -0,0 +1,94 @@ + last 5 consent_request rows + * php83 check_consent_request_400.php -> full dump for one row id + * + * Reads DB credentials from the app's own .env (does not print them). + */ + +$envPath = __DIR__ . '/.env'; +if (! is_file($envPath)) { + fwrite(STDERR, "Could not find .env at {$envPath}\n"); + exit(1); +} + +$lines = file($envPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); +$env = []; +foreach ($lines as $line) { + $line = trim($line); + if ($line === '' || $line[0] === '#' || strpos($line, '=') === false) { + continue; + } + [$k, $v] = explode('=', $line, 2); + $env[trim($k)] = trim($v, " \t\n\r\0\x0B\"'"); +} + +$host = $env['database.default.hostname'] ?? 'localhost'; +$db = $env['database.default.database'] ?? ''; +$user = $env['database.default.username'] ?? ''; +$pass = $env['database.default.password'] ?? ''; +$port = (int) ($env['database.default.port'] ?? 3306); + +if ($db === '' || $user === '') { + fwrite(STDERR, "Could not resolve DB credentials from .env (looked for database.default.* keys)\n"); + exit(1); +} + +$mysqli = @new mysqli($host, $user, $pass, $db, $port ?: 3306); +if ($mysqli->connect_errno) { + fwrite(STDERR, "DB connect failed: " . $mysqli->connect_error . "\n"); + exit(1); +} + +echo "Connected to DB '{$db}' on {$host}.\n\n"; + +$id = (int) ($argv[1] ?? 0); + +if ($id > 0) { + $stmt = $mysqli->prepare("SELECT id, operation, workflow_state, status, http_code, is_retryable, + consent_id, abha_address, transaction_id, last_error, created_at, + request_json, response_json + FROM abdm_hiu_workflows WHERE id = ?"); + $stmt->bind_param('i', $id); + $stmt->execute(); + $row = $stmt->get_result()->fetch_assoc(); + if (! $row) { + echo "No row found for id={$id}\n"; + exit(0); + } + foreach (['id', 'operation', 'workflow_state', 'status', 'http_code', 'is_retryable', 'consent_id', 'abha_address', 'transaction_id', 'last_error', 'created_at'] as $col) { + echo str_pad($col, 16) . ": " . ($row[$col] ?? '') . "\n"; + } + echo "\n--- request_json ---\n"; + $reqDecoded = json_decode((string) $row['request_json'], true); + echo $reqDecoded !== null ? json_encode($reqDecoded, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) : (string) $row['request_json']; + echo "\n\n--- response_json ---\n"; + $respDecoded = json_decode((string) $row['response_json'], true); + echo $respDecoded !== null ? json_encode($respDecoded, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) : (string) $row['response_json']; + echo "\n"; + exit(0); +} + +$res = $mysqli->query("SELECT id, operation, workflow_state, status, http_code, is_retryable, + consent_id, abha_address, transaction_id, last_error, created_at + FROM abdm_hiu_workflows + WHERE operation = 'consent_request' + ORDER BY id DESC LIMIT 5"); +if (! $res) { + fwrite(STDERR, "Query failed: " . $mysqli->error . "\n"); + exit(1); +} + +echo "Last 5 'consent_request' workflow rows:\n"; +while ($row = $res->fetch_assoc()) { + echo "----\n"; + foreach (['id', 'operation', 'workflow_state', 'status', 'http_code', 'is_retryable', 'consent_id', 'abha_address', 'transaction_id', 'last_error', 'created_at'] as $col) { + echo str_pad($col, 16) . ": " . ($row[$col] ?? '') . "\n"; + } +} +echo "\nRun 'php83 check_consent_request_400.php ' on one of the above ids to see the full raw request/response JSON.\n";