fix handling of resource_url

This commit is contained in:
Florian Dold 2018-01-18 02:50:18 +01:00
parent 82d9c2a7cd
commit 2f68e9e50e
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
11 changed files with 37 additions and 21 deletions

View File

@ -784,6 +784,7 @@ export interface PurchaseRecord {
timestamp_refund: number; timestamp_refund: number;
lastSessionSig: string | undefined; lastSessionSig: string | undefined;
lastSessionId: string | undefined;
} }

View File

@ -56,12 +56,12 @@ msgid ""
"wallet." "wallet."
msgstr "" msgstr ""
#: src/webex/pages/confirm-contract.tsx:249 #: src/webex/pages/confirm-contract.tsx:251
#, c-format #, c-format
msgid "The merchant%1$s offers you to purchase:\n" msgid "The merchant%1$s offers you to purchase:\n"
msgstr "" msgstr ""
#: src/webex/pages/confirm-contract.tsx:270 #: src/webex/pages/confirm-contract.tsx:272
#, fuzzy, c-format #, fuzzy, c-format
msgid "Confirm payment" msgid "Confirm payment"
msgstr "Bezahlung bestätigen" msgstr "Bezahlung bestätigen"

View File

@ -56,12 +56,12 @@ msgid ""
"wallet." "wallet."
msgstr "" msgstr ""
#: src/webex/pages/confirm-contract.tsx:249 #: src/webex/pages/confirm-contract.tsx:251
#, c-format #, c-format
msgid "The merchant%1$s offers you to purchase:\n" msgid "The merchant%1$s offers you to purchase:\n"
msgstr "" msgstr ""
#: src/webex/pages/confirm-contract.tsx:270 #: src/webex/pages/confirm-contract.tsx:272
#, c-format #, c-format
msgid "Confirm payment" msgid "Confirm payment"
msgstr "" msgstr ""

View File

@ -56,12 +56,12 @@ msgid ""
"wallet." "wallet."
msgstr "" msgstr ""
#: src/webex/pages/confirm-contract.tsx:249 #: src/webex/pages/confirm-contract.tsx:251
#, c-format #, c-format
msgid "The merchant%1$s offers you to purchase:\n" msgid "The merchant%1$s offers you to purchase:\n"
msgstr "" msgstr ""
#: src/webex/pages/confirm-contract.tsx:270 #: src/webex/pages/confirm-contract.tsx:272
#, c-format #, c-format
msgid "Confirm payment" msgid "Confirm payment"
msgstr "" msgstr ""

View File

@ -56,12 +56,12 @@ msgid ""
"wallet." "wallet."
msgstr "" msgstr ""
#: src/webex/pages/confirm-contract.tsx:249 #: src/webex/pages/confirm-contract.tsx:251
#, c-format #, c-format
msgid "The merchant%1$s offers you to purchase:\n" msgid "The merchant%1$s offers you to purchase:\n"
msgstr "" msgstr ""
#: src/webex/pages/confirm-contract.tsx:270 #: src/webex/pages/confirm-contract.tsx:272
#, c-format #, c-format
msgid "Confirm payment" msgid "Confirm payment"
msgstr "" msgstr ""

View File

@ -56,12 +56,12 @@ msgid ""
"wallet." "wallet."
msgstr "" msgstr ""
#: src/webex/pages/confirm-contract.tsx:249 #: src/webex/pages/confirm-contract.tsx:251
#, c-format #, c-format
msgid "The merchant%1$s offers you to purchase:\n" msgid "The merchant%1$s offers you to purchase:\n"
msgstr "" msgstr ""
#: src/webex/pages/confirm-contract.tsx:270 #: src/webex/pages/confirm-contract.tsx:272
#, c-format #, c-format
msgid "Confirm payment" msgid "Confirm payment"
msgstr "" msgstr ""

View File

