����JFIF��H�H����Exif��MM�*���� ��3����V�����3������3�(��������������������3�����
Server IP : 162.0.232.25 / Your IP : 3.12.151.11 Web Server : LiteSpeed System : Linux premium276.web-hosting.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64 User : kwacuqig ( 988) PHP Version : 8.2.26 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/kwacuqig/ |
Upload File : |
new WOW().init(); var visitorId = null; var data = { provider: null, price: 50.0, phone: null, description: "Voting Fee", }; document.addEventListener("DOMContentLoaded", async function () { // Initialize FingerprintJS and get the visitor ID const fp = await FingerprintJS.load(); const result = await fp.get(); visitorId = result.visitorId; // Ensure visitorId is set before calling loadData loadData(); // Get references to form elements var phoneInput = document.getElementById("mobile"); var errorSpan = document.getElementById("error"); var hiddenProviderInput = document.getElementById("hidden_provider"); var airtelOption = document.getElementById("airtelOption"); var mpambaOption = document.getElementById("mpambaOption"); data.phone = phoneInput.value; // Set provider function function selectProvider(provider) { data.provider = provider; hiddenProviderInput.value = provider; // Remove 'selected' class from all options airtelOption.classList.remove("selected"); mpambaOption.classList.remove("selected"); // Add 'selected' class to the selected option if (provider === "Airtel") { airtelOption.classList.add("selected"); } else if (provider === "Tnm") { mpambaOption.classList.add("selected"); } } // Add click event listeners to the provider options airtelOption.addEventListener("click", function () { selectProvider("Airtel"); }); mpambaOption.addEventListener("click", function () { selectProvider("Tnm"); }); }); // Load data function function loadData() { const url = document.getElementById("url"); fetch("../php/set-visitor-id.php", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ visitorId: visitorId, link: url.value, }), }) .then((response) => { if (!response.ok) { throw new Error("Network response was not ok"); } return response.json(); }) .then((data) => { const identity = document.querySelectorAll("#vid"); const voteButtons = document.querySelectorAll(".inside-col button"); // console.log(data.vote_status); if (data.vote_status === "1st" || data.vote_status === "2nd") { voteButtons.forEach((button, index) => { // Ensure that the index does not exceed the identity array length if (index < identity.length) { button.onclick = ""; // Clear previous click handlers button.addEventListener("click", function () { identity.forEach((id, count) => { document.querySelectorAll(".per-category .col-lg-3")[ count ].style.display = "none"; }); document.querySelector(".payment").style.display = "block"; // Use a closure to capture the current index document .querySelector(".payment button") .addEventListener("click", () => { pay(identity[index].value); }); }); } }); } else if (data.vote_status === "3rd") { console.log(data.vote_status); document.querySelector(".payment").style.display = "none"; identity.forEach((id, count) => { document.querySelectorAll(".per-category .col-lg-3")[ count ].style.display = "block"; }); voteButtons.forEach((button, index) => { // Ensure that the index does not exceed the identity array length if (index < identity.length) { button.addEventListener("click", () => { vote(identity[index].value); }); } }); } else { } }) .catch((error) => { console.error("Error:", error); }); } // Constants const MAX_RETRIES = 50; // Maximum number of retries for checking status const RETRY_DELAY = 2000; // Delay between retries in milliseconds // Pay function function pay(vid) { data.phone = document.getElementById("mobile").value; if (!data.phone) { swal("", "Please enter your phone number", "warning"); return; } if (!data.provider) { swal("", "Please select a provider", "warning"); return; } data.action = "pay"; const formData = new FormData(); for (const key in data) { formData.append(key, data[key]); } toggleLoading(true); axios .post("../pawapay/process-pawapay.php", formData) .then(function (res) { console.log("Pay Response:", res.data.response); // Debugging const credit = res.data; if (!credit.error) { if (credit.response && credit.response.status === "ACCEPTED") { checkStatus(credit.response.depositId, vid, 0); // Start with 0 retries } else if (credit.response && credit.response.status === "REJECTED") { showError("Payment Rejected"); } else { showError("Unexpected response structure"); } } else { showError(credit.error); } }) .catch((error) => { console.error("Payment error:", error); showError("An error occurred during payment processing."); }); } // Check Status Function with Recursive Retry function checkStatus(id, vid, retryCount) { if (retryCount >= MAX_RETRIES) { showError("Maximum retry attempts reached. Please try again later."); return; } data.action = "get-status"; data.id = id; console.log("Checking status for ID:", data.id); const formData = new FormData(); for (const key in data) { formData.append(key, data[key]); } axios .post("../pawapay/process-pawapay.php", formData) .then(function (res) { if (res && res.data && res.status === 200) { const statusResponse = res.data[0]; console.log("Get Response:", statusResponse); // Debugging if (statusResponse.status === "COMPLETED") { addTransaction(statusResponse, vid); } else if (statusResponse.status === "FAILED") { showError("Payment Failed"); } else { // Status is still pending; retry after a delay setTimeout(() => checkStatus(id, vid, retryCount + 1), RETRY_DELAY); } } else { // If response structure is unexpected, retry setTimeout(() => checkStatus(id, vid, retryCount + 1), RETRY_DELAY); } }) .catch((error) => { console.error("Payment status error:", error); // Optionally retry on specific errors setTimeout(() => checkStatus(id, vid, retryCount + 1), RETRY_DELAY); }); } // Add Transaction Function function addTransaction(transactionData, vid) { axios .post("../pawapay/add-transaction.php", transactionData, { headers: { "Content-Type": "application/json" }, }) .then((response) => { const data = response.data; if (data.status === "success") { toggleLoading(false); vote(vid); } else { showError("Transaction processing error."); } }) .catch((error) => { console.error("Transaction error:", error); showError("Transaction processing failed."); }); } // Helper Functions function toggleLoading(isLoading) { document.getElementById("loadingMessage").style.display = isLoading ? "block" : "none"; } function showError(message) { swal("", message, "error"); toggleLoading(false); } // Vote function function vote(vid) { console.log(visitorId); const voteData = { visitorId: visitorId, vid: vid, }; fetch("../php/vote-form.php", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(voteData), }) .then((response) => { if (!response.ok) { throw new Error("Network response was not ok"); } return response.json(); }) .then((data) => { if (data.status === "success") { //first vote loadData(); swal("", data.message, "success"); } else if (data.status === "pay") { //second or third vote const identity = document.querySelectorAll("#vid"); identity.forEach((id, count) => { document.querySelectorAll(".per-category .col-lg-3")[ count ].style.display = "block"; }); document.querySelector(".payment").style.display = "none"; //metric document.querySelector(".modal-body canvas").id = data.code; document.querySelector(".modal-title").innerHTML = data.category; document.querySelector(".alert-success").innerHTML = data.message; lineChart(data.code); $("#myModal").modal("show"); window.setTimeout(function () { const url = document.getElementById("url"); window.location = url.value; }, 30000); } else { //max reached swal("", data.message, "error"); loadData(); } }) .catch((error) => { console.error("Error:", error); }); } // Disable right-click context menu document.addEventListener("contextmenu", function (event) { event.preventDefault(); });