Sketching and Drawing Pencils for Beginners. (2024)

`; }; const unblockCoupon = async (data) => { try { const url = `/apps/ez/api/UnblockCoupon`; const responses = await makeAjaxRequest(url, data); const response = JSON.parse(responses); if (response.ReturnCode == '0') { appendDiscountInCheckOutForPoints(''); applyDiscountCode(''); const dataa = { attributes: { TBT: 'nothing', }, }; const appendCart = await makeAjaxRequest(`/cart.js`, dataa); if (localStorage.getItem('ub')?.length > 1) localStorage.removeItem('ub'); // location.reload(); } else { showErrorMessage(response.ReturnMessage); } } catch (error) { console.log('unblockCoupon Error:', error); } }; const confirmCouponRedemptionWithoutOtp = async (data) => { // when OPT is not required await applyDiscountCode(data.POSPromo);const dataa = { attributes: { EasyId: data?.EasyId, RequestID: data?.RequestID, OrderTypeId: "easyRewardsDiscountCoupon", TempCouponCode: data?.TempCouponCode, ER_custom_checkoutToken: generateRandomCheckoutToken(), UseedCoupon:data.POSPromo }};const appendCart = await makeAjaxRequest(`/cart.js`, dataa); const successMessage = `

Discount Applied !

`; document.querySelector('#cart-errors')?.insertAdjacentHTML('afterend', successMessage); // ashish const couponCodeHtml = `${data.POSPromo.toUpperCase()}`; let ashishDiv = `

Coupon Redeemed! Use coupon code ${couponCodeHtml} in checkout

`; document.querySelector('#iframeID').contentWindow.document.body.querySelector('.abhi_modal-content').innerHTML += ashishDiv; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.abhi_easyModalDynamicContent').style.display = 'none'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.closeModalAndReleasePoints').style.display = 'none'; document.querySelector('#iframeID').contentWindow.document.body.querySelector('.closeSuccessModal').style.display = 'block'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.closeSuccessModal') .addEventListener('click', async (e) => { e.preventDefault(); // document.querySelector("#iframeID").contentWindow.document.body.querySelector(".abhi_eazyRewardzModal").style.display = "none"; document.querySelector('#iframeID').style.display = 'none'; // location.reload(); }); }; const confirmCouponOtp = async (data) => { try { let errorMessage = document.querySelector('#iframeID')?.contentWindow?.document?.body?.querySelector('.errorMessage') || document.querySelector('.errorMessage'); if (errorMessage?.textContent?.length >= 1) { // clearing the text for previous error messages errorMessage.textContent = ' '; errorMessage.style.display = 'none'; } showLoader(true); const url = `/apps/ez/api/ConfirmCouponOtp`; const couponOtp = document.querySelector('.couponOtpInput')?.value; const params = { ...data, couponOtp, }; const responses = await makeAjaxRequest(url, data); const response = JSON.parse(responses); console.log("Parameters Coupon", data); const dataa = { attributes: { EasyId: data.EasyId, RequestID: data.RequestID, OrderTypeId: 'easyRewardsDiscountCoupon', TempCouponCode: data.CouponCode, ER_custom_checkoutToken: generateRandomCheckoutToken(), UseedCoupon:data.DiscountCode }, }; const appendCart = await makeAjaxRequest(`/cart.js`, dataa); if (response.ReturnCode == '0') { const cartForm = document.querySelectorAll("form[action='/cart']"); let input = document.createElement('input'); input.type = 'hidden'; input.name = 'discount'; input.value = data.DiscountCode; input.class = 'easyReward-discount'; await applyDiscountCode(data.DiscountCode); showLoader(false); const successMessage = `

Discount Applied !

`; document.querySelector('#cart-errors')?.insertAdjacentHTML('afterend', successMessage); // ashish const couponCodeHtml = `${data.DiscountCode.toUpperCase()}`; let ashishDiv = `

Coupon Redeemed! Use coupon code ${couponCodeHtml} in checkout

`; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.abhi_modal-content').innerHTML += ashishDiv; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.abhi_easyModalDynamicContent').style.display = 'none'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.closeSuccessModal').style.display = 'block'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.closeSuccessModal') .addEventListener('click', async (e) => { e.preventDefault(); // document.querySelector("#iframeID").contentWindow.document.body.querySelector(".abhi_eazyRewardzModal").style.display = "none"; document.querySelector('#iframeID').style.display = 'none'; // location.reload(); }); } else { // enabling submit button here since the otp was invalid // document // .querySelector("#iframeID") // .contentWindow.document.body.querySelector(".confirmCouponOtp").disabled = false; // document // .querySelector("#iframeID") // .contentWindow.document.body.querySelector(".confirmCouponOtp").style.opacity = "1"; // ends showErrorMessage(response.ReturnMessage); } } catch (error) { console.log(error); } }; const renderOtpHtml = (data, requiredParameters, pointsRedeem) => { const abhi_uiSetting = JSON.parse(localStorage.getItem('abhi_uiSetting')); const html = abhi_getConfirmOtpHtml(abhi_uiSetting); // alert(requiredParameters) document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.stc_cancleButtonOtpForm') ?.addEventListener('click', async function (e) { e.preventDefault(); const responses = await releasePoints(); const response = JSON.parse(responses); if (response.ReturnCode == '0') { // console.log("Reload 1") location.reload(); } else { // console.log("Reload 2") location.reload(); } }); document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.abhi_easyModalDynamicContent').innerHTML = html; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.confirmOtp') .addEventListener('click', async function (e) { e.preventDefault(); showLoader(true); // disabling submit button to prevent multiple clicks. document.querySelector('#iframeID').contentWindow.document.body.querySelector('.confirmOtp').disabled = true; document.querySelector('#iframeID').contentWindow.document.body.querySelector('.confirmOtp').style.opacity = '0.5'; // ends const url = `/apps/ez/api/ConfirmOTP`; const enteredOTP = document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.OtpInput').value; const date = new Date().toString().split(' '); const aDate = `${date[2]} ${date[1]} ${date[3]}`; // alert(pointsRedeem) const postData = { EasyId: requiredParameters.EasyId, TransactionCode: localStorage.identifier, SmsCode: document.querySelector('#iframeID').contentWindow.document.body.querySelector('.OtpInput').value, TransactionDate: aDate, CountryCode: '91', StoreName: Shopify.shop, PointRedeem: pointsRedeem, EasyPoints: requiredParameters.EasyPoints, PointRate: requiredParameters.PointRate, PointValue: requiredParameters.PointValue, }; // console.log("lllllll -> ", postData); const responses = await makeAjaxRequest(url, postData); // console.log("cccc -> ", responses); const response = JSON.parse(responses); // console.log("mmmmm -> ", response); // if (response.ReturnCode != "0") { // showErrorMessage(response.ReturnMessage); // return; // } if (response.ReturnCode != '0') { // console.log("=========> When user code is 365 then error", response.ReturnCode); // enabling submit button here since the otp was invalid document.querySelector('#iframeID').contentWindow.document.body.querySelector('.confirmOtp').disabled = false; document.querySelector('#iframeID').contentWindow.document.body.querySelector('.confirmOtp').style.opacity = '1'; // ends showErrorMessage(response.ReturnMessage); return; } // else if (response.ReturnCode == "0") /* console.log( "==============================When user code is 0 then success" ); */ // display success message on UI (to be done) // console.log("Parameters Points", requiredParameters); const dataa = { attributes: { EasyId: requiredParameters.EasyId, RedemptionCode: enteredOTP, OldTransactionCode: localStorage.identifier, PointRedeem: pointsRedeem, EasyPoints: requiredParameters.EasyPoints, PointRate: requiredParameters.PointRate, PointValue: requiredParameters.PointValue, OrderTypeId: 'easyRewardsPoints', ER_custom_checkoutToken: generateRandomCheckoutToken(), UseedCode:JSON.stringify({"code":response?.code,"isTender":false}) }, }; const appendCart = await makeAjaxRequest(`/cart.js`, dataa); // --------------------------------------------------------------------------------- if (response.ReturnCode == '0') { localStorage.setItem('cd', response.code); // const appendResponse = appendDiscountInCheckOutForPoints(response.code); // passing discountCoupon // if (appendResponse === true) { // console.log("appendResponse is true ==============", appendResponse); // testing for automatic coupon redemption const coupon = response.code; const applyCouponFunction = async (coupon) => { /* const shopName = checkLocation(); const url = shopName.split("."); const domain = `${url[url.length - 2]}.${url[url.length - 1]}`; const DB_domain = `${url[0]}` console.log(DB_domain) console.log("domain :", domain); console.log("coupon", coupon) const discountURL = `https://www.${domain}/discount/${coupon}` const TestingURL = `https://${DB_domain}.myshopify.com/discount/${coupon}` try { await fetch(domain == "myshopify.com" ? TestingURL : discountURL, { mode: "cors", headers: { "Access-Control-Allow-Origin": " * ", }, }) .then((response) => response.text()) //response.json()s .then((result) => console.log(result, "inside apply coupon success") ); } catch (error) { console.log(error); // alert(error); } */ }; // applyCouponFunction(coupon); await applyDiscountCode(coupon); showErrorMessage(''); const successMessage = `

