<?php
require_once '../config.php';
require_once '../functions.php';

echo "<h1>Debug Balance API (GET Request)</h1>";

echo "<h2>API Configuration:</h2>";
echo "URL: " . SMS_BALANCE_URL . "<br>";
echo "API KEY (Config): " . SMS_API_KEY . "<br>";

echo "<h2>Calling get_balance():</h2>";
$response = get_balance();

echo "<h3>Refined Response (from function):</h3>";
var_dump($response);

echo "<h2>Raw Curl Check:</h2>";
$url = "http://bulksmsbd.net/api/getBalanceApi?api_key=" . SMS_API_KEY;
echo "Requesting: $url <br>";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPGET, true);
$raw_response = curl_exec($ch);
curl_close($ch);

echo "<h3>Raw Response Content:</h3>";
echo "<pre>" . htmlspecialchars($raw_response) . "</pre>";

echo "<h3>JSON Decode Check:</h3>";
$json = json_decode($raw_response, true);
if (json_last_error() === JSON_ERROR_NONE) {
    echo "Is Valid JSON. Content:<br>";
    echo "<pre>" . print_r($json, true) . "</pre>";
} else {
    echo "Not JSON. Raw string.";
}
?>