<?php
$id = $_REQUEST['baselinker_details'];
brecho($id);

$baselinker_config = loadConfiguration();
$order = getOrder($baselinker_config['token'], $id);
brecho($order);
function loadConfiguration()
{
    global $db;
    $dbRes = $db->query("SELECT * FROM config WHERE category='baselinker'");
    $config = [];
    while ($row = $db->fetchByAssoc($dbRes)) {
        $config[$row['name']] = $row['value'];
    }
    return $config;
}
function getOrder($token, $orderId)
{
    $methodParams = '{
        "order_id": ' . $orderId . '
    }';
    $apiParams = [
        "method" => "getOrders",
        "parameters" => $methodParams
    ];

    $curl = curl_init("https://api.baselinker.com/connector.php");
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_HTTPHEADER, ["X-BLToken: " . $token]);
    curl_setopt($curl, CURLOPT_VERBOSE, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($apiParams));
    $res = json_decode(curl_exec($curl));
    if ($res->orders[0]->order_source != '') {
        return $res->orders[0];
    }
}
function brecho($msg)
{
echo '<br><pre>';
    print_r($msg);
    echo PHP_EOL;
    echo '</pre><br>';
}