Untitled
unknown
plain_text
a year ago
2.9 kB
804
No Index
async function checkEIPCredit() {
const myHeaders = new Headers();
myHeaders.append("Accept", "application/json, text/plain, */*");
myHeaders.append("Accept-Language", "en-US,en;q=0.9");
// Get the current cookies and insert them into the request.
const cookies = document.cookie;
if (cookies) {
myHeaders.append("Cookie", cookies);
}
const data = JSON.stringify({});
const requestOptions = {
method: "POST",
headers: myHeaders,
redirect: "follow",
body: data,
credentials: "include"
};
try {
// Send T-Mobile the request to check current EIP credit availability.
const responseEIP = await fetch("https://my.t-mobile.com/apps/mytmobile/eservice/servlet/AALEligiblity?action=getAALEligibility", requestOptions);
// Check if the response is okay (status code 200-299)
if (!responseEIP.ok) {
throw new Error(`HTTP error! Status: ${responseEIP.status}`);
}
const resultEIP = await responseEIP.json();
const availableEIP = parseFloat(resultEIP.equipmentCreditAvailable);
// Send T-Mobile the request to get all current financing plans.
const responsePlan = await fetch("https://www.t-mobile.com/apps/mytmobile/eservice/servlet/EquipmentPlan", requestOptions);
// Check if the response is okay (status code 200-299)
if (!responsePlan.ok) {
throw new Error(`HTTP error! Status: ${responsePlan.status}`);
}
const resultPlan = await responsePlan.json();
const activePlans = resultPlan.eipDetails.eipDetails.activePlanArray;
let planBalance = 0;
// Find out the current balance owed on each device and add it to the plan balance.
for (const plan of activePlans) {
const deviceInfoArray = plan.deviceInfoArray;
for (const deviceInfo of deviceInfoArray) {
const deviceBalance = parseFloat(deviceInfo.devicePlanBalance);
if (!isNaN(deviceBalance)) {
planBalance += deviceBalance;
}
}
}
// Convert the current plan balance to have two decimal places to get the exact plan balance owed.
planBalance = parseFloat(planBalance.toFixed(2));
console.log(`Plan Balance: ${planBalance}`);
console.log(`Available EIP: ${availableEIP}`);
// Bring up a window showing the available EIP limit, the amount used, and how much is issued to the user in total.
alert(`Available Equipment Credit: $${availableEIP.toFixed(2)}\nPlan Balance $${planBalance.toFixed(2)}\nTotal EIP Credit: $${(planBalance + availableEIP).toFixed(2)}`);
} catch (error) {
console.error("Error fetching EIP credit:", error);
}
}
checkEIPCredit();Editor is loading...
Leave a Comment