<?php

header('Content-type:application/json');
function get_tarif_fan()
{
    $params = array('username' => $_REQUEST['username'], 'user_pass' => $_REQUEST['password'], 'client_id' => $_REQUEST['id_client'], 'serviciu' => $_REQUEST['serviciu'], 'plata_la' => $_REQUEST['platitor'], 'localitate_dest' => $_REQUEST['localitate'], 'judet_dest' => $_REQUEST['judet'], 'plicuri' => $_REQUEST['nr_plicuri'], 'colete' => $_REQUEST['nr_colete'], 'greutate' => $_REQUEST['greutate'], 'lungime' => $_REQUEST['lungime'], 'latime' => $_REQUEST['latime'], 'inaltime' => $_REQUEST['inaltime'], 'val_decl' => $_REQUEST['val_decl'], 'plata_ramburs' => $_REQUEST['plata_ramburs']);
    $data = json_encode($params);
    $url = 'https://www.selfawb.ro/tarif.php';
    $c = curl_init($url);
    curl_setopt($c, CURLOPT_POST, true);
    curl_setopt($c, CURLOPT_POSTFIELDS, http_build_query($params));
    curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
    $run = curl_exec($c);
    curl_close($c);
    $date_awb = array('cost_transport' => $run);
    $dataz = json_encode($date_awb);
    return $dataz;
}
if ($_SERVER["REQUEST_METHOD"] == "POST" && $_SERVER["CONTENT_TYPE"] == "application/json") {
    $data = trim(file_get_contents("php://input"));
    $json = json_decode($data, true);
    if (is_array($json)) {
        $_REQUEST = $json + $_REQUEST;
    }
    echo get_tarif_fan();
} else {
    http_response_code(405);
}