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: remove obsolete c


From: gnunet
Subject: [GNUnet-SVN] [taler-web-common] branch master updated: remove obsolete contract downloading, add refund
Date: Thu, 01 Jun 2017 16:54:08 +0200

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 ebf2b43  remove obsolete contract downloading, add refund
ebf2b43 is described below

commit ebf2b43fb00f057643d69abf34b54a1b6087dfcd
Author: Florian Dold <address@hidden>
AuthorDate: Thu Jun 1 16:52:51 2017 +0200

    remove obsolete contract downloading, add refund
---
 taler-wallet-lib.js | 113 ++++++++------------------------------------
 taler-wallet-lib.ts | 131 ++++++++--------------------------------------------
 2 files changed, 36 insertions(+), 208 deletions(-)

diff --git a/taler-wallet-lib.js b/taler-wallet-lib.js
index 09dc239..4b6a900 100644
--- a/taler-wallet-lib.js
+++ b/taler-wallet-lib.js
@@ -35,6 +35,7 @@ var taler;
         logVerbose = !!localStorage.getItem("taler-log-verbose");
     }
     catch (e) {
+        // can't read from local storage
     }
     var presentHandlers = [];
     var absentHandlers = [];
@@ -121,81 +122,6 @@ var taler;
         callWallet("taler-create-reserve", args);
     }
     taler.createReserve = createReserve;
