/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // Set to true to stop pinging the server for tx status var stopPaymentCheck = false; $("#payment-popup").on("popup:close", function () { stopPaymentCheck = true; }); $(".numpad-button").on("click", function () { var val = $(this).data("value"); if (val == "C") { $("#amount-box").val(""); return; } $("#amount-box").val($("#amount-box").val() + val); }); $("#showcodebtn").click(function () { var amount = $("#amount-box").val() * 1.0; if (amount <= 0) { app.dialog.alert("Please specify an amount.", "Error"); return; } else if (amount > 999.99) { app.dialog.alert("Please specify an amount less than $999.99.", "Error"); return; } app.preloader.show(); makeQrCode(amount, function (ok, msg) { app.preloader.hide(); if (!ok) { app.dialog.alert(msg, "Error"); } else { app.popup.open($("#payment-popup")); } }); }); function makeQrCode(amount, callback) { callAPI("gettxcode", { key: localStorage.getItem("key"), amount: amount }, function (data) { var typeNumber = 4; var errorCorrectionLevel = 'L'; var qr = qrcode(typeNumber, errorCorrectionLevel); qr.addData(SETTINGS['webapp_url'] + '?sendto=' + data.txcode + "&amount=" + data.amount); qr.make(); var svg = qr.createSvgTag({ margin: 6, scalable: true }); var base64 = window.btoa(svg); $("#qrcode").attr("src", 'data:image/svg+xml;base64,' + base64); $("#pay-amount").text(data.amount.toFixed(2)); $("#paid-amount").text(data.amount.toFixed(2)); app.preloader.hide(); checkPaymentStatus(data.txcode); callback(true); }, function (msg) { callback(false, msg); }); } function checkPaymentStatus(txcode) { if (stopPaymentCheck) { stopPaymentCheck = false; return; } callAPI("gettxstatus", { key: localStorage.getItem("key"), txcode: txcode }, function (data) { if (data.complete == true) { app.popup.close($("#payment-popup")); app.popup.open($("#paid-popup")); $("#amount-box").val(""); } else { setTimeout(function () { checkPaymentStatus(txcode); }, 15 * 100); } }, function (msg) { app.popup.close($("#payment-popup")); app.popup.close($("#paid-popup")); app.dialog.alert(msg, "Error"); }); }