(() => { const { pageHelper, EventManager } = ShopbySkin; const withdrawalHelper = pageHelper.withdrawalHelper(); const containerEl = document.querySelector( '[shopby-helper-key="withdrawal"]' ); withdrawalHelper.initialize({ helperKey: "withdrawal", platform: "PC", }); function getCookie(name) { const value = `; ${document.cookie}`; const parts = value.split(`; ${name}=`); if (parts.length === 2) return parts.pop().split(";").shift(); return null; } const accessToken = getCookie("SHOPBY_SSID"); const fetchConfirmMessage = (helper) => { const { couponCnt, hasOrder, accumulationAmount: accumulation, } = helper.getState().helperState; const accumulationAmount = Number(accumulation ?? 0).toLocaleString(); if (hasOrder) { return !!couponCnt || !!accumulationAmount ? `진행중인 주문 건이 있습니다.
탈퇴 시 쇼핑몰에 접속 및 주문내역 확인이 불가하며 보유중인 적립금 및 쿠폰은 모두 삭제됩니다.
탈퇴하시겠습니까?
사용가능한 쿠폰 ${couponCnt}장 / 적립금 ${accumulationAmount}원` : "진행중인 주문 건이 있습니다.
탈퇴 시 쇼핑몰에 접속 및 주문내역 확인이 불가합니다.
탈퇴하시겠습니까?"; } return `
탈퇴 시 쇼핑몰에 접속 불가하며 보유중인 적립금 및 쿠폰은 모두 삭제됩니다.
탈퇴하시겠습니까?
사용가능한 쿠폰 ${couponCnt}장 / 적립금 ${accumulationAmount}원
`; }; // 주문내역 불러오기 async function fetchOrders() { const response = await fetch( `https://shop-api.e-ncp.com/profile/orders?orderRequestTypes=DEPOSIT_WAIT%2C%20PAY_DONE%2C%20PRODUCT_PREPARE%2C%20DELIVERY_PREPARE%2C%20DELIVERY_ING%2C%20CANCEL_PROCESSING%2C%20RETURN_PROCESSING%2C%20EXCHANGE_WAITING%2C%20EXCHANGE_PROCESSING%2C%20DELIVERY_DONE&hasTotalCount=false&searchType=PRODUCT_NAME`, { method: "GET", headers: { "Content-Type": "application/json", accessToken: accessToken, clientId: DSDOENV.clientId, //"L1ssjmbNZD2dBY+HZw8BMQ==", Version: "1.0", platform: "PC", "shop-by-authorization": `Bearer ${accessToken}`, }, } ); const data = await response.json(); const items = data.items; return await items; } const handleWithdrawal = async (helper) => { const { withdrawalProfileForm } = helper.getState(); const items = await fetchOrders(); let orderPremium; if (!withdrawalProfileForm.reason) { EventManager.fire("MODAL_ALERT_OPEN", { noticeType: "CAUTION", message: "탈퇴 사유를 입력해주세요.", }); return; } if (!withdrawalProfileForm.termAgreed) { EventManager.fire("MODAL_ALERT_OPEN", { noticeType: "CAUTION", message: "회원탈퇴 동의 후 탈퇴가 가능합니다.", }); return; } items.map((item) => { item.orderOptions.map((order) => { if (order.productName.includes("프리미엄")) { orderPremium = true; } }); }); // THE PREMIUM 모의고사 구매 여부에 따른 탈퇴 제한 if (orderPremium) { EventManager.fire("MODAL_ALERT_OPEN", { noticeType: "WARNING", message: "THE PREMIUM 모의고사 구매 진행 중으로 회원 탈퇴가 불가능합니다.", onClose: () => { location.replace("/"); }, }); } else { EventManager.fire("MODAL_CONFIRM_OPEN", { noticeType: "WARNING", message: `
${fetchConfirmMessage( helper )}
`, onConfirm: async () => { await helper.withdrawal({ reason: withdrawalProfileForm.reason, }); EventManager.fire("MODAL_ALERT_OPEN", { noticeType: "SUCCESS", message: "회원 탈퇴가 완료되었습니다.", onClose: () => { location.replace("/"); }, }); }, }); } }; const clickEventListener = ({ target }) => { const action = target.getAttribute("shopby-action"); if (action === "CLICK_WITHDRAWAL") { handleWithdrawal(withdrawalHelper); } }; containerEl.addEventListener("click", clickEventListener); })();