-    function handlePaymentResponse(walletResp) {
-        /**
-         * Handle a failed payment.
-         *
-         * Try to notify the wallet first, before we show a potentially
-         * synchronous error message (such as an alert) or leave the page.
-         */
-        function handleFailedPayment(r) {
-            var timeoutHandle = null;
-            function err() {
-                raise_error("pay-failed", { status: r.status, response: 
r.responseText });
-            }
-            function onResp() {
-                if (timeoutHandle != null) {
-                    clearTimeout(timeoutHandle);
-                    timeoutHandle = null;
-                }
-                err();
-            }
-            function onTimeout() {
-                timeoutHandle = null;
-                err();
-            }
-            callWallet("taler-payment-failed", { H_contract: 
walletResp.H_contract }, onResp);
-            timeoutHandle = setTimeout(onTimeout, 200);
-        }
-        logVerbose && console.log("handling taler-notify-payment: ", 
walletResp);
-        // Payment timeout in ms.
-        var timeout_ms = 1000;
-        // Current request.
-        var r;
-        var timeoutHandle = null;
-        function sendPay() {
-            r = new XMLHttpRequest();
-            r.open("post", walletResp.contract.pay_url);
-            r.setRequestHeader("Content-Type", 
"application/json;charset=UTF-8");
-            r.send(JSON.stringify(walletResp.payReq));
-            r.onload = function () {
-                if (!r) {
-                    return;
-                }
-                switch (r.status) {
-                    case 200:
-                        var merchantResp = JSON.parse(r.responseText);
-                        logVerbose && console.log("got success from pay_url");
-                        callWallet("taler-payment-succeeded", { H_contract: 
walletResp.H_contract, merchantSig: merchantResp.sig }, function () {
-                            var nextUrl = walletResp.contract.fulfillment_url;
-                            logVerbose && console.log("taler-payment-succeeded 
done, going to", nextUrl);
-                            window.location.href = nextUrl;
-                            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;
-                }
-                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);
-        }
-        sendPay();
-    }
     function onPresent(f) {
         presentHandlers.push(f);
     }
@@ -204,12 +130,6 @@ var taler;
         absentHandlers.push(f);
     }
     taler.onAbsent = onAbsent;
-    function internalPay(p) {
-        // either the callback gets called,
-        // or the wallet will redirect the browser
-        callWallet("taler-pay", p, handlePaymentResponse);
-    }
-    taler.internalPay = internalPay;
     function pay(p) {
         if (!installed) {
             logVerbose && console.log("delaying call to 'pay' until GNU Taler 
wallet is present");
@@ -218,15 +138,20 @@ var taler;
             });
             return;
         }
-        internalPay(p);
+        callWallet("taler-pay", p);
     }
     taler.pay = pay;
-    function internalAddAuditor(d) {
-        // either the callback gets called,
-        // or the wallet will redirect the browser
-        callWallet("taler-add-auditor", d);
+    function refund(refundUrl) {
+        if (!installed) {
+            logVerbose && console.log("delaying call to 'refund' until GNU 
Taler wallet is present");
+            taler.onPresent(function () {
+                refund(refundUrl);
+            });
+            return;
+        }
+        callWallet("taler-refund", refundUrl);
     }
-    taler.internalAddAuditor = internalAddAuditor;
+    taler.refund = refund;
     function addAuditor(d) {
         if (!installed) {
             logVerbose && console.log("delaying call to 'addAuditor' until GNU 
Taler wallet is present");
@@ -235,15 +160,9 @@ var taler;
             });
             return;
         }
-        internalAddAuditor(d);
+        callWallet("taler-add-auditor", d);
     }
     taler.addAuditor = addAuditor;
-    function internalCheckAuditor(url) {
-        return new Promise(function (resolve, reject) {
-            callWallet("taler-check-auditor", url, function (x) { return 
resolve(x); });
-        });
-    }
-    taler.internalCheckAuditor = internalCheckAuditor;
     /**
      * Check if an auditor is already added to the wallet.
      *
@@ -258,7 +177,11 @@ var taler;
                 });
             });
         }
-        return internalCheckAuditor(url);
+        return new Promise(function (resolve, reject) {
+            taler.onPresent(function () {
+                callWallet("taler-check-auditor", url, function (x) { return 
resolve(x); });
+            });
+        });
     }
     taler.checkAuditor = checkAuditor;
     function initTaler() {
diff --git a/taler-wallet-lib.ts b/taler-wallet-lib.ts
index 7ef6b4f..f16b81b 100644
--- a/taler-wallet-lib.ts
+++ b/taler-wallet-lib.ts
@@ -134,86 +134,6 @@ namespace taler {
     callWallet("taler-create-reserve", args);
   }
 
-
-  function handlePaymentResponse(walletResp: any) {
-    /**
-     * Handle a failed payment.
-     *
-     * Try to notify the wallet first, before we show a potentially
-     * synchronous error message (such as an alert) or leave the page.
-     */
-    function handleFailedPayment(r: XMLHttpRequest) {
-      let timeoutHandle: number|null = null;
-      function err() {
-        raise_error("pay-failed", {status: r.status, response: 
r.responseText});
-      }
-      function onResp() {
-        if (timeoutHandle != null) {
-          clearTimeout(timeoutHandle);
-          timeoutHandle = null;
-        }
-        err();
-      }
-      function onTimeout() {
-        timeoutHandle = null
-        err();
-      }
-      callWallet("taler-payment-failed", {H_contract: walletResp.H_contract}, 
onResp);
-      timeoutHandle = setTimeout(onTimeout, 200);
-    }
-
-
-    logVerbose && console.log("handling taler-notify-payment: ", walletResp);
-    // 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", walletResp.contract.pay_url);
-      r.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
-      r.send(JSON.stringify(walletResp.payReq));
-      r.onload = function() {
-        if (!r) {
-          return;
-        }
-        switch (r.status) {
-          case 200:
-            const merchantResp = JSON.parse(r.responseText);
-            logVerbose && console.log("got success from pay_url");
-            callWallet("taler-payment-succeeded", {H_contract: 
walletResp.H_contract, merchantSig: merchantResp.sig}, () => {
-              let nextUrl = walletResp.contract.fulfillment_url;
-              logVerbose && console.log("taler-payment-succeeded done, going 
to", nextUrl);
-              window.location.href = nextUrl;
-              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;
-        }
-        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);
-    }
-    sendPay();
-  }
-
-
   export function onPresent(f: any) {
     presentHandlers.push(f);
   }
@@ -222,27 +142,11 @@ namespace taler {
     absentHandlers.push(f);
   }
 
-  interface FulfillmentQuery {
-    type: "fulfillment_url";
-  }
-
-  interface OrderIdQuery {
-    type: "order_id";
-    order_id: string;
-  }
-
-
   interface PayDetail {
     contract_url?: string;
     offer_url?: string;
   }
 
-  export function internalPay(p: PayDetail) {
-    // either the callback gets called,
-    // or the wallet will redirect the browser
-    callWallet("taler-pay", p, handlePaymentResponse);
-  }
-
   export function pay(p: PayDetail) {
     if (!installed) {
       logVerbose && console.log("delaying call to 'pay' until GNU Taler wallet 
is present");
@@ -251,7 +155,18 @@ namespace taler {
       });
       return;
     }
-    internalPay(p);
+    callWallet("taler-pay", p);
+  }
+
+  export function refund(refundUrl: string) {
+    if (!installed) {
+      logVerbose && console.log("delaying call to 'refund' until GNU Taler 
wallet is present");
+      taler.onPresent(() => {
+        refund(refundUrl);
+      });
+      return;
+    }
+    callWallet("taler-refund", refundUrl);
   }
 
   export interface AuditorDetail {
@@ -262,13 +177,6 @@ namespace taler {
   }
 
 
-  export function internalAddAuditor(d: AuditorDetail) {
-    // either the callback gets called,
-    // or the wallet will redirect the browser
-    callWallet("taler-add-auditor", d);
-  }
-
-
   export function addAuditor(d: AuditorDetail) {
     if (!installed) {
       logVerbose && console.log("delaying call to 'addAuditor' until GNU Taler 
wallet is present");
@@ -277,14 +185,7 @@ namespace taler {
       });
       return;
     }
-    internalAddAuditor(d);
-  }
-
-
-  export function internalCheckAuditor(url: string): 
Promise<AuditorDetail|undefined> {
-    return new Promise<AuditorDetail|undefined>((resolve, reject) => {
-      callWallet("taler-check-auditor", url, (x: any) => resolve(x as 
AuditorDetail));
-    });
+    callWallet("taler-add-auditor", d);
   }
 
 
@@ -302,7 +203,11 @@ namespace taler {
         });
       });
     }
-    return internalCheckAuditor(url);
+    return new Promise<AuditorDetail|undefined>((resolve, reject) => {
+      taler.onPresent(() => {
+        callWallet("taler-check-auditor", url, (x: any) => resolve(x));
+      });
+    });
   }
 
 

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



reply via email to

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