Discount Applied !

`; document.querySelector('#cart-errors')?.insertAdjacentHTML('afterend', successMessage); // ashish const couponCodeHtml = `${response.code.toUpperCase()}`; let ashishDiv = `

Point Redeemed! Use coupon code ${couponCodeHtml} in checkout

`; document.querySelector('#iframeID').contentWindow.document.body.querySelector('.abhi_form-group').innerHTML += ashishDiv; document.querySelector('#iframeID').contentWindow.document.body.querySelector('.resendOtp').style.display = 'none'; document.querySelector('#iframeID').contentWindow.document.body.querySelector('.applied').style.display = 'none'; document.querySelector('#iframeID').contentWindow.document.body.querySelector('.cancel_hide').style.display = 'none'; document.querySelector('#iframeID').contentWindow.document.body.querySelector('.OtpInput').style.display = 'none'; document.querySelector('#iframeID').contentWindow.document.body.querySelector('.hide_label').style.display = 'none'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.closeModalAndReleasePoints').style.display = 'none'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.closeSuccessModal').style.display = 'block'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.abhi_easyModalDynamicContent h2 b').style.display = 'none'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.abhi_mobileScreen').style.height = '70px'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.abhi_modal-content').style.padding = '0 25px'; } else { showErrorMessage(response.ReturnMessage); } }); // Release point when user click on cancle button document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.confirmModalCancleButtonReleasPoint') ?.addEventListener('click', async () => { const releasePointsResponse = await releasePoints(); // console.log("releasePointsResponse", releasePointsResponse); // console.log("click Cancle button"); if (releasePointsResponse?.ReturnCode === 0 || releasePointsResponse?.ReturnCode == '0') { window.location.reload(); } else { showErrorMessage(releasePointsResponse?.ReturnMessage || 'Please Try After Some Time'); } }); document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.closeSuccessModal') .addEventListener('click', async (e) => { e.preventDefault(); // document.querySelector("#iframeID").contentWindow.document.body.querySelector(".abhi_eazyRewardzModal").style.display = "none"; document.querySelector('#iframeID').style.display = 'none'; // location.reload(); }); document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.resendOtp') .addEventListener('click', async (e) => { const date = new Date().toString().split(' '); const aDate = `${date[2]} ${date[1]} ${date[3]}`; e.preventDefault(); const url = `/apps/ez/api/ResendOTPs`; const response = await makeAjaxRequest(url, { EasyId: localStorage.id, TransactionCode: localStorage.identifier, BillDate: aDate, CountryCode: '91', StoreName: Shopify.shop, }); // alert("clicked!!") }); }; const appendDiscountInCheckOutForPoints = (couponCodeForPoints) => { const cartForm = document.querySelectorAll("form[action='/cart']"); const input = document.createElement('input'); input.type = 'hidden'; input.className = 'easyReward-discount'; input.name = 'discount'; input.value = couponCodeForPoints; if (cartForm.length === 0) { // console.log("cartForm is null ===============", cartForm); return true; } else { cartForm.forEach((x) => { x.append(input); }); return false; } }; const releasePoints = async () => { try { const url = `/apps/ez/api/ReleaseRedemptionPoints`; const date = new Date().toString().split(' '); const aDate = `${date[2]} ${date[1]} ${date[3]}`; const responses = await makeAjaxRequest(url, { EasyId: localStorage.id, TransactionCode: localStorage.identifier, StoreName: Shopify.shop, TransactionDate: aDate, CouponCode: localStorage.cd, DisableGiftCard: localStorage.cd, }); const response = JSON.parse(responses); if (response.ReturnCode == 0) { localStorage.removeItem('identifier'); localStorage.removeItem('cd'); appendDiscountInCheckOutForPoints(''); const dataa = { attributes: { TBT: 'nothing', }, }; const appendCart = await makeAjaxRequest(`/cart.js`, dataa); } return response; } catch (error) { console.log(error); } }; function reloadOnCancel() { document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.continueCheckout') .addEventListener('click', async function (e) { e.preventDefault(); showLoader(true); const response = await releasePoints(); // const response = JSON.parse(responses); // console.log("checkout -> ", response); showLoader(false); if (response.ReturnCode == '0') { // console.log("Reload 3") location.reload(); } else { // console.log("Reload 4") location.reload(); } }); } async function createModal(htmlData) { var frame = document.querySelector('#iframeID'); var frameDoc = frame.contentDocument || frame.contentWindow.document; frameDoc.documentElement.innerHTML = htmlData; // console.log(htmlData); // frame.contentWindow.document.write(htmlData) await allFunctionality(); } function closeModal() { var frame = document.getElementById('iframeID'); frame.style.display = 'none'; var frameDoc = frame.contentDocument || frame.contentWindow.document; frameDoc.documentElement.innerHTML = ''; } const abhi_modalHtml = `

