<?php
// Path to the orders.json file
$ordersFilePath = __DIR__ . '/../database/webhook.json';

// Check if the file exists
if (!file_exists($ordersFilePath)) {
    // Return error message as JSON if the file doesn't exist
    header('Content-Type: application/json');
    echo json_encode(['error' => 'File not found']);
    exit;
}

// Read the contents of the orders.json file
$jsonData = file_get_contents($ordersFilePath);

// Decode the JSON data into an associative array
$data = json_decode($jsonData, true);

// Check for JSON decoding errors
if ($data === null) {
    // Return error message if JSON decoding fails
    header('Content-Type: application/json');
    echo json_encode(['error' => 'Failed to decode JSON']);
    exit;
}

// Set the correct content type for the response
header('Content-Type: application/json');

// Return the data as JSON
echo json_encode($data, JSON_PRETTY_PRINT);
?>