// URL of the API you want to fetch const apiUrl = 'https://api.evertransit.com/v1.1/pricing/plans' //const signupUrl = 'https://signup.dev.evertransit.com' //const password = 'TejmcySXPJix2MvaF1k3E0' // const apiUrl = 'https://api.evertransit.whipclient.io/v1.1/pricing/plans' const signupUrl = 'https://signup.evertransit.com' const username = 'et_signup_client' const password = 'ExqI8!%5i+W3#M2U' //var products = {} var base64Credentials = btoa(username + ':' + password) getProducts = function () { return $.ajax({ url: apiUrl, type: 'GET', dataType: 'json', headers: { Authorization: 'Basic ' + base64Credentials }, success: function (response) { // Handle successful response return response }, error: function (jqXHR, textStatus, errorThrown) { // Handle error response console.log(errorThrown) return [] } }) } document.addEventListener('DOMContentLoaded', function () { // Function to add content to the div function addContentToDiv() { var div = document.getElementById('dynamic_pricing') // Check if the div exists if (div) { getProducts().then(data => { const setOfFeatures = [] let sortedProducts = data.sort( (a, b) => a.default_price - b.default_price ) div.innerHTML = createHtml(data) }) } else { console.error('Div not found.') } } // Call the function to add content on page load addContentToDiv() }) function createHtml(products) { var html = "
" + "
" + products.map(product => createPlanHtml(product)).join("") + "
" var endHtml = html + "
 
" return endHtml } function createPlanHtml(product) { const hasTrial = product?.metadata?.hasOwnProperty('trial_days'); const trialBanner = hasTrial ? "
" + product?.metadata?.trial_days + " Days
Free Trial
" : ""; var html = "
" + trialBanner + "" + product.name + "" + "
Get Started
" return html } function buildLiField(liText) { return "
  • " + liText + "
  • " } function getSetUpFee(eachProduct) { let filteredPrice = eachProduct.prices.filter((allPrice) => allPrice.product == eachProduct.id) let findedPrice = filteredPrice.find((eachPrice) => eachPrice.nickname ? (eachPrice.nickname).split(' ').join('').toLowerCase() == 'setupfee' : '') return findedPrice == undefined || findedPrice == null ? "" + '0' + " " : "" + findedPrice.unit_amount / 100 + "" } function getProductRecurring(eachProduct) { let filteredPrice = eachProduct.prices.filter((allPrice) => allPrice.product == eachProduct.id) let findedPrice = filteredPrice.find((eachPrice) => eachPrice.type === "recurring" && eachPrice.active == true && eachPrice.unit_amount !== null) return findedPrice == undefined || findedPrice == null ? "" + '0' + " " : "" + findedPrice.unit_amount / 100 + "" } function getOverageLimit(eachProduct) { let getByTiersMode = eachProduct.prices.find((eachPrice) => { if (eachPrice.tiers_mode == 'graduated') { return true } else if (eachPrice.tiers_mode == 'volume') { return true } else { return false } }) if (getByTiersMode) { let overageLimit = getByTiersMode.tiers.find((each) => each.up_to) return "" + overageLimit.up_to + "" } } function getOverageFee(eachProduct) { let getByTiersMode = eachProduct.prices.find((eachPrice) => { if (eachPrice.tiers_mode == 'graduated') { return true } else if (eachPrice.tiers_mode == 'volume') { return true } else { return false } }) if (getByTiersMode) { let overageFee = getByTiersMode.tiers.find((each) => each.up_to == null) return "" + overageFee.unit_amount / 100 + "" } }