`; const abhi_getModalHtml = (abhi_uiSetting) => { return `

${abhi_uiSetting.Modal1.Heading}

`; }; const abhi_getAvailablePointsHtml = (data, abhi_uiSetting) => { return `

${abhi_uiSetting.Modal2.Heading}

Balance:

Balance Points : ${data.AvailablePoints}

`; }; const submitRedeemCouponOtp = async () => { showLoader(true); const url = `/apps/ez/api/RedeemCoupon`; if (!document.querySelector('#iframeID').contentWindow.document.body.querySelector('.abhi_mobileInput').value) { return showErrorMessage('Please Enter Mobile No.'); } if ( !document.querySelector('#iframeID').contentWindow.document.body.querySelector('.discountCouponInputValue').value ) { return showErrorMessage('Please Enter Coupon Code.'); } let mydate = new Date(); let month = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][mydate.getMonth()]; let str = mydate.getDate().toString().length > 1 ? mydate.getDate() + ' ' + month + ' ' + mydate.getFullYear() : `0${mydate.getDate()}` + ' ' + month + ' ' + mydate.getFullYear(); const params = { EasyId: document.querySelector('#iframeID').contentWindow.document.body.querySelector('.abhi_mobileInput').value, EasyDiscountCoupon: document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.discountCouponInputValue').value, StoreName: Shopify.shop, Date: str, }; const responses = await makeAjaxRequest(url, params); const response = JSON.parse(responses); if (response.ReturnCode != '0') { return showErrorMessage(response.ReturnMessage); } else { const otpParams = { EasyId: document.querySelector('#iframeID').contentWindow.document.body.querySelector('.abhi_mobileInput') .value, RequestID: response.RequestID, CouponCode: document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.discountCouponInputValue').value, DiscountCode: response.POSPromo, StoreName: Shopify.shop, }; const ubPrams = { RequestID: response?.RequestID, CouponCode: otpParams?.CouponCode, StoreName: Shopify.shop, }; localStorage.setItem('ub', JSON.stringify(ubPrams)); if (response.OTPRequired != 1) { await confirmCouponRedemptionWithoutOtp({...response,EasyId:params.EasyId,TempCouponCode:params.EasyDiscountCoupon}); } else { const couponHtml = getCouponOtpHtml(); document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.abhi_easyModalDynamicContent').innerHTML = couponHtml; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.abhi_closeEasyModal').style.display = 'none'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.confirmCouponOtp') .addEventListener('click', function (e) { e.preventDefault(); // disabling submit button to prevent multiple clicks. let cofirmCoupnOtpBtn = e.target; cofirmCoupnOtpBtn.disabled = true; cofirmCoupnOtpBtn.style.opacity = '0.5'; if (document.querySelector('#iframeID').contentWindow.document.body.querySelector('.couponOtpInput')) { otpParams.couponOtp = document.body?.querySelector('.couponOtpInput')?.value || document.querySelector('#iframeID').contentWindow.document.body?.querySelector('.couponOtpInput') ?.value; } confirmCouponOtp(otpParams) .then((res) => { cofirmCoupnOtpBtn.disabled = false; cofirmCoupnOtpBtn.style.opacity = '1'; }) .catch((error) => [console.log('confirmCouponOtp error', error)]); }); document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.resendCouponOtp') .addEventListener('click', function (e) { e.preventDefault(); resendCouponOtp(otpParams); }); document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.continueCheckoutCoupon') .addEventListener('click', function (e) { e.preventDefault(); unblockCoupon(otpParams) .then((res) => { location.reload(); }) .catch((error) => { showErrorMessage(error.message || 'Redemption Failed'); }); }); } showLoader(false); } }; const checkApiStatus = async () => { const settingsUrl = `/apps/ez/api/getAppSettings`; const appSettingsParams = { storeName: Shopify.shop, }; const currentThemeId = Shopify.theme.id; const appSettingsResponses = await makeAjaxRequest(settingsUrl, appSettingsParams); const appSettingsResponse = JSON.parse(appSettingsResponses); const isTestMode = appSettingsResponse.isTestMode; const testThemeId = appSettingsResponse.testThemeId; if (isTestMode && currentThemeId != testThemeId) { return; } const url = `/apps/ez/api/GetStoreDetails`; const data = { url: Shopify.shop, tag: 'fe', }; const responseData = await makeAjaxRequest(url, data); const response = JSON.parse(responseData); if (true) { // if (response.Status == "Active") { let mainDivForErContent = document.createElement('div'); mainDivForErContent.innerHTML = abhi_modalHtml; document.querySelector('#iframeID').contentWindow.document.body.appendChild(mainDivForErContent); document .querySelector('#iframeID') .contentWindow.document.body.querySelector('#myModal .abhi_closeEasyModal') .addEventListener('click', function (e) { document.querySelector('#iframeID').contentWindow.document.body.querySelector('#myModal').style.display = 'none'; }); localStorage.setItem( 'abhi_uiSetting', JSON.stringify({ Modal1: { Heading: response.Modal1.Heading, CustomMessage: response.Modal1.CustomMessage, SubmitButtonText: response.Modal1.SubmitButtonText, SubmitButtonColor: response.Modal1.SubmitButtonColor, CancelButtonText: response.Modal1.CancelButtonText, CancelButtonColor: response.Modal1.CancelButtonColor, RedeemPointsButtonColor: response.Modal1.RedeemPointsButtonColor, RedeemPointsButtonText: response.Modal1.RedeemPointsButtonText, ApplyCouponButtonColor: response.Modal1.ApplyCouponButtonColor, ApplyCouponButtonText: response.Modal1.ApplyCouponButtonText, }, ModalB: { Heading: response.ModalB.Heading, CancelButtonText: response.ModalB.CancelButtonText, CancelButtonColor: response.ModalB.CancelButtonColor, }, Modal2: { Heading: response.Modal2.Heading, SubmitButtonText: response.Modal2.SubmitButtonText, SubmitButtonColor: response.Modal2.SubmitButtonColor, CancelButtonText: response.Modal2.CancelButtonText, CancelButtonColor: response.Modal2.CancelButtonColor, }, Modal3: { Heading: response.Modal3.Heading, SubmitButtonText: response.Modal3.SubmitButtonText, SubmitButtonColor: response.Modal3.SubmitButtonColor, CancelButtonText: response.Modal3.CancelButtonText, CancelButtonColor: response.Modal3.CancelButtonColor, }, RedeemButton: { ButtonColor: response.ButtonColor, DomSelector: response.DomSelector, }, }) ); var customCss = document.createElement('style'); customCss.innerText = `${response.CustomCss}`; // document.querySelector("#iframeID").contentWindow.document.body.head.innerHTML = document.querySelector("#iframeID").contentWindow.document.body.head.innerHTML + customCss document.querySelector('#iframeID').contentWindow.document.head.appendChild(customCss); // document.querySelector(".abhi_easyPointModalBtn").addEventListener("click", function (e) { // e.preventDefault(); const uiSetting = JSON.parse(localStorage.getItem('abhi_uiSetting')); const newHtml = abhi_getModalHtml(response); document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.abhi_easyModalDynamicContent').innerHTML = newHtml; const customMessage = document.createElement('small'); customMessage.classList.add('customMessage'); customMessage.textContent = response.Modal1.CustomMessage; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.customMessageWrap') .appendChild(customMessage); document.querySelector('#iframeID').contentWindow.document.body.querySelector('#myModal').style.display = 'block'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.getAvailablePointsSubmit') .addEventListener('click', getAvailablePointsSubmit); // IF USER PRESS Enter document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.abhi_mobileInput') .addEventListener('keydown', function (event) { if (event.key === 'Enter') { getAvailablePointsSubmit; } }); document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.getAvailablePointsSubmit').style.backgroundColor = uiSetting.Modal1.RedeemPointsButtonColor + ' !important'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.getAvailablePointsSubmit').innerText = uiSetting.Modal1.RedeemPointsButtonText; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.applyCouponButton').style.backgroundColor = uiSetting.Modal1.ApplyCouponButtonColor + ' !important'; document.querySelector('#iframeID').contentWindow.document.body.querySelector('.applyCouponButton').innerText = uiSetting.Modal1.ApplyCouponButtonText; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.abhi_continueCheckoutSubmit').style.backgroundColor = uiSetting.Modal1.CancelButtonColor + ' !important'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.abhi_continueCheckoutSubmit').innerText = uiSetting.Modal1.CancelButtonText; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.applyCouponButton') .addEventListener('click', function () { document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.discountCouponInput').style.display = 'block'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.discountCouponInputValue').style.display = 'block'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.abhi_eazyRewardzFormGroup').style.marginBottom = '55px'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.applyCouponButton') .classList.add('redeemCouponSubmit'); const abhi_uiSetting = JSON.parse(localStorage.getItem('abhi_uiSetting')); document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.applyCouponButton').innerHTML = 'Submit'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.applyCouponButton').style.backgroundColor = abhi_uiSetting.Modal1.SubmitButtonColor; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.getAvailablePointsSubmit').style.display = 'none'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.redeemCouponSubmit') .addEventListener('click', function (e) { e.preventDefault(); let redeemCouponbtn = e.target; redeemCouponbtn.disabled = true; redeemCouponbtn.style.opacity = '0.5'; submitRedeemCouponOtp() .then((res) => { redeemCouponbtn.disabled = false; redeemCouponbtn.style.opacity = '1'; }) .catch((error) => { console.log('submitRedeemCouponOtp error', error); redeemCouponbtn.disabled = true; redeemCouponbtn.style.opacity = '1'; }); }); }); // }); // test code to check will this work document .querySelector('#iframeID') .contentWindow.document.body.querySelector('a[href$=availablePoints]') ?.addEventListener('click', function (e) { e.preventDefault(); const abhi_uiSetting = JSON.parse(localStorage.getItem('abhi_uiSetting')); const newHtml = abhi_getModalHtml(abhi_uiSetting); document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.abhi_easyModalDynamicContent').innerHTML = newHtml; document.querySelector('#iframeID').contentWindow.document.body.querySelector('.abhi_checkPointsButton').id = 'checkBalancePoint'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.getAvailablePointsSubmit').innerHTML = 'Submit'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.getAvailablePointsSubmit').style.backgroundColor = abhi_uiSetting.Modal1.SubmitButtonColor; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.applyCouponButton').style.display = 'none'; document.querySelector('#iframeID').contentWindow.document.body.querySelector('#myModal').style.display = 'block'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.getAvailablePointsSubmit') .addEventListener('click', getAvailablePointsSubmit); // IF USER PRESS Enter document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.abhi_mobileInput') .addEventListener('keydown', function (event) { if (event.key === 'Enter') { getAvailablePointsSubmit; } }); document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.availablePointsH2').innerHTML = 'Point Balance'; }); const identifier = `easyRewards${(Math.random() + 5).toString(36).substring(2)}`; if (!localStorage.identifier) { /* console.log( "NOOOOOTTTTTTTTTTT LOCALSTORAGE ITENTIFIER", localStorage.identifier ); */ localStorage.setItem('identifier', identifier); } } // return response }; const renderavailablePointDetails = (data, higherOrderParams) => { const abhi_uiSetting = JSON.parse(localStorage.getItem('abhi_uiSetting')); const html = abhi_getAvailablePointsHtml(data, abhi_uiSetting); document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.abhi_easyModalDynamicContent').innerHTML = html; if (!higherOrderParams.EasyId) { return showErrorMessage('Please Enter Mobile No'); } document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.abhi_redeemAvailablePoints') .addEventListener('click', async function (e) { e.preventDefault(); showLoader(true); // if (!document.querySelector(".abhi_mobileInput").value) { // // return showErrorMessage("Please Enter Mobile No.") // } const enteredAmount = document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.redeemPointsInput').value; const url = `/apps/ez/api/CheckForEasyPointsRedemption`; const cartDataJson = await fetch(`/cart.js`); const cartData = await cartDataJson.json(); const date = new Date().toString().split(' '); const aDate = `${date[2]} ${date[1]} ${date[3]}`; const postdata = { EasyId: higherOrderParams.EasyId, EasyPoints: enteredAmount * 1, Amount: cartData.total_price / 100, StoreName: Shopify.shop, PointRate: higherOrderParams.PointRate, TransactionCode: localStorage.identifier, RedemptionDate: aDate, }; const pointsRedeem = enteredAmount; const responses = await makeAjaxRequest(url, postdata); const response = JSON.parse(responses); if (response.ReturnCode != '0') { showErrorMessage(response.ReturnMessage); return; } showLoader(false); higherOrderParams.PointValue = response.CashWorthPoints; higherOrderParams.EasyPoints = response.EasyPoints; renderOtpHtml(data, higherOrderParams, pointsRedeem); }); reloadOnCancel(); }; const abhi_getConfirmOtpHtml = (abhi_uiSetting) => { return `

