<?php

header("Content-Type: application/json; charset=UTF-8");
include 'config.php';

if (!isset($_POST['trx'])) {
    echo json_encode([
        "success" => false,
        "message" => "trx parameter missing",
        "data" => []
    ]);
    exit;
}

$trx = $_POST['trx'];

// ✅ Correct column name: trnxid
$stmt = $conn->prepare("SELECT * FROM ShuvoPays WHERE trnxid = ?");
$stmt->bind_param("s", $trx);
$stmt->execute();
$result = $stmt->get_result();

if ($result->num_rows > 0) {

    // Multiple rows possible → array বানাই
    $rows = [];
    while ($row = $result->fetch_assoc()) {
        $rows[] = $row;
    }

    echo json_encode([
        "success" => true,
        "message" => "Transaction history found",
        "data" => $rows   // IMPORTANT → ArrayList
    ]);

} else {
    echo json_encode([
        "success" => false,
        "message" => "No transaction found",
        "data" => []   // Empty array for safe parsing
    ]);
}

$stmt->close();
$conn->close();
?>