<?php
header("Content-Type: application/json");

// Beem Africa API details
$api_key     = "106de5fd0d63b2de";
$secret_key  = "NDY1NGE3NjZjYTgzZmE5MTFkOThkODg1MDZjMmE1NTVmOTc2OGJlMzc1MDRmYjNlMDkxODE1MWFiM2JkY2FlNg==";
$sender_name = "Bexa Mikopo";

$url = "https://apisms.beem.africa/public/v1/vendors/balance";
$headers = [
    "Content-Type: application/json",
    "Authorization: Basic " . base64_encode("$api_key:$secret_key"),
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($httpCode == 200) {
    echo json_encode(["status" => "success", "balance" => json_decode($response, true)]);
} else {
    echo json_encode(["status" => "error", "message" => "Failed to fetch SMS balance"]);
}
?>