${abhi_uiSetting.Modal3.Heading}

`; }; const showPointBalance = (data) => { const abhi_uiSetting = JSON.parse(localStorage.getItem('abhi_uiSetting')); const checkAvailablePointsHtml = `

${abhi_uiSetting.ModalB.Heading}

Balance Points : ${data.AvailablePoints}


`; document.querySelector('.abhi_easyModalDynamicContent').innerHTML = checkAvailablePointsHtml; document.querySelector('.closeAvailablePointModal').addEventListener('click', function (e) { location.reload(); }); document.querySelector('.abhi_modal-content').classList.add('abhi_mobileScreen'); // document.querySelector('.abhi_modal-content').style.width = '55%'; }; const getAvailablePointsSubmit = async (e) => { e.preventDefault(); showLoader(true); const enteredMobileNo = document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.abhi_mobileInput').value; localStorage.setItem('id', enteredMobileNo); const data = { EasyId: enteredMobileNo, StoreName: Shopify.shop, }; const url = `/apps/ez/api/CustomerAvailablePoints`; // const url2 = `https://easyrewards.herokuapp.com/api/CustomerAvailablePoints` const responses = await makeAjaxRequest(url, data); const response = JSON.parse(responses); if (response.ReturnCode !== '0') { // showErrorMessage(response.ReturnMessage); showErrorMessage('No Benefits to redeem. Complete the transaction to earn loyalty benefits.'); return; } showLoader(false); const higherOrderParams = { EasyId: enteredMobileNo, PointRate: response.PointRate, TotalPointValue: response.PointValue, PartnerName: response.PartnerName, }; if (!localStorage.identifier) { const identifier = `easyRewards${(Math.random() + 5).toString(36).substring(2)}`; localStorage.setItem('identifier', identifier); } if (e.target.id == 'checkBalancePoint') { showPointBalance(response); } else { renderavailablePointDetails(response, higherOrderParams); } }; async function allFunctionality() { await checkApiStatus(); const getCouponOtpHtml = () => { return `