@ -685,7 +685,6 @@ export class QueryRoot {
put<T>(store: Store<T>, val: T, keyName?: string): QueryRoot { put<T>(store: Store<T>, val: T, keyName?: string): QueryRoot {
this.checkFinished(); this.checkFinished();
const doPut = (tx: IDBTransaction) => { const doPut = (tx: IDBTransaction) => {
console.log("put into", store.name, "value", val);
const req = tx.objectStore(store.name).put(val); const req = tx.objectStore(store.name).put(val);
if (keyName) { if (keyName) {
req.onsuccess = () => { req.onsuccess = () => {

View File

@ -96,6 +96,7 @@ import {
CreateReserveRequest, CreateReserveRequest,
CreateReserveResponse, CreateReserveResponse,
HistoryRecord, HistoryRecord,
NextUrlResult,
Notifier, Notifier,
PayCoinInfo, PayCoinInfo,
QueryPaymentResult, QueryPaymentResult,
@ -312,7 +313,7 @@ export class Wallet {
private processPreCoinThrottle: {[url: string]: number} = {}; private processPreCoinThrottle: {[url: string]: number} = {};
private timerGroup: TimerGroup; private timerGroup: TimerGroup;
private speculativePayData: SpeculativePayData | undefined; private speculativePayData: SpeculativePayData | undefined;
private cachedNextUrl: { [fulfillmentUrl: string]: string } = {}; private cachedNextUrl: { [fulfillmentUrl: string]: NextUrlResult } = {};
/** /**
* Set of identifiers for running operations. * Set of identifiers for running operations.
@ -652,6 +653,7 @@ export class Wallet {
contractTermsHash: proposal.contractTermsHash, contractTermsHash: proposal.contractTermsHash,
finished: false, finished: false,
lastSessionSig: undefined, lastSessionSig: undefined,
lastSessionId: undefined,
merchantSig: proposal.merchantSig, merchantSig: proposal.merchantSig,
payReq, payReq,
refundsDone: {}, refundsDone: {},
@ -735,14 +737,14 @@ export class Wallet {
const fu = new URI(purchase.contractTerms.fulfillment_url); const fu = new URI(purchase.contractTerms.fulfillment_url);
fu.addSearch("order_id", purchase.contractTerms.order_id); fu.addSearch("order_id", purchase.contractTerms.order_id);
if (merchantResp.session_sig) { if (merchantResp.session_sig) {
fu.addSearch("session_sig", merchantResp.session_sig);
purchase.lastSessionSig = merchantResp.session_sig; purchase.lastSessionSig = merchantResp.session_sig;
console.log("updating session sig", purchase); purchase.lastSessionId = sessionId;
fu.addSearch("session_sig", merchantResp.session_sig);
await this.q().put(Stores.purchases, purchase).finish(); await this.q().put(Stores.purchases, purchase).finish();
} }
await this.paymentSucceeded(purchase.contractTermsHash, merchantResp.sig); await this.paymentSucceeded(purchase.contractTermsHash, merchantResp.sig);
const nextUrl = fu.href(); const nextUrl = fu.href();
this.cachedNextUrl[purchase.contractTerms.fulfillment_url] = nextUrl; this.cachedNextUrl[purchase.contractTerms.fulfillment_url] = { nextUrl, lastSessionId: sessionId };
return { nextUrl }; return { nextUrl };
} }
@ -899,6 +901,7 @@ export class Wallet {
contractTerms: t.contractTerms, contractTerms: t.contractTerms,
contractTermsHash: t.contractTermsHash, contractTermsHash: t.contractTermsHash,
found: true, found: true,
lastSessionId: t.lastSessionId,
lastSessionSig: t.lastSessionSig, lastSessionSig: t.lastSessionSig,
payReq: t.payReq, payReq: t.payReq,
}; };
@ -925,6 +928,7 @@ export class Wallet {
contractTermsHash: t.contractTermsHash, contractTermsHash: t.contractTermsHash,
found: true, found: true,
lastSessionSig: t.lastSessionSig, lastSessionSig: t.lastSessionSig,
lastSessionId: t.lastSessionId,
payReq: t.payReq, payReq: t.payReq,
}; };
} }
@ -2891,7 +2895,7 @@ export class Wallet {
* payed for, or if it is not cached anymore. Use the asynchronous * payed for, or if it is not cached anymore. Use the asynchronous
* queryPaymentByFulfillmentUrl to avoid false negatives. * queryPaymentByFulfillmentUrl to avoid false negatives.
*/ */
getNextUrlFromResourceUrl(resourceUrl: string): string | undefined { getNextUrlFromResourceUrl(resourceUrl: string): NextUrlResult | undefined {
return this.cachedNextUrl[resourceUrl]; return this.cachedNextUrl[resourceUrl];
} }

View File

@ -302,6 +302,7 @@ export interface QueryPaymentFound {
contractTermsHash: string; contractTermsHash: string;
contractTerms: ContractTerms; contractTerms: ContractTerms;
lastSessionSig?: string; lastSessionSig?: string;
lastSessionId?: string;
payReq: PayReq; payReq: PayReq;
} }
@ -603,3 +604,12 @@ export interface Badge {
*/ */
clearNotification(): void; clearNotification(): void;
} }
/**
* Cached next URL for a particular session id.
*/
export interface NextUrlResult {
nextUrl: string;
lastSessionId: string | undefined;
}

View File

@ -150,7 +150,7 @@ class ContractPrompt extends React.Component<ContractPromptProps, ContractPrompt
if (this.props.resourceUrl) { if (this.props.resourceUrl) {
const p = await wxApi.queryPaymentByFulfillmentUrl(this.props.resourceUrl); const p = await wxApi.queryPaymentByFulfillmentUrl(this.props.resourceUrl);
console.log("query for resource url", this.props.resourceUrl, "result", p); console.log("query for resource url", this.props.resourceUrl, "result", p);
if (p.found) { if (p.found && (p.lastSessionSig === undefined || p.lastSessionSig === this.props.sessionId)) {
const nextUrl = new URI(p.contractTerms.fulfillment_url); const nextUrl = new URI(p.contractTerms.fulfillment_url);
nextUrl.addSearch("order_id", p.contractTerms.order_id); nextUrl.addSearch("order_id", p.contractTerms.order_id);
if (p.lastSessionSig) { if (p.lastSessionSig) {
@ -218,7 +218,9 @@ class ContractPrompt extends React.Component<ContractPromptProps, ContractPrompt
console.error("proposal has no id"); console.error("proposal has no id");
return; return;
} }
console.log("confirmPay with", proposalId, "and", this.props.sessionId);
const payResult = await wxApi.confirmPay(proposalId, this.props.sessionId); const payResult = await wxApi.confirmPay(proposalId, this.props.sessionId);
console.log("payResult", payResult);
document.location.href = payResult.nextUrl; document.location.href = payResult.nextUrl;
this.setState({ holdCheck: true }); this.setState({ holdCheck: true });
} }

View File

@ -422,7 +422,7 @@ async function talerPay(fields: any, url: string, tabId: number): Promise<string
if (fields.resource_url) { if (fields.resource_url) {
const p = await w.queryPaymentByFulfillmentUrl(fields.resource_url); const p = await w.queryPaymentByFulfillmentUrl(fields.resource_url);
console.log("query for resource url", fields.resource_url, "result", p); console.log("query for resource url", fields.resource_url, "result", p);
if (p.found) { if (p.found && (fields.session_id === undefined || fields.session_id === p.lastSessionId)) {
return goToPayment(p); return goToPayment(p);
} }
} }
@ -508,9 +508,9 @@ function handleHttpPayment(headerList: chrome.webRequest.HttpHeader[], url: stri
// Fast path for existing payment // Fast path for existing payment
if (fields.resource_url) { if (fields.resource_url) {
const nextUrl = currentWallet.getNextUrlFromResourceUrl(fields.resource_url); const result = currentWallet.getNextUrlFromResourceUrl(fields.resource_url);
if (nextUrl) { if (result && (fields.session_id === undefined || fields.session_id === result.lastSessionId)) {
return { redirectUrl: nextUrl }; return { redirectUrl: result.nextUrl };
} }
} }
// Fast path for new contract // Fast path for new contract