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, '>')
|
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
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);
|
|
|
|
const 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 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";
|
|
|
|
} else if (srvModel.buttonSize === 1) {
|
|
|
|
width = "168px";
|
|
|
|
} else if (srvModel.buttonSize === 2) {
|
|
|
|
width = "209px";
|
|
|
|
}
|
|
|
|
|
2018-09-08 14:53:11 +09:00
|
|
|
var html = '<form method="POST" action="' + esc(srvModel.urlRoot) + 'api/v1/invoices">';
|
|
|
|
html += addinput("storeId", srvModel.storeId);
|
2019-04-03 21:43:53 +02:00
|
|
|
|
2019-04-04 20:56:12 +02:00
|
|
|
// Add price as hidden only if it's a fixed amount (srvModel.buttonType = 0)
|
2019-04-03 21:43:53 +02:00
|
|
|
if (srvModel.buttonType == 0) {
|
|
|
|
html += addinput("price", srvModel.price);
|
|
|
|
}
|
|
|
|
else if (srvModel.buttonType == 1) {
|
|
|
|
html += '\n <div style="text-align:center;width:' + width + '">';
|
2019-04-04 21:32:16 +02:00
|
|
|
html += '<div>';
|
2019-04-03 21:43:53 +02:00
|
|
|
html += addPlusMinusButton("-");
|
2019-04-04 20:56:12 +02:00
|
|
|
html += addInputPrice(srvModel.price, widthInput, "");
|
2019-04-03 21:43:53 +02:00
|
|
|
html += addPlusMinusButton("+");
|
|
|
|
html += '</div>';
|
2019-04-04 21:32:16 +02:00
|
|
|
html += addSelectCurrency();
|
|
|
|
html += '</div>';
|
2019-04-03 21:43:53 +02:00
|
|
|
}
|
2019-04-04 20:56:12 +02:00
|
|
|
else if (srvModel.buttonType == 2) {
|
|
|
|
html += '\n <div style="text-align:center;width:' + width + '">';
|
|
|
|
|
|
|
|
// Input price
|
|
|
|
html += addInputPrice(srvModel.price, width, 'onchange="document.querySelector(\'#btcpay-input-range\').value = document.querySelector(\'#btcpay-input-price\').value"');
|
2019-04-04 21:32:16 +02:00
|
|
|
html += addSelectCurrency();
|
2019-04-04 20:56:12 +02:00
|
|
|
// Slider
|
|
|
|
html += '<input class="btcpay-input-range" id="btcpay-input-range" value="' + srvModel.price + '" type="range" min="' + srvModel.min + '" max="' + srvModel.max + '" step="' + srvModel.step + '" style="width:' + width + ';margin-bottom:15px;"' +
|
|
|
|
'oninput="document.querySelector(\'#btcpay-input-price\').value = document.querySelector(\'#btcpay-input-range\').value" />';
|
|
|
|
|
|
|
|
// Slider style
|
|
|
|
html += '<style type="text/css">input[type=range].btcpay-input-range { -webkit-appearance: none; width: 100%; margin: 9.45px 0; } input[type=range].btcpay-input-range:focus { outline: none; } input[type=range].btcpay-input-range::-webkit-slider-runnable-track { width: 100%; height: 3.1px; cursor: pointer; box-shadow: 0px 0px 1.7px #002200, 0px 0px 0px #003c00; background: #f3f3f3; border-radius: 1px; border: 0px solid rgba(24, 213, 1, 0); } input[type=range].btcpay-input-range::-webkit-slider-thumb { box-shadow: 0px 0px 3.7px rgba(0, 170, 0, 0), 0px 0px 0px rgba(0, 195, 0, 0); border: 2.5px solid #cedc21; height: 22px; width: 23px; border-radius: 12px; background: #0f3723; cursor: pointer; -webkit-appearance: none; margin-top: -9.45px; } input[type=range].btcpay-input-range:focus::-webkit-slider-runnable-track { background: #ffffff; } input[type=range].btcpay-input-range::-moz-range-track { width: 100%; height: 3.1px; cursor: pointer; box-shadow: 0px 0px 1.7px #002200, 0px 0px 0px #003c00; background: #f3f3f3; border-radius: 1px; border: 0px solid rgba(24, 213, 1, 0); } input[type=range].btcpay-input-range::-moz-range-thumb { box-shadow: 0px 0px 3.7px rgba(0, 170, 0, 0), 0px 0px 0px rgba(0, 195, 0, 0); border: 2.5px solid #cedc21; height: 22px; width: 23px; border-radius: 12px; background: #0f3723; cursor: pointer; } input[type=range].btcpay-input-range::-ms-track { width: 100%; height: 3.1px; cursor: pointer; background: transparent; border-color: transparent; color: transparent; } input[type=range].btcpay-input-range::-ms-fill-lower { background: #e6e6e6; border: 0px solid rgba(24, 213, 1, 0); border-radius: 2px; box-shadow: 0px 0px 1.7px #002200, 0px 0px 0px #003c00; } input[type=range].btcpay-input-range::-ms-fill-upper { background: #f3f3f3; border: 0px solid rgba(24, 213, 1, 0); border-radius: 2px; box-shadow: 0px 0px 1.7px #002200, 0px 0px 0px #003c00; } input[type=range].btcpay-input-range::-ms-thumb { box-shadow: 0px 0px 3.7px rgba(0, 170, 0, 0), 0px 0px 0px rgba(0, 195, 0, 0); border: 2.5px solid #cedc21; height: 22px; width: 23px; border-radius: 12px; background: #0f3723; cursor: pointer; height: 3.1px; } input[type=range].btcpay-input-range:focus::-ms-fill-lower { background: #f3f3f3; } input[type=range].btcpay-input-range:focus::-ms-fill-upper { background: #ffffff; }</style>';
|
|
|
|
html += '</div>';
|
|
|
|
}
|
2019-04-03 21:43:53 +02:00
|
|
|
|
2018-08-22 11:10:46 +02:00
|
|
|
if (srvModel.currency) {
|
|
|
|
html += addinput("currency", srvModel.currency);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
if (srvModel.notifyEmail) {
|
|
|
|
html += addinput("notifyEmail", srvModel.notifyEmail);
|
|
|
|
}
|
|
|
|
|
2018-08-23 11:55:29 +09:00
|
|
|
html += '\n <input type="image" src="' + esc(srvModel.payButtonImageUrl) + '" name="submit" 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
function addinput(name, value) {
|
2018-08-23 11:55:29 +09:00
|
|
|
var html = '\n <input type="hidden" name="' + esc(name) + '" value="' + esc(value) + '" />';
|
2018-08-22 11:10:46 +02:00
|
|
|
return html;
|
|
|
|
}
|
|
|
|
|
2019-04-03 21:43:53 +02:00
|
|
|
function addPlusMinusButton(type) {
|
|
|
|
var button = '<button style="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;" onclick="event.preventDefault();document.querySelector(\'#btcpay-input-price\').value = parseInt(document.querySelector(\'#btcpay-input-price\').value) TYPE 1;">TYPE</button>';
|
|
|
|
if (type === "+") {
|
|
|
|
return button.replace(/TYPE/g, '+');
|
|
|
|
} else {
|
|
|
|
return button.replace(/TYPE/g, '-');
|
|
|
|
}
|
|
|
|
}
|
2019-04-04 20:56:12 +02:00
|
|
|
|
|
|
|
function addInputPrice(price, widthInput, customFn) {
|
|
|
|
var input = '<input type="text" id="btcpay-input-price" name="price" value="' + price + '" style="' +
|
|
|
|
'border:none;background-image:none;background-color:transparent;-webkit-box-shadow:none;-moz-box-shadow:none;-webkit-appearance: none;' + // Reset css
|
2019-04-04 21:32:16 +02:00
|
|
|
'width:' + widthInput + ';text-align:center;font-size:25px;margin:auto;border-radius:5px;line-height:35px;background:#fff;"' + // Custom css
|
2019-04-04 20:56:12 +02:00
|
|
|
'oninput="event.preventDefault();isNaN(event.target.value) ? document.querySelector(\'#btcpay-input-price\').value = ' + price + ' : event.target.value" CUSTOM />';
|
|
|
|
if (customFn) {
|
|
|
|
return input.replace("CUSTOM", customFn);
|
|
|
|
}
|
|
|
|
return input.replace("CUSTOM", "");
|
|
|
|
}
|
2019-04-04 21:32:16 +02:00
|
|
|
|
|
|
|
function addSelectCurrency() {
|
|
|
|
return '<select onchange="document.querySelector(\'input[type = hidden][name = currency]\').value = event.target.value" style="-webkit-appearance: none; border: 0; display: block; padding: 0 3em; margin: auto auto 5px auto; font-size: 11px; background: 0 0; cursor: pointer;">' +
|
|
|
|
'<option value="USD">USD</option>' +
|
|
|
|
'<option value="GBP">GBP</option>' +
|
|
|
|
'<option value="EUR">EUR</option>' +
|
|
|
|
'<option value="BTC">BTC</option>' +
|
|
|
|
'</select>';
|
|
|
|
}
|