Enter OTP

`; }; const confirmCouponOtp = async (data) => { const url = `/apps/ez/api/ConfirmCouponOtp`; const couponOtp = document.querySelector('.couponOtpInput').value; const params = { ...data, couponOtp, }; const responses = await makeAjaxRequest(url, data); const response = JSON.parse(responses); const dataa = { attributes: { EasyId: data.EasyId, RequestID: data.RequestID, OrderTypeId: 'easyRewardsDiscountCoupon', TempCouponCode: data.CouponCode, }, }; const appendCart = await makeAjaxRequest(`/cart.js`, dataa); if (response.ReturnCode == '0') { const cartForm = document.querySelector("form[action='/cart']"); let input = document.createElement('input'); input.type = 'hidden'; input.name = 'discount'; input.value = data.DiscountCode; input.class = 'easyReward-discount'; // container.appendChild(input); const shopName = checkLocation(); const url = shopName.split('.'); const domain = `${url[url.length - 2]}.${url[url.length - 1]}`; const DB_domain = `${url[0]}`; const discountURL = `https://www.${domain}/discount/${coupon}`; const TestingURL = `https://${DB_domain}.myshopify.com/discount/${coupon}`; try { await fetch(domain == 'myshopify.com' ? TestingURL : discountURL, { mode: 'cors', headers: { 'Access-Control-Allow-Origin': ' * ', }, }) .then((response) => response.text()) // response.json()s .then((result) => console.log(result, 'inside apply coupon success')); } catch (error) { console.log(error); } const successMessage = `

