2015-12-25 22:42:14 +01:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
|
|
|
(C) 2015 GNUnet e.V.
|
|
|
|
|
|
|
|
TALER is free software; you can redistribute it and/or modify it under the
|
|
|
|
terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; either version 3, or (at your option) any later version.
|
|
|
|
|
|
|
|
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
2016-01-10 20:07:42 +01:00
|
|
|
/// <reference path="../lib/decl/handlebars/handlebars.d.ts" />
|
2015-12-16 10:45:16 +01:00
|
|
|
"use strict";
|
2016-01-10 20:07:42 +01:00
|
|
|
var url = URI(document.location.href);
|
|
|
|
var query = URI.parseQuery(url.query());
|
|
|
|
var $_ = function (x) { return document.getElementById(x); };
|
2015-12-16 10:45:16 +01:00
|
|
|
function renderContract(contract) {
|
2016-01-10 20:07:42 +01:00
|
|
|
var showAmount = document.getElementById("show-amount");
|
2015-12-16 10:45:16 +01:00
|
|
|
$_('merchant-name').innerText = contract.merchant.name;
|
|
|
|
}
|
|
|
|
function clone(obj) {
|
|
|
|
// This is faster than it looks ...
|
|
|
|
return JSON.parse(JSON.stringify(obj));
|
|
|
|
}
|
|
|
|
Handlebars.registerHelper('prettyAmount', function (amount) {
|
2016-01-10 20:07:42 +01:00
|
|
|
var v = amount.value + amount.fraction / 10e6;
|
2015-12-16 10:45:16 +01:00
|
|
|
return v.toFixed(2) + " " + amount.currency;
|
|
|
|
});
|
2016-01-10 20:07:42 +01:00
|
|
|
document.addEventListener("DOMContentLoaded", function (e) {
|
|
|
|
var offer = JSON.parse(query.offer);
|
2015-12-17 13:30:34 +01:00
|
|
|
console.dir(offer);
|
2016-01-10 20:07:42 +01:00
|
|
|
var source = $_("contract-template").innerHTML;
|
|
|
|
var template = Handlebars.compile(source);
|
2015-12-20 20:05:06 +01:00
|
|
|
$_("render-contract").innerHTML = template(offer.contract);
|
2016-01-10 20:07:42 +01:00
|
|
|
document.getElementById("confirm-pay").addEventListener("click", function (e) {
|
2015-12-18 01:30:22 +01:00
|
|
|
console.log("Query:", JSON.stringify(query));
|
2016-01-10 20:07:42 +01:00
|
|
|
var d = {
|
2015-12-18 01:30:22 +01:00
|
|
|
offer: JSON.parse(query.offer),
|
|
|
|
merchantPageUrl: query.merchantPageUrl
|
2015-12-17 22:56:24 +01:00
|
|
|
};
|
2016-01-10 20:07:42 +01:00
|
|
|
chrome.runtime.sendMessage({ type: 'confirm-pay', detail: d }, function (resp) {
|
2015-12-20 20:05:06 +01:00
|
|
|
if (!resp.success) {
|
2016-01-10 20:07:42 +01:00
|
|
|
var source_1 = $_("error-template").innerHTML;
|
|
|
|
var template_1 = Handlebars.compile(source_1);
|
|
|
|
$_("status").innerHTML = template_1(resp);
|
2015-12-17 22:56:24 +01:00
|
|
|
return;
|
2015-12-16 10:45:16 +01:00
|
|
|
}
|
2015-12-20 20:05:06 +01:00
|
|
|
document.location.href = URI(d.offer.exec_url)
|
|
|
|
.absoluteTo(query.merchantPageUrl)
|
|
|
|
.addQuery({ H_contract: d.offer.H_contract })
|
|
|
|
.href();
|
2015-12-16 10:45:16 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-01-10 20:07:42 +01:00
|
|
|
//# sourceMappingURL=confirm-contract.js.map
|