<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// Set API URL and your API Key
$api_url = "http://api.navasan.tech/latest/?api_key=freeH5tgsXNSnISRKBMELZW5DZytUkzu"; // Replace with your actual API key

// Initialize cURL session
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // For testing only, bypass SSL verification if needed

// Execute the API request
$response = curl_exec($ch);

// Check for cURL errors
if (curl_errno($ch)) {
    echo 'Error in cURL request: ' . curl_error($ch);
    curl_close($ch);
    exit;
}

curl_close($ch);

// Display the raw response for debugging
//echo "Raw API Response: ";
//var_dump($response);

// Attempt to decode JSON response
$data = json_decode($response, true);

// Check JSON error (if decoding fails)
if (json_last_error() !== JSON_ERROR_NONE) {
    echo "JSON decode error: " . json_last_error_msg();
    exit;
}

// Display the price if available
if (isset($data['usd_sell']['value'])) { // Adjust the key based on the actual response format
    $usd_price = $data['usd_sell']['value'] + 2000; // Add 2000 to the original price
    echo $usd_price; // Output the modified price
} else {
    echo "Failed to retrieve price data. Full response: ";
    var_dump($data);
}
?>
