diff options
Diffstat (limited to 'extension/content_scripts')
-rw-r--r-- | extension/content_scripts/notify.js | 34 | ||||
-rw-r--r-- | extension/content_scripts/notify.ts | 38 |
2 files changed, 62 insertions, 10 deletions
diff --git a/extension/content_scripts/notify.js b/extension/content_scripts/notify.js index 4749fe9bf..d81732f10 100644 --- a/extension/content_scripts/notify.js +++ b/extension/content_scripts/notify.js @@ -65,12 +65,36 @@ var TalerNotify; document.addEventListener("taler-contract", function (e) { // XXX: the merchant should just give us the parsed data ... var offer = JSON.parse(e.detail); - var uri = URI(chrome.extension.getURL("pages/confirm-contract.html")); - var params = { - offer: JSON.stringify(offer), - merchantPageUrl: document.location.href, + if (!offer.contract) { + console.error("contract field missing"); + return; + } + var msg = { + type: "check-repurchase", + detail: { + contract: offer.contract + }, }; - document.location.href = uri.query(params).href(); + chrome.runtime.sendMessage(msg, function (resp) { + if (resp.error) { + console.error("wallet backend error", resp); + return; + } + if (resp.isRepurchase) { + console.log("doing repurchase"); + console.assert(resp.existingFulfillmentUrl); + console.assert(resp.existingContractHash); + window.location.href = subst(resp.existingFulfillmentUrl, resp.existingContractHash); + } + else { + var uri = URI(chrome.extension.getURL("pages/confirm-contract.html")); + var params = { + offer: JSON.stringify(offer), + merchantPageUrl: document.location.href, + }; + document.location.href = uri.query(params).href(); + } + }); }); document.addEventListener('taler-execute-payment', function (e) { console.log("got taler-execute-payment in content page"); diff --git a/extension/content_scripts/notify.ts b/extension/content_scripts/notify.ts index 9a64bcf0c..d300dbc03 100644 --- a/extension/content_scripts/notify.ts +++ b/extension/content_scripts/notify.ts @@ -77,12 +77,40 @@ namespace TalerNotify { document.addEventListener("taler-contract", function(e: CustomEvent) { // XXX: the merchant should just give us the parsed data ... let offer = JSON.parse(e.detail); - let uri = URI(chrome.extension.getURL("pages/confirm-contract.html")); - let params = { - offer: JSON.stringify(offer), - merchantPageUrl: document.location.href, + + if (!offer.contract) { + console.error("contract field missing"); + return; + } + + let msg = { + type: "check-repurchase", + detail: { + contract: offer.contract + }, }; - document.location.href = uri.query(params).href(); + + chrome.runtime.sendMessage(msg, (resp) => { + if (resp.error) { + console.error("wallet backend error", resp); + return; + } + if (resp.isRepurchase) { + console.log("doing repurchase"); + console.assert(resp.existingFulfillmentUrl); + console.assert(resp.existingContractHash); + window.location.href = subst(resp.existingFulfillmentUrl, + resp.existingContractHash); + + } else { + let uri = URI(chrome.extension.getURL("pages/confirm-contract.html")); + let params = { + offer: JSON.stringify(offer), + merchantPageUrl: document.location.href, + }; + document.location.href = uri.query(params).href(); + } + }); }); |