From 80f43b85c8e98031b26c927e58f04858f9683d2f Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 24 Dec 2015 03:20:18 +0100 Subject: payment --- extension/content_scripts/notify.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'extension/content_scripts/notify.js') diff --git a/extension/content_scripts/notify.js b/extension/content_scripts/notify.js index 065aae193..676fd7653 100644 --- a/extension/content_scripts/notify.js +++ b/extension/content_scripts/notify.js @@ -55,25 +55,32 @@ document.addEventListener('taler-execute-payment', function (e) { }, }; chrome.runtime.sendMessage(msg, (resp) => { - console.log("got backend response to execute-payment:", JSON.stringify(resp)); if (!resp.success) { console.log("failure!"); return; } + console.log("Making request to ", resp.payUrl); let r = new XMLHttpRequest(); r.open('post', resp.payUrl); r.send(JSON.stringify(resp.payReq)); - let evt; + let detail = {}; r.onload = (e) => { - if (r.status != 200) { - console.log("non-200 error"); - console.log(r.responseText); - alert("merchant returned HTTP status " + r.status); + switch (r.status) { + case 200: + detail.success = true; + break; + case 301: + detail.success = true; + console.log("Headers:", r.getAllResponseHeaders()); + detail.fulfillmentUrl = r.getResponseHeader('Location'); + break; + default: + detail.success = false; + break; } - else { - evt = new CustomEvent("taler-payment-result", { detail: resp }); - } - document.dispatchEvent(evt); + console.log("status was:", r.status); + console.log("detail:", JSON.stringify(detail)); + document.dispatchEvent(new CustomEvent("taler-payment-result", { detail: detail })); }; }); }); -- cgit v1.2.3