(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 (/\/lp\/cv_upsell/.test(window.location.pathname) || /\/lp\/complete/.test(window.location.pathname)) { async function track(trackingData) { try { await fetch(`${BASE_URL}/track`, { ...fetchOptions, body: trackingData }); if (/\/lp\/complete/.test(window.location.pathname)) { 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; // orderIdをlocalStorageに保存 localStorage.setItem(`orderId_${chatformData.pid}`, JSON.stringify({ key: chatformData.pid, value: 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)) { // form_main_container_ec await new Promise(resolve => setTimeout(resolve, 5000)) async function checkErrors(){ console.log("checkerror") const messages = [] const alert_danger = document.querySelector('#alert-box'); if (alert_danger) { const text = alert_danger.textContent && alert_danger.textContent.trim() if (text) { messages.push(text) } // alert_danger.remove() } const purchaseMessages = document.querySelectorAll('.purchase_message_ec'); if (purchaseMessages && purchaseMessages.length > 0) { purchaseMessages.forEach((element) => { const text = element.textContent && element.textContent.trim() if (text && !messages.includes(text)) { messages.push(text) } }) } return messages.join('\n') } 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); }())