have from contract, remove extended contract query

This commit is contained in:
Florian Dold 2017-03-03 15:37:04 +01:00
parent ac34262853
commit 1637127658
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
5 changed files with 28 additions and 48 deletions

View File

@ -76,11 +76,10 @@ namespace TalerNotify {
});
}
function queryPayment(query: any): Promise<any> {
// current URL without fragment
function queryPayment(url: string): Promise<any> {
const walletMsg = {
type: "query-payment",
detail: query,
detail: { url },
};
return new Promise((resolve, reject) => {
chrome.runtime.sendMessage(walletMsg, (resp: any) => {
@ -331,7 +330,9 @@ namespace TalerNotify {
});
addHandler("taler-pay", async(msg: any, sendResponse: any) => {
let res = await queryPayment(msg.contract_query);
// current URL without fragment
let url = URI(document.location.href).fragment("").href();
let res = await queryPayment(url);
logVerbose && console.log("taler-pay: got response", res);
if (res && res.payReq) {
sendResponse(res);

View File

@ -483,6 +483,9 @@ export class Contract {
@Checkable.String
order_id: string;
@Checkable.String
pay_url: string;
@Checkable.String
fulfillment_url: string;

View File

@ -669,27 +669,13 @@ export class Wallet {
/**
* Retrieve all necessary information for looking up the contract
* with the given hash.
* Retrieve information required to pay for a contract, where the
* contract is identified via the fulfillment url.
*/
async queryPayment(query: any): Promise<any> {
let t: TransactionRecord | undefined;
async queryPayment(url: string): Promise<any> {
console.log("query for payment", url);
console.log("query for payment", query);
switch (query.type) {
case "fulfillment_url":
t = await this.q().getIndexed(Stores.transactions.fulfillmentUrlIndex, query.value);
break;
case "order_id":
t = await this.q().getIndexed(Stores.transactions.orderIdIndex, query.value);
break;
case "hash":
t = await this.q().get<TransactionRecord>(Stores.transactions, query.value);
break;
default:
throw Error("invalid type");
}
const t = await this.q().getIndexed(Stores.transactions.fulfillmentUrlIndex, url);
if (!t) {
console.log("query for payment failed");

View File

@ -155,7 +155,7 @@ function makeHandlers(db: IDBDatabase,
return Promise.resolve(msg);
}
}
return wallet.queryPayment(detail);
return wallet.queryPayment(detail.url);
},
["exchange-info"]: function (detail) {
if (!detail.baseUrl) {
@ -318,6 +318,13 @@ class ChromeNotifier implements Notifier {
*/
let paymentRequestCookies: { [n: number]: any } = {};
/**
* Handle a HTTP response that has the "402 Payment Required" status.
* In this callback we don't have access to the body, and must communicate via
* shared state with the content script that will later be run later
* in this tab.
*/
function handleHttpPayment(headerList: chrome.webRequest.HttpHeader[], url: string, tabId: number): any {
const headers: { [s: string]: string } = {};
for (let kv of headerList) {
@ -330,44 +337,26 @@ function handleHttpPayment(headerList: chrome.webRequest.HttpHeader[], url: stri
contract_url: headers["x-taler-contract-url"],
contract_query: headers["x-taler-contract-query"],
offer_url: headers["x-taler-offer-url"],
pay_url: headers["x-taler-pay-url"],
}
let n: number = 0;
let talerHeaderFound = Object.keys(fields).filter((x: any) => (fields as any)[x]).length != 0;
for (let key of Object.keys(fields)) {
if ((fields as any)[key]) {
n++;
}
}
if (n == 0) {
if (!talerHeaderFound) {
// looks like it's not a taler request, it might be
// for a different payment system (or the shop is buggy)
console.log("ignoring non-taler 402 response");
}
let contract_query = undefined;
// parse " type [ ':' value ] " format
if (fields.contract_query) {
let res = /[-a-zA-Z0-9_.,]+(:.*)?/.exec(fields.contract_query);
if (res) {
contract_query = {type: res[0], value: res[1]};
if (contract_query.type == "fulfillment_url" && !contract_query.value) {
contract_query.value = url;
}
}
return;
}
let payDetail = {
contract_query,
contract_url: fields.contract_url,
offer_url: fields.offer_url,
pay_url: fields.pay_url,
};
console.log("got pay detail", payDetail)
// This cookie will be read by the injected content script
// in the tab that displays the page.
paymentRequestCookies[tabId] = {
type: "pay",
payDetail,
@ -375,6 +364,7 @@ function handleHttpPayment(headerList: chrome.webRequest.HttpHeader[], url: stri
}
function handleBankRequest(wallet: Wallet, headerList: chrome.webRequest.HttpHeader[],
url: string, tabId: number): any {
const headers: { [s: string]: string } = {};

@ -1 +1 @@
Subproject commit 4831e664d69759da288625911c053d145aa1b68c
Subproject commit caf5a98114402d057ba08b14279eb8e46481a02c