2018-08-22 11:10:46 +02:00
|
|
|
$(function () {
|
|
|
|
inputChanges();
|
|
|
|
|
|
|
|
// Clipboard Copy
|
|
|
|
new Clipboard('#copyCode', {
|
|
|
|
text: function (trigger) {
|
|
|
|
$(".copyLabelPopup").show().delay(1000).fadeOut(500);
|
2018-08-23 11:55:29 +09:00
|
|
|
return inputChanges();
|
2018-08-22 11:10:46 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-08-23 11:55:29 +09:00
|
|
|
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, '<')
|
|
|
|
.replace(/>/g, '>')
|
|
|
|
/*
|
2019-10-29 20:59:28 +01:00
|
|
|
You may add other replacements here for HTML only
|
2018-08-23 11:55:29 +09:00
|
|
|
(but it's not necessary).
|
|
|
|
Or for XML, only if the named entities are defined in its DTD.
|
|
|
|
*/
|
2019-04-03 21:43:53 +02:00
|
|
|
;
|
2018-08-23 11:55:29 +09:00
|
|
|
}
|
|
|
|
|
2018-08-22 11:10:46 +02:00
|
|
|
Vue.use(VeeValidate);
|
2019-06-25 21:01:37 +02:00
|
|
|
var dictionary = {
|
2018-08-22 11:10:46 +02:00
|
|
|
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 inputChanges(event, buttonSize) {
|
2018-08-23 11:55:29 +09:00
|
|
|
if (buttonSize !== null && buttonSize !== undefined) {
|
2018-08-22 11:10:46 +02:00
|
|
|
srvModel.buttonSize = buttonSize;
|
|
|
|
}
|
|
|
|
|
2019-04-03 21:43:53 +02:00
|
|
|
var width = "209px";
|
|
|
|
var widthInput = "3em";
|
|
|
|
if (srvModel.buttonSize === 0) {
|
|
|
|
width = "146px";
|
|
|
|
widthInput = "2em";
|
2019-07-31 15:58:04 +02:00
|
|
|
} else if (srvModel.buttonSize === 1 ) {
|
2019-04-03 21:43:53 +02:00
|
|
|
width = "168px";
|
|
|
|
} else if (srvModel.buttonSize === 2) {
|
|
|
|
width = "209px";
|
|
|
|
}
|
2019-10-29 20:59:28 +01:00
|
|
|
var html =
|
|
|
|
'<style>\n' +
|
|
|
|
' .btcpay-form { display: inline-flex; align-items: center; justify-content: center; }\n' +
|
|
|
|
' .btcpay-form--inline { flex-direction: row; }\n' +
|
|
|
|
' .btcpay-form--block { flex-direction: column; }\n' +
|
|
|
|
' .btcpay-form--inline .submit { margin-left: 15px; }\n' +
|
|
|
|
' .btcpay-form--block select { margin-bottom: 10px; }\n' +
|
|
|
|
' .btcpay-form .btcpay-custom { display: flex; align-items: center; justify-content: center; }\n' +
|
|
|
|
' .btcpay-form .plus-minus { cursor:pointer; font-size:25px; line-height: 25px; background: rgba(0,0,0,.1); height: 30px; width: 45px; border:none; border-radius: 60px; margin: auto; }\n' +
|
|
|
|
' .btcpay-form select { -moz-appearance: none; -webkit-appearance: none; appearance: none; background: transparent; border:1px solid transparent; display: block; padding: 1px; margin-left: auto; margin-right: auto; font-size: 11px; cursor: pointer; }\n' +
|
|
|
|
' .btcpay-form select:hover { border-color: #ccc; }\n' +
|
|
|
|
' #btcpay-input-price { border: none; box-shadow: none; -mox-appearance: none; -webkit-appearance: none; text-align: center; font-size: 25px; margin: auto; border-radius: 5px; line-height: 35px; background: #fff; }\n' +
|
|
|
|
'</style>\n' +
|
|
|
|
'<form method="POST" action="' + esc(srvModel.urlRoot) + 'api/v1/invoices" class="btcpay-form btcpay-form--' + (srvModel.fitButtonInline ? 'inline' : 'block') +'">\n' +
|
|
|
|
addInput("storeId", srvModel.storeId);
|
|
|
|
|
|
|
|
if (srvModel.checkoutDesc) html += addInput("checkoutDesc", srvModel.checkoutDesc);
|
|
|
|
|
|
|
|
if (srvModel.orderId) html += addInput("orderId", srvModel.orderId);
|
|
|
|
|
|
|
|
if (srvModel.serverIpn) html += addInput("serverIpn", srvModel.serverIpn);
|
|
|
|
|
|
|
|
if (srvModel.browserRedirect) html += addInput("browserRedirect", srvModel.browserRedirect);
|
2019-04-03 21:43:53 +02:00
|
|
|
|
2019-10-29 20:59:28 +01:00
|
|
|
if (srvModel.notifyEmail) html += addInput("notifyEmail", srvModel.notifyEmail);
|
|
|
|
|
|
|
|
if (srvModel.checkoutQueryString) html += addInput("checkoutQueryString", srvModel.checkoutQueryString);
|
|
|
|
|
|
|
|
// Fixed amount: Add price and currency as hidden inputs
|
2019-04-03 21:43:53 +02:00
|
|
|
if (srvModel.buttonType == 0) {
|
2019-10-29 20:59:28 +01:00
|
|
|
html += addInput("price", srvModel.price);
|
|
|
|
html += addInput("currency", srvModel.currency);
|
2019-04-03 21:43:53 +02:00
|
|
|
}
|
2019-10-29 20:59:28 +01:00
|
|
|
// Custom amount
|
2019-04-03 21:43:53 +02:00
|
|
|
else if (srvModel.buttonType == 1) {
|
2019-10-29 20:59:28 +01:00
|
|
|
html += ' <div>\n <div class="btcpay-custom">\n';
|
2019-07-31 15:58:04 +02:00
|
|
|
|
2019-10-29 20:59:28 +01:00
|
|
|
if (!srvModel.simpleInput) html += addPlusMinusButton("-");
|
|
|
|
|
|
|
|
html += ' ' + addInputPrice(srvModel.price, widthInput, "", srvModel.simpleInput? "number": null, srvModel.min, srvModel.max, srvModel.step);
|
|
|
|
|
|
|
|
if (!srvModel.simpleInput) html += addPlusMinusButton("+");
|
|
|
|
|
|
|
|
html += ' </div>\n';
|
|
|
|
html += addSelectCurrency(srvModel.currency);
|
|
|
|
html += ' </div>\n';
|
2019-04-03 21:43:53 +02:00
|
|
|
}
|
2019-10-29 20:59:28 +01:00
|
|
|
// Slider
|
2019-04-04 20:56:12 +02:00
|
|
|
else if (srvModel.buttonType == 2) {
|
2019-10-29 20:59:28 +01:00
|
|
|
html += ' <div>\n';
|
2019-04-04 20:56:12 +02:00
|
|
|
html += addInputPrice(srvModel.price, width, 'onchange="document.querySelector(\'#btcpay-input-range\').value = document.querySelector(\'#btcpay-input-price\').value"');
|
2019-10-29 20:59:28 +01:00
|
|
|
html += addSelectCurrency(srvModel.currency);
|
2019-04-06 15:02:02 +02:00
|
|
|
html += addSlider(srvModel.price, srvModel.min, srvModel.max, srvModel.step, width);
|
2019-10-29 20:59:28 +01:00
|
|
|
html += ' </div>\n';
|
2018-08-22 11:10:46 +02:00
|
|
|
}
|
|
|
|
|
2019-10-29 20:59:28 +01:00
|
|
|
html += ' <input type="image" class="submit" name="submit" src="' + esc(srvModel.payButtonImageUrl) + '" style="width:' + width + '" alt="Pay with BtcPay, Self-Hosted Bitcoin Payment Processor">';
|
2018-08-22 11:10:46 +02:00
|
|
|
|
2018-08-23 11:55:29 +09:00
|
|
|
html += '\n</form>';
|
2018-08-22 11:10:46 +02:00
|
|
|
|
2018-08-23 11:55:29 +09:00
|
|
|
$("#mainCode").text(html).html();
|
|
|
|
$("#preview").html(html);
|
2018-08-22 11:10:46 +02:00
|
|
|
|
|
|
|
$('pre code').each(function (i, block) {
|
|
|
|
hljs.highlightBlock(block);
|
|
|
|
});
|
|
|
|
|
|
|
|
return html;
|
|
|
|
}
|
|
|
|
|
2019-10-29 20:59:28 +01:00
|
|
|
function addInput(name, value) {
|
|
|
|
return ' <input type="hidden" name="' + esc(name) + '" value="' + esc(value) + '" />\n';
|
2018-08-22 11:10:46 +02:00
|
|
|
}
|
|
|
|
|
2019-04-03 21:43:53 +02:00
|
|
|
function addPlusMinusButton(type) {
|
2019-10-29 20:59:28 +01:00
|
|
|
return ' <button class="plus-minus" onclick="event.preventDefault(); var price = parseInt(document.querySelector(\'#btcpay-input-price\').value); if (\'' + type + '\' == \'-\' && (price - 1) < 1) { return; } document.querySelector(\'#btcpay-input-price\').value = parseInt(document.querySelector(\'#btcpay-input-price\').value) ' + type + ' 1;">' + type + '</button>\n';
|
2019-04-03 21:43:53 +02:00
|
|
|
}
|
2019-04-04 20:56:12 +02:00
|
|
|
|
2019-07-31 15:58:04 +02:00
|
|
|
function addInputPrice(price, widthInput, customFn, type, min, max, step) {
|
2019-10-29 20:59:28 +01:00
|
|
|
return ' <input id="btcpay-input-price" name="price" type="' + (type || "text") + '" min="' + (min || 0) + '" max="' + (max || "none") + '" step="' + (step || "any") + '" value="' + price + '" style="width: ' + widthInput + ';" oninput="event.preventDefault();isNaN(event.target.value) || event.target.value <= 0 ? document.querySelector(\'#btcpay-input-price\').value = ' + price + ' : event.target.value" ' + (customFn || '') + ' />\n';
|
2019-04-04 20:56:12 +02:00
|
|
|
}
|
2019-04-04 21:32:16 +02:00
|
|
|
|
2019-10-29 20:59:28 +01:00
|
|
|
function addSelectCurrency(currency) {
|
|
|
|
return ' <select name="currency">\n' +
|
|
|
|
['USD', 'GBP', 'EUR', 'BTC'].map(c => ' <option value="' + c + '"' + (c === currency ? ' selected' : '') + '>' + c + '</option>').join('\n') + '\n' +
|
|
|
|
' </select>\n'
|
2019-04-06 15:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function addSlider(price, min, max, step, width) {
|
|
|
|
var input = document.getElementById('template-input-slider').innerHTML.trim();
|
|
|
|
input = input.replace("PRICE", price);
|
|
|
|
input = input.replace("MIN", min);
|
|
|
|
input = input.replace("MAX", max);
|
|
|
|
input = input.replace("STEP", step);
|
|
|
|
input = input.replace("WIDTH", width);
|
2019-10-29 20:59:28 +01:00
|
|
|
return ' ' + input + '\n';
|
2019-04-04 21:32:16 +02:00
|
|
|
}
|