Discount Applied !

`; document.querySelector('#cart-errors').insertAdjacentHTML('afterend', successMessage); document.querySelector('#myModal').style.display = 'none'; } else { showErrorMessage(response.ReturnMessage); } }; const resendCouponOtp = async (data) => { const url = `/apps/ez/api/ResendCouponOtp`; const params = { EasyId: data.EasyId, TransactionCode: data.CouponCode, StoreName: data.StoreName, }; const response = await makeAjaxRequest(url, params); }; const unblockCoupon = async (data) => { const url = `/apps/ez/api/UnblockCoupon`; const responses = await makeAjaxRequest(url, data); const response = JSON.parse(responses); if (response.ReturnCode == '0') { // alert("stop") location.reload(); } else { showErrorMessage(response.ReturnMessage); } }; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.getAvailablePointsSubmit') .addEventListener('click', getAvailablePointsSubmit); // IF USER PRESS Enter document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.abhi_mobileInput') .addEventListener('keydown', function (event) { if (event.key === 'Enter') { getAvailablePointsSubmit; } }); document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.abhi_closeEasyModal') .addEventListener('click', closeModal); document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.applyCouponButton') .addEventListener('click', function () { document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.discountCouponInputValue').style.display = 'block'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.discountCouponInput').style.display = 'block'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.abhi_eazyRewardzFormGroup').style.marginBottom = '55px'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.applyCouponButton') .classList.add('redeemCouponSubmit'); const abhi_uiSetting = JSON.parse(localStorage.getItem('abhi_uiSetting')); document.querySelector('#iframeID').contentWindow.document.body.querySelector('.applyCouponButton').innerHTML = 'Submit'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.applyCouponButton').style.backgroundColor = abhi_uiSetting.Modal1.SubmitButtonColor; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.getAvailablePointsSubmit').style.display = 'none'; document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.redeemCouponSubmit') .addEventListener('click', async function (e) { e.preventDefault(); /* console.log("redeemCouponSubmit class triggered OnClick") */ // const redeem = await submitRedeemCouponOtp(); }); }); document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.abhi_continueCheckoutSubmit') .addEventListener('click', function (e) { // fetchData() if (localStorage.getItem('ub')?.length > 1) { unblockCoupon(JSON.parse(localStorage.getItem('ub'))) .then((res) => { // console.log("coupon Released"); localStorage.removeItem('ub'); }) .catch((err) => { console.log('error while releasing coupon:', err); }); } else { location.reload(); } }); document .querySelector('#iframeID') .contentWindow.document.body.querySelector('.closeModalAndReleasePoints') .addEventListener('click', async function (e) { const response = await releasePoints(); // const response = JSON.parse(responses); if (response.ReturnCode === '0') { location.reload(); } else { location.reload(); } }); }

Sketching and Drawing Pencils for Beginners. (2024)
Top Articles
Latest Posts
Article information

Author: Pres. Lawanda Wiegand

Last Updated:

Views: 6339

Rating: 4 / 5 (51 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Pres. Lawanda Wiegand

Birthday: 1993-01-10

Address: Suite 391 6963 Ullrich Shore, Bellefort, WI 01350-7893

Phone: +6806610432415

Job: Dynamic Manufacturing Assistant

Hobby: amateur radio, Taekwondo, Wood carving, Parkour, Skateboarding, Running, Rafting

Introduction: My name is Pres. Lawanda Wiegand, I am a inquisitive, helpful, glamorous, cheerful, open, clever, innocent person who loves writing and wants to share my knowledge and understanding with you.