function esc(input) { return ('' + input) /* Forces the conversion to string. */ .replace(/&/g, '&') /* This MUST be the 1st replacement. */ .replace(/'/g, ''') /* The 4 other predefined entities, required. */ .replace(/"/g, '"') .replace(//g, '>') /* You may add other replacements here for HTML only (but it's not necessary). Or for XML, only if the named entities are defined in its DTD. */ ; } function unesc(input) { return ('' + input) .replace(/&/g, '&') .replace(/</g, '<') .replace(/>/g, '>') } Vue.use(VeeValidate); var dictionary = { en: { attributes: { price: 'Price', checkoutDesc: 'Checkout Description', orderId: 'Order Id', serverIpn: 'Server IPN', notifyEmail: 'Send Email Notifications', browserRedirect: 'Browser Redirect', payButtonImageUrl: "Pay Button Image Url" } } }; VeeValidate.Validator.localize(dictionary); function getStyles (styles) { return document.getElementById(styles).innerHTML.replace(/\s{2}/g, '').trim() + '\n' } function getScripts(srvModel) { const scripts = [] if (srvModel.useModal) { const modal = document.getElementById('template-modal') scripts.push(unesc(modal.innerHTML)) } if (srvModel.buttonType == '1') { const priceButtons = document.getElementById('template-price-buttons') const priceInput = document.getElementById('template-price-input') scripts.push(unesc(priceButtons.innerHTML)) scripts.push(unesc(priceInput.innerHTML)) } if (srvModel.buttonType == '2') { const priceSlider = document.getElementById('template-price-slider') const priceInput = document.getElementById('template-price-input') scripts.push(unesc(priceSlider.innerHTML)) scripts.push(unesc(priceInput.innerHTML)) } return scripts } function inputChanges(vueApp, event, buttonSize) { if (buttonSize !== null && buttonSize !== undefined) { srvModel.buttonSize = buttonSize; } let width = '209px'; let height = '57px'; let widthInput = '3em'; if (srvModel.buttonSize === 0) { width = '146px'; widthInput = '2em'; height = '40px'; } else if (srvModel.buttonSize === 1) { width = '168px'; height = '46px'; } else if (srvModel.buttonSize === 2) { width = '209px'; height = '57px'; } let actionUrl = 'api/v1/invoices'; let priceInputName = 'price'; let app = srvModel.appIdEndpoint? srvModel.apps.find(value => value.id === srvModel.appIdEndpoint ): null; let allowCurrencySelection = true; let allowDefaultPaymentMethodSelection = true; if (app) { if (app.appType.toLowerCase() === 'pointofsale') { actionUrl = `apps/${app.id}/pos`; } else if (app.appType.toLowerCase() === 'crowdfund') { actionUrl = `apps/${app.id}/crowdfund`; } else { actionUrl = 'api/v1/invoices'; app = null; } if (actionUrl !== 'api/v1/invoices') { priceInputName = 'amount'; allowCurrencySelection = false; allowDefaultPaymentMethodSelection = false; srvModel.useModal = false; } } var html = // Styles getStyles('template-paybutton-styles') + (srvModel.buttonType == '2' ? getStyles('template-slider-styles') : '') + // Form '
'; // Scripts const scripts = getScripts(srvModel); const code = html + (scripts.length ? `\n` : '') $("#mainCode").text(code).html(); const preview = document.getElementById('preview'); preview.innerHTML = html; scripts.forEach(snippet => { // script needs to be inserted as node, otherwise it won't get executed const script = document.createElement('script') script.innerHTML = snippet preview.appendChild(script) }) const form = preview.querySelector("form"); const formData = new FormData(form); let url = new URL(form.getAttribute("action")); formData.forEach((value, key) => { if (key !== "jsonResponse") { url.searchParams.append(key, value); } }); url = url.href; vueApp.previewLink = url; if (window.lnurlEndpoint){ let lnurlResult = lnurlEndpoint + "?"; if (srvModel.currency){ lnurlResult += `¤cy=${srvModel.currency}`; } if (srvModel.price){ lnurlResult += `&amount=${srvModel.price}`; } if (srvModel.orderId){ lnurlResult += `&orderId=${srvModel.orderId}`; } lnurlResult= lnurlResult.replace("?&", "?"); vueApp.lnurlLink = lnurlResult; } $('pre code').each(function (i, block) { hljs.highlightBlock(block); }); return html; } function addInput(name, value) { return ` \n`; } function addPlusMinusButton(type, step, min, max) { step = step === "any" ? 1 : step; min = min == null ? 1 : parseInt(min); max = max == null ? null : parseInt(max); return ` \n`; } function addInputPrice(name, price, widthInput, min = 0, max = 'none', step = 'any') { if (!price) price = min return ` \n`; } function addSlider(price, min, max, step, width) { if (!price) price = min return ` \n`; } function addSelectCurrency(currency) { // Remove all non-alphabet characters from input string and uppercase it for display const safeCurrency = currency.replace(/[^a-z]/gi, '').toUpperCase(); const defaultCurrencies = ['USD', 'GBP', 'EUR', 'BTC']; const options = defaultCurrencies.map(c => ` `); // If user provided a currency not in our default currencies list, add it to the top of the options as a selected option if (defaultCurrencies.indexOf(safeCurrency) === -1) { options.unshift(` `) } return ` \n` }