diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-01-18 02:50:18 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-01-18 02:50:18 +0100 |
commit | 2f68e9e50e83c55ca46e9d4d72956d6525d0fa8c (patch) | |
tree | bfe94c2e0af1f3777765d37b35eeb76ed4e221be | |
parent | 82d9c2a7cd2e343866997438d44aa5422190a028 (diff) |
fix handling of resource_url
-rw-r--r-- | src/dbTypes.ts | 1 | ||||
-rw-r--r-- | src/i18n/de.po | 4 | ||||
-rw-r--r-- | src/i18n/en-US.po | 4 | ||||
-rw-r--r-- | src/i18n/fr.po | 4 | ||||
-rw-r--r-- | src/i18n/it.po | 4 | ||||
-rw-r--r-- | src/i18n/taler-wallet-webex.pot | 4 | ||||
-rw-r--r-- | src/query.ts | 1 | ||||
-rw-r--r-- | src/wallet.ts | 14 | ||||
-rw-r--r-- | src/walletTypes.ts | 10 | ||||
-rw-r--r-- | src/webex/pages/confirm-contract.tsx | 4 | ||||
-rw-r--r-- | src/webex/wxBackend.ts | 8 |
11 files changed, 37 insertions, 21 deletions
diff --git a/src/dbTypes.ts b/src/dbTypes.ts index 9e9663219..609c85265 100644 --- a/src/dbTypes.ts +++ b/src/dbTypes.ts @@ -784,6 +784,7 @@ export interface PurchaseRecord { timestamp_refund: number; lastSessionSig: string | undefined; + lastSessionId: string | undefined; } diff --git a/src/i18n/de.po b/src/i18n/de.po index 1f6e98962..39f1f56e6 100644 --- a/src/i18n/de.po +++ b/src/i18n/de.po @@ -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" diff --git a/src/i18n/en-US.po b/src/i18n/en-US.po index 3e47e952a..2fdb451db 100644 --- a/src/i18n/en-US.po +++ b/src/i18n/en-US.po @@ -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 "" diff --git a/src/i18n/fr.po b/src/i18n/fr.po index 97ff47067..5d47a1f74 100644 --- a/src/i18n/fr.po +++ b/src/i18n/fr.po @@ -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 "" diff --git a/src/i18n/it.po b/src/i18n/it.po index 97ff47067..5d47a1f74 100644 --- a/src/i18n/it.po +++ b/src/i18n/it.po @@ -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 "" diff --git a/src/i18n/taler-wallet-webex.pot b/src/i18n/taler-wallet-webex.pot index 97ff47067..5d47a1f74 100644 --- a/src/i18n/taler-wallet-webex.pot +++ b/src/i18n/taler-wallet-webex.pot @@ -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 "" diff --git a/src/query.ts b/src/query.ts index 290d02a2a..e45596c66 100644 --- a/src/query.ts +++ b/src/query.ts @@ -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 = () => { diff --git a/src/wallet.ts b/src/wallet.ts index aa974369a..7c2914926 100644 --- a/src/wallet.ts +++ b/src/wallet.ts @@ -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]; } diff --git a/src/walletTypes.ts b/src/walletTypes.ts index 45a795873..c98717ac2 100644 --- a/src/walletTypes.ts +++ b/src/walletTypes.ts @@ -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; +} diff --git a/src/webex/pages/confirm-contract.tsx b/src/webex/pages/confirm-contract.tsx index c302239c6..cd58d712a 100644 --- a/src/webex/pages/confirm-contract.tsx +++ b/src/webex/pages/confirm-contract.tsx @@ -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 }); } diff --git a/src/webex/wxBackend.ts b/src/webex/wxBackend.ts index 7bbba1759..a4f534af9 100644 --- a/src/webex/wxBackend.ts +++ b/src/webex/wxBackend.ts @@ -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 |