<?php
// File: customer/get_metode_aktif.php
header('Content-Type: application/json');
include '../config/koneksi.php';

if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    // Hanya ambil metode yang aktif dan belum dihapus
    $query = "SELECT metode_id, nama_metode, tipe_metode, qris_gambar FROM mst_metode_bayar WHERE active_st = 1 AND deleted_st = 0 ORDER BY metode_id ASC";
    $result = $conn->query($query);
    
    $data = [];
    if ($result && $result->num_rows > 0) {
        while ($row = $result->fetch_assoc()) {
            if (!empty($row['qris_gambar'])) {
                $base_url = "http://" . $_SERVER['HTTP_HOST'] . "/api_koneksi/uploads/qris/";
                $row['qris_gambar_url'] = $base_url . $row['qris_gambar'];
            } else {
                $row['qris_gambar_url'] = "";
            }
            $data[] = $row;
        }
        echo json_encode(["status" => "sukses", "pesan" => "Data metode ditemukan", "data" => $data]);
    } else {
        echo json_encode(["status" => "kosong", "pesan" => "Belum ada metode pembayaran yang aktif", "data" => []]);
    }
} else {
    echo json_encode(["status" => "gagal", "pesan" => "Metode request tidak valid"]);
}

$conn->close();
?>
