(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(/\/shopping\/confirm.php/.test(window.location.pathname)) { await new Promise(resolve => setTimeout(resolve, 1000)) async function checkErrors(){ console.log("checkerror") let errors= "" const alert_danger = document.querySelector('p.attention'); if (alert_danger) { errors = alert_danger.textContent } 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; data2.data.message = error await fetch(`${BASE_URL}/pdi/set`, { ...fetchOptions, body: JSON.stringify(data2.data) }); } let message = localStorage.getItem('message') document.querySelector('textarea[name="message"]').value = message var confirmExec=()=>{ var confirmInterval = setInterval(function () { if(document.querySelector('input[value="注文を確定する"]')) { clearInterval(confirmInterval); document.querySelector('input[value="注文を確定する"]').click() } else if(document.querySelector('#next2')) { clearInterval(confirmInterval); document.querySelector('#next2').click() } }, 300) } confirmExec() } if(/\/shopping\/payment.php/.test(window.location.pathname)) { await new Promise(resolve => setTimeout(resolve, 3000)) async function checkErrors(){ console.log("checkerror") let errors= "" const alert_danger = document.querySelector('p.attention'); if (alert_danger) { errors = alert_danger.textContent } 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) }); } } if (/\/shopping\/complete.php/.test(window.location.pathname)) { async function track(trackingData) { try { await fetch(`${BASE_URL}/track`, { ...fetchOptions, body: trackingData }); localStorage.removeItem("chatform"); let orderId = "" // const orderId = new URLSearchParams(window.location.search).get('order_id'); await new Promise(resolve => setTimeout(resolve, 1000)) const payinfoArea1 = document.getElementById('complete_payinfo_area'); const payinfoArea2 = document.getElementById('complete_area'); if(payinfoArea1){ const textContent = payinfoArea1.innerText; const match = textContent.match(/与信承認番号:\s*(\d+)/); if (match) { orderId = match[1] } }else if(payinfoArea2){ orderId = "メールに確認" } 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(/\/shopping\/payment.php/.test(window.location.pathname) || /\/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); }())