gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-web-common] branch master updated: implement taler.p


From: gnunet
Subject: [GNUnet-SVN] [taler-web-common] branch master updated: implement taler.pay
Date: Sun, 12 Feb 2017 21:41:12 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository web-common.

The following commit(s) were added to refs/heads/master by this push:
     new 55fed81  implement taler.pay
55fed81 is described below

commit 55fed81eb4ba9a44c4c568ca5989234e10de8289
Author: Florian Dold <address@hidden>
AuthorDate: Sun Feb 12 21:41:09 2017 +0100

    implement taler.pay
---
 taler-wallet-lib.js | 101 +++++++++++++++++++++++++------------------------
 taler-wallet-lib.ts | 107 +++++++++++++++++++++++++++-------------------------
 2 files changed, 108 insertions(+), 100 deletions(-)

diff --git a/taler-wallet-lib.js b/taler-wallet-lib.js
index 05bac16..d1975fd 100644
--- a/taler-wallet-lib.js
+++ b/taler-wallet-lib.js
@@ -133,10 +133,7 @@ var taler;
         internalExecutePayment(contractHash, payUrl, offeringUrl);
     }
     taler.executePayment = executePayment;
-    function internalExecutePayment(contractHash, payUrl, offeringUrl, 
onError) {
-        if (!contractHash) {
-            raise_error("protocol-violation", { hint: "contract hash not 
given" });
-        }
+    function handlePaymentResponse(resp, payUrl) {
         function subst(url, contractHash) {
             url = url.replace("${H_contract}", contractHash);
             url = url.replace("${$}", "$");
@@ -164,60 +161,63 @@ var taler;
                 timeoutHandle = null;
                 err();
             }
-            callWallet("taler-payment-failed", { H_contract: contractHash }, 
onResp);
+            callWallet("taler-payment-failed", { H_contract: resp.H_contract 
}, onResp);
             timeoutHandle = setTimeout(onTimeout, 200);
         }
-        function handleResponse(resp) {
-            logVerbose && console.log("handling taler-notify-payment");
-            // Payment timeout in ms.
-            var timeout_ms = 1000;
-            // Current request.
-            var r;
-            var timeoutHandle = null;
-            function sendPay() {
-                r = new XMLHttpRequest();
-                r.open("post", payUrl);
-                r.setRequestHeader("Content-Type", 
"application/json;charset=UTF-8");
-                r.send(JSON.stringify(resp.payment));
-                r.onload = function () {
-                    if (!r) {
-                        return;
-                    }
-                    switch (r.status) {
-                        case 200:
-                            callWallet("taler-payment-succeeded", { 
H_contract: contractHash }, function () {
-                                window.location.href = 
subst(resp.contract.fulfillment_url, resp.H_contract);
-                                window.location.reload(true);
-                            });
-                            break;
-                        default:
-                            handleFailedPayment(r);
-                            break;
-                    }
+        logVerbose && console.log("handling taler-notify-payment");
+        // Payment timeout in ms.
+        var timeout_ms = 1000;
+        // Current request.
+        var r;
+        var timeoutHandle = null;
+        function sendPay() {
+            r = new XMLHttpRequest();
+            r.open("post", payUrl);
+            r.setRequestHeader("Content-Type", 
"application/json;charset=UTF-8");
+            r.send(JSON.stringify(resp.payment));
+            r.onload = function () {
+                if (!r) {
+                    return;
+                }
+                switch (r.status) {
+                    case 200:
+                        callWallet("taler-payment-succeeded", { H_contract: 
resp.H_contract }, function () {
+                            window.location.href = 
subst(resp.contract.fulfillment_url, resp.H_contract);
+                            window.location.reload(true);
+                        });
+                        break;
+                    default:
+                        handleFailedPayment(r);
+                        break;
+                }
+                r = null;
+                if (timeoutHandle != null) {
+                    clearTimeout(timeoutHandle);
+                    timeoutHandle = null;
+                }
+            };
+            function retry() {
+                if (r) {
+                    r.abort();
                     r = null;
-                    if (timeoutHandle != null) {
-                        clearTimeout(timeoutHandle);
-                        timeoutHandle = null;
-                    }
-                };
-                function retry() {
-                    if (r) {
-                        r.abort();
-                        r = null;
-                    }
-                    timeout_ms = Math.min(timeout_ms * 2, 10 * 1000);
-                    logVerbose && console.log("sendPay timed out, retrying in 
", timeout_ms, "ms");
-                    sendPay();
                 }
-                timeoutHandle = setTimeout(retry, timeout_ms);
+                timeout_ms = Math.min(timeout_ms * 2, 10 * 1000);
+                logVerbose && console.log("sendPay timed out, retrying in ", 
timeout_ms, "ms");
+                sendPay();
             }
-            sendPay();
+            timeoutHandle = setTimeout(retry, timeout_ms);
+        }
+        sendPay();
+    }
+    function internalExecutePayment(contractHash, payUrl, offeringUrl, 
onError) {
+        if (!contractHash) {
+            raise_error("protocol-violation", { hint: "contract hash not 
given" });
         }
         var args = {
             H_contract: contractHash,
             offering_url: offeringUrl
         };
-        callWallet("taler-get-payment", args, handleResponse);
+        callWallet("taler-get-payment", args, function (r) { return 
handlePaymentResponse(r, payUrl); });
     }
     taler.internalExecutePayment = internalExecutePayment;
     function onPresent(f) {
@@ -291,7 +291,10 @@ var taler;
             });
             return;
         }
-        callWallet("taler-pay", p);
+        callWallet("taler-pay", p, function (resp) {
+            // either we get a response here, or the wallet will redirect the 
browser
+            handlePaymentResponse(resp, resp.pay_url);
+        });
     }
     taler.pay = pay;
     function initTaler() {
diff --git a/taler-wallet-lib.ts b/taler-wallet-lib.ts
index c906720..7a76771 100644
--- a/taler-wallet-lib.ts
+++ b/taler-wallet-lib.ts
@@ -149,11 +149,7 @@ namespace taler {
   }
 
 
-  export function internalExecutePayment(contractHash: string, payUrl: string, 
offeringUrl: string, onError?: any) {
-    if (!contractHash) {
-      raise_error("protocol-violation", {hint: "contract hash not given"});
-    }
-
+  function handlePaymentResponse(resp: any, payUrl: string) {
     function subst(url: string, contractHash: string) {
       url = url.replace("${H_contract}", contractHash);
       url = url.replace("${$}", "$");
@@ -182,57 +178,62 @@ namespace taler {
         timeoutHandle = null
         err();
       }
-      callWallet("taler-payment-failed", {H_contract: contractHash}, onResp);
+      callWallet("taler-payment-failed", {H_contract: resp.H_contract}, 
onResp);
       timeoutHandle = setTimeout(onTimeout, 200);
     }
 
 
-    function handleResponse(resp: any) {
-      logVerbose && console.log("handling taler-notify-payment");
-      // Payment timeout in ms.
-      let timeout_ms = 1000;
-      // Current request.
-      let r: XMLHttpRequest|null;
-      let timeoutHandle: number|null = null;
-      function sendPay() {
-        r = new XMLHttpRequest();
-        r.open("post", payUrl);
-        r.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
-        r.send(JSON.stringify(resp.payment));
-        r.onload = function() {
-          if (!r) {
-            return;
-          }
-          switch (r.status) {
-            case 200:
-              callWallet("taler-payment-succeeded", {H_contract: 
contractHash}, () => {
-                window.location.href = subst(resp.contract.fulfillment_url,
-                                             resp.H_contract);
-                window.location.reload(true);
-              });
-              break;
-            default:
-              handleFailedPayment(r);
-              break;
-          }
+    logVerbose && console.log("handling taler-notify-payment");
+    // Payment timeout in ms.
+    let timeout_ms = 1000;
+    // Current request.
+    let r: XMLHttpRequest|null;
+    let timeoutHandle: number|null = null;
+    function sendPay() {
+      r = new XMLHttpRequest();
+      r.open("post", payUrl);
+      r.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
+      r.send(JSON.stringify(resp.payment));
+      r.onload = function() {
+        if (!r) {
+          return;
+        }
+        switch (r.status) {
+          case 200:
+            callWallet("taler-payment-succeeded", {H_contract: 
resp.H_contract}, () => {
+              window.location.href = subst(resp.contract.fulfillment_url,
+                                           resp.H_contract);
+              window.location.reload(true);
+            });
+            break;
+          default:
+            handleFailedPayment(r);
+            break;
+        }
+        r = null;
+        if (timeoutHandle != null) {
+          clearTimeout(timeoutHandle!);
+          timeoutHandle = null;
+        }
+      };
+      function retry() {
+        if (r) {
+          r.abort();
           r = null;
-          if (timeoutHandle != null) {
-            clearTimeout(timeoutHandle!);
-            timeoutHandle = null;
-          }
-        };
-        function retry() {
-          if (r) {
-            r.abort();
-            r = null;
-          }
-          timeout_ms = Math.min(timeout_ms * 2, 10 * 1000);
-          logVerbose && console.log("sendPay timed out, retrying in ", 
timeout_ms, "ms");
-          sendPay();
         }
-        timeoutHandle = setTimeout(retry, timeout_ms);
+        timeout_ms = Math.min(timeout_ms * 2, 10 * 1000);
+        logVerbose && console.log("sendPay timed out, retrying in ", 
timeout_ms, "ms");
+        sendPay();
       }
-      sendPay();
+      timeoutHandle = setTimeout(retry, timeout_ms);
+    }
+    sendPay();
+  }
+
+
+  export function internalExecutePayment(contractHash: string, payUrl: string, 
offeringUrl: string, onError?: any) {
+    if (!contractHash) {
+      raise_error("protocol-violation", {hint: "contract hash not given"});
     }
 
     let args = {
@@ -240,7 +241,7 @@ namespace taler {
       offering_url: offeringUrl
     };
 
-    callWallet("taler-get-payment", args, handleResponse);
+    callWallet("taler-get-payment", args, (r: any) => handlePaymentResponse(r, 
payUrl));
   }
 
 
@@ -322,6 +323,7 @@ namespace taler {
     contract_url?: string;
     offer_url?: string;
     contract_query: FulfillmentQuery | OrderIdQuery;
+    pay_url: string;
   }
 
   export function pay(p: PayDetail) {
@@ -332,7 +334,10 @@ namespace taler {
       });
       return;
     }
-    callWallet("taler-pay", p);
+    callWallet("taler-pay", p, (resp: any) => {
+      // either we get a response here, or the wallet will redirect the browser
+      handlePaymentResponse(resp, resp.pay_url);
+    });
   }
 
 

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]