<?php
header('Content-Type: application/json');

// Ambil data dari request
$auth_username = $_POST['auth_username'] ?? '';
$auth_token = $_POST['auth_token'] ?? '';

if(empty($auth_username) || empty($auth_token)){
    echo json_encode(["success" => false, "message" => "Auth username dan token wajib diisi!"]);
    exit;
}

// Ambil user ID dari token (sebelum tanda ":")
$user_id = explode(":", $auth_token)[0];

// URL API dinamis sesuai user_id
$url = "https://app.orderkuota.com/api/v2/qris/mutasi/" . $user_id;

// Payload
$payload = "app_reg_id=&phone_uuid=fRY7qYvGQgKWDZ1N916dRg&phone_model=ASUS_X01BDA&requests%5Bqris_history%5D%5Bketerangan%5D=&requests%5Bqris_history%5D%5Bjumlah%5D=&request_time=".time()."000&phone_android_version=9&app_version_code=250811&auth_username={$auth_username}&requests%5Bqris_history%5D%5Bpage%5D=1&auth_token={$auth_token}&app_version_name=25.08.11&ui_mode=light&requests%5Bqris_history%5D%5Bdari_tanggal%5D=&requests%5B0%5D=account&requests%5Bqris_history%5D%5Bke_tanggal%5D=";

// Header
$headers = [
    "Host: app.orderkuota.com",
    "signature: 0f4281aea38cab8f1212efe422671c5e66baf82ad8b24cece5c1169ba19a5095f46a925e5c652f7a96b9c9e66e2db9240d1ff5e1111cdf6c02802d0fe28597a9",
    "timestamp: ".time()."000",
    "content-type: application/x-www-form-urlencoded",
    "content-length: " . strlen($payload),
    "accept-encoding: gzip",
    "user-agent: okhttp/4.12.0"
];

// Eksekusi cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');

$response = curl_exec($ch);

if(curl_errno($ch)){
    echo json_encode(["success" => false, "message" => curl_error($ch)]);
} else {
    echo $response;
}
curl_close($ch);
?>
