Make JSless payments work.
This commit is contained in:
parent
a164ea9183
commit
ab241e5ca2
@ -46,7 +46,7 @@ namespace TalerNotify {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var contract_request = new XMLHttpRequest();
|
var contract_request = new XMLHttpRequest();
|
||||||
console.log("downloading contract from '" + url + "'")
|
console.log("downloading contract from '" + url + "'");
|
||||||
contract_request.open("GET", url, true);
|
contract_request.open("GET", url, true);
|
||||||
contract_request.onload = function (e) {
|
contract_request.onload = function (e) {
|
||||||
if (contract_request.readyState == 4) {
|
if (contract_request.readyState == 4) {
|
||||||
@ -76,6 +76,9 @@ namespace TalerNotify {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Wallet-internal version of executeContract, used for 402 payments.
|
* Wallet-internal version of executeContract, used for 402 payments.
|
||||||
|
*
|
||||||
|
* Even though we're inside a content script, we send events to the dom
|
||||||
|
* to avoid code duplication.
|
||||||
*/
|
*/
|
||||||
function internalExecuteContract(contractHash: string, payUrl: string,
|
function internalExecuteContract(contractHash: string, payUrl: string,
|
||||||
offerUrl: string) {
|
offerUrl: string) {
|
||||||
@ -86,25 +89,13 @@ namespace TalerNotify {
|
|||||||
* synchronous error message (such as an alert) or leave the page.
|
* synchronous error message (such as an alert) or leave the page.
|
||||||
*/
|
*/
|
||||||
function handleFailedPayment(status) {
|
function handleFailedPayment(status) {
|
||||||
let timeoutHandle = null;
|
const msg = {
|
||||||
function err() {
|
type: "payment-failed",
|
||||||
alert("Payment failed: Unexpected status code for $pay_url: " + status);
|
detail: {},
|
||||||
}
|
};
|
||||||
function onResp() {
|
chrome.runtime.sendMessage(msg, (resp) => {
|
||||||
if (timeoutHandle != null) {
|
alert("payment failed");
|
||||||
clearTimeout(timeoutHandle);
|
});
|
||||||
timeoutHandle = null;
|
|
||||||
}
|
|
||||||
err();
|
|
||||||
}
|
|
||||||
function onTimeout() {
|
|
||||||
timeoutHandle = null;
|
|
||||||
err();
|
|
||||||
}
|
|
||||||
let eve = new CustomEvent('taler-payment-failed', {detail: {}});
|
|
||||||
document.dispatchEvent(eve);
|
|
||||||
document.addEventListener("taler-payment-failed-ok", onResp, false);
|
|
||||||
timeoutHandle = setTimeout(onTimeout, 200);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -157,7 +148,7 @@ namespace TalerNotify {
|
|||||||
};
|
};
|
||||||
|
|
||||||
document.addEventListener("taler-notify-payment", handleResponse, false);
|
document.addEventListener("taler-notify-payment", handleResponse, false);
|
||||||
let eve = new CustomEvent('taler-fetch-payment', {detail: detail});
|
let eve = new CustomEvent('taler-execute-contract', {detail: detail});
|
||||||
document.dispatchEvent(eve);
|
document.dispatchEvent(eve);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,7 +324,7 @@ namespace TalerNotify {
|
|||||||
console.log("got resp");
|
console.log("got resp");
|
||||||
console.dir(resp);
|
console.dir(resp);
|
||||||
if (!resp.success) {
|
if (!resp.success) {
|
||||||
console.log("got event detial:");
|
console.log("got event detail:");
|
||||||
console.dir(e.detail);
|
console.dir(e.detail);
|
||||||
if (e.detail.offering_url) {
|
if (e.detail.offering_url) {
|
||||||
console.log("offering url", e.detail.offering_url);
|
console.log("offering url", e.detail.offering_url);
|
||||||
|
@ -54,7 +54,9 @@ function makeHandlers(db: IDBDatabase,
|
|||||||
return exportDb(db);
|
return exportDb(db);
|
||||||
},
|
},
|
||||||
["ping"]: function(detail, sender) {
|
["ping"]: function(detail, sender) {
|
||||||
return Promise.resolve(paymentRequestCache[sender.tab.id]);
|
let info = paymentRequestCookies[sender.tab.id];
|
||||||
|
delete paymentRequestCookies[sender.tab.id];
|
||||||
|
return Promise.resolve(info);
|
||||||
},
|
},
|
||||||
["reset"]: function(detail, sender) {
|
["reset"]: function(detail, sender) {
|
||||||
if (db) {
|
if (db) {
|
||||||
@ -240,7 +242,7 @@ class ChromeNotifier implements Notifier {
|
|||||||
/**
|
/**
|
||||||
* Mapping from tab ID to payment information (if any).
|
* Mapping from tab ID to payment information (if any).
|
||||||
*/
|
*/
|
||||||
let paymentRequestCache = {};
|
let paymentRequestCookies = {};
|
||||||
|
|
||||||
function handleHttpPayment(headerList: chrome.webRequest.HttpHeader[],
|
function handleHttpPayment(headerList: chrome.webRequest.HttpHeader[],
|
||||||
url: string, tabId: number): any {
|
url: string, tabId: number): any {
|
||||||
@ -251,7 +253,7 @@ function handleHttpPayment(headerList: chrome.webRequest.HttpHeader[],
|
|||||||
|
|
||||||
const contractUrl = headers["x-taler-contract-url"];
|
const contractUrl = headers["x-taler-contract-url"];
|
||||||
if (contractUrl !== undefined) {
|
if (contractUrl !== undefined) {
|
||||||
paymentRequestCache[tabId] = {type: "fetch", contractUrl};
|
paymentRequestCookies[tabId] = {type: "fetch", contractUrl};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,7 +268,7 @@ function handleHttpPayment(headerList: chrome.webRequest.HttpHeader[],
|
|||||||
|
|
||||||
// Offer URL is optional
|
// Offer URL is optional
|
||||||
const offerUrl = headers["x-taler-offer-url"];
|
const offerUrl = headers["x-taler-offer-url"];
|
||||||
paymentRequestCache[tabId] = {
|
paymentRequestCookies[tabId] = {
|
||||||
type: "execute",
|
type: "execute",
|
||||||
offerUrl,
|
offerUrl,
|
||||||
payUrl,
|
payUrl,
|
||||||
|
Loading…
Reference in New Issue
Block a user