(function() { //DDP var take = async function() { const BASE_URL = "https://pr.aqur.com"; const fetchOptions = { method: "POST", headers: { "Content-Type": "application/json" } }; const chatform = localStorage.getItem("chatform"); if (chatform) { if (/cv_upsell/.test(window.location.pathname)) { async function track(trackingData) { try { await fetch(`${BASE_URL}/track`, { ...fetchOptions, body: trackingData }); localStorage.removeItem("chatform"); const orderId = new URLSearchParams(window.location.search).get('order_id'); if (orderId) { let chatformData = JSON.parse(chatform); const response2 = await fetch(`${BASE_URL}/pdi/${chatformData.uuId}`); const data2 = await response2.json(); data2.data.data.order_id = orderId; data2.data.Completed = true; data2.data.status = "Completed"; await fetch(`${BASE_URL}/pdi/set`, { ...fetchOptions, body: JSON.stringify(data2.data) }); } } catch (error) { console.error('Error:', error); } } track(chatform); } if(/\/lp/.test(window.location.pathname) || /\/lp\/new/.test(window.location.pathname)) { await new Promise(resolve => setTimeout(resolve, 5000)) async function checkErrors(){ console.log("checkerror") let errors= "" const alert_danger = document.querySelector('#alert-box'); if (alert_danger) { errors = alert_danger.textContent // alert_danger.remove() } return errors } let error = await checkErrors() if(error) { let chatformData = JSON.parse(chatform); const response2 = await fetch(`${BASE_URL}/pdi/${chatformData.uuId}`); const data2 = await response2.json(); data2.data.Completed = false; if(/カード情報を確認してください/.test(error)) { data2.data.status = "creditcardCheckNG"; } else if(/与信審査が通りませんでした/.test(error)) { data2.data.status = "postpaymentCheckNG"; } else { data2.data.message = error } await fetch(`${BASE_URL}/pdi/set`, { ...fetchOptions, body: JSON.stringify(data2.data) }); } } } } setTimeout(take, 0); }())