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;
lastSessionSig: string | undefined;
lastSessionId: string | undefined;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -302,6 +302,7 @@ export interface QueryPaymentFound {
contractTermsHash: string;
contractTerms: ContractTerms;
lastSessionSig?: string;
lastSessionId?: string;
payReq: PayReq;
}
@ -603,3 +604,12 @@ export interface Badge {
*/
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) {
const p = await wxApi.queryPaymentByFulfillmentUrl(this.props.resourceUrl);
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);
nextUrl.addSearch("order_id", p.contractTerms.order_id);
if (p.lastSessionSig) {
@ -218,7 +218,9 @@ class ContractPrompt extends React.Component<ContractPromptProps, ContractPrompt
console.error("proposal has no id");
return;
}
console.log("confirmPay with", proposalId, "and", this.props.sessionId);
const payResult = await wxApi.confirmPay(proposalId, this.props.sessionId);
console.log("payResult", payResult);
document.location.href = payResult.nextUrl;
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) {
const p = await w.queryPaymentByFulfillmentUrl(fields.resource_url);
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);
}
}
@ -508,9 +508,9 @@ function handleHttpPayment(headerList: chrome.webRequest.HttpHeader[], url: stri
// Fast path for existing payment
if (fields.resource_url) {
const nextUrl = currentWallet.getNextUrlFromResourceUrl(fields.resource_url);
if (nextUrl) {
return { redirectUrl: nextUrl };
const result = currentWallet.getNextUrlFromResourceUrl(fields.resource_url);
if (result && (fields.session_id === undefined || fields.session_id === result.lastSessionId)) {
return { redirectUrl: result.nextUrl };
}
}
// Fast path for new contract