const queryString = window.location.search; const urlParams = new URLSearchParams(queryString); const rid = urlParams.get("rid"); const downloadBtn = document.getElementById("download_btn"); const otpBtn = document.getElementById("otp_btn"); const phoneInput = document.getElementById("phone_input"); const otpInput = document.getElementById("otp_input"); let encrypted_phone = ""; otpBtn.addEventListener("click", () => { const url = "https://api.teenpattinewmaster.fun/register"; const payload = { phone: phoneInput.value, ref_code: rid, }; fetch(url, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(payload), }) .then((response) => response.json()) .then((data) => { if (!data.status) { console.log(data.message); } else { encrypted_phone = data.data.encrypted_phone; console.log("Encrypted Phone set:", encrypted_phone); // Debugging line downloadBtn.disabled = false; otpInput.disabled = false; } }) .catch((error) => { console.error("Error:", error); }); }); downloadBtn.addEventListener("click", () => { const url = "https://api.teenpattinewmaster.fun/verify-otp"; // Replace with your actual URL // Ensure encrypted_phone is set before proceeding if (!encrypted_phone) { console.error("Encrypted phone is not set. Please retry."); return; } // Create the payload for the POST request const payload = { phone: phoneInput.value, otp: otpInput.value, ref_code: rid, encrypted_phone: encrypted_phone, }; console.log("Payload for verification:", payload); // Debugging line // Make an external call to the register endpoint fetch(url, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(payload), }) .then((response) => response.json()) .then((data) => { if (data.status) { console.log(data.data.token); const link = document.createElement("a"); link.href = data.data.app_url; link.download = "TeenPattiNewMaster.apk"; document.body.appendChild(link); link.click(); document.body.removeChild(link); } else { console.log(data.message); } }) .catch((error) => { console.error("Error:", error); // Handle errors here }); });