$method, CURLOPT_HTTPHEADER => $headers, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 45 ]); if ($payload !== null) { curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); } $body = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($body === false || $status < 200 || $status >= 300) { throw new Exception("HTTP $status: " . ($body ?: curl_error($ch))); } curl_close($ch); return json_decode($body, true); } function values($fit, $demand, $margin, $cost, $risk, $customer) { return [ "determine_trade_in_value_vehicle_fit_score" => $fit, "determine_trade_in_value_market_demand_score" => $demand, "determine_trade_in_value_gross_margin_potential" => $margin, "determine_trade_in_value_reconditioning_or_process_cost" => $cost, "determine_trade_in_value_compliance_risk_score" => $risk, "determine_trade_in_value_customer_value_score" => $customer ]; } try { $identityUrl = getenv("DECISIOQ_IDENTITY_URL") ?: "https://identity.vinquery.com/connect/token"; $catalogUrl = rtrim(getenv("DECISIOQ_DKS_URL") ?: "https://dks.vinquery.com", "/"); $decisionServiceUrl = rtrim(getenv("DECISIOQ_DDE_URL") ?: "https://dde.vinquery.com", "/"); $correlationId = "auto-ucd-008-php-" . bin2hex(random_bytes(8)); $tokenResponse = request_json("POST", $identityUrl, [ "clientId" => required_env("DECISIOQ_CLIENT_ID"), "clientSecret" => required_env("DECISIOQ_CLIENT_SECRET"), "audience" => getenv("DECISIOQ_AUDIENCE") ?: "vinquery:api:decisioq" ]); $token = $tokenResponse["jwtToken"]; request_json("GET", "$catalogUrl/decisioncatalog/decisions/AUTO-UCD-008", null, $token, $correlationId); $result = request_json("POST", "$decisionServiceUrl/api/v1/decide", [ "decisionId" => "AUTO-UCD-008", "profileId" => "balanced", "scenarioId" => "standard_retail", "algorithm" => "TOPSIS", "weightStrategy" => "Expert", "runSensitivity" => false, "requestContext" => ["correlationId" => $correlationId], "options" => [ ["optionId" => "OPTION-001", "name" => "Retail Trade Option", "values" => values(86, 92, 3200, 900, 22, 84)], ["optionId" => "OPTION-002", "name" => "Wholesale Backup Option", "values" => values(78, 73, 4100, 1600, 35, 76)], ["optionId" => "OPTION-003", "name" => "Certified Retail Option", "values" => values(91, 85, 2300, 650, 18, 88)] ] ], $token, $correlationId); echo json_encode($result, JSON_PRETTY_PRINT) . PHP_EOL; } catch (Exception $ex) { fwrite(STDERR, $ex->getMessage() . PHP_EOL); exit(1); } ?>