gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] 02/02: protocol changes


From: gnunet
Subject: [taler-wallet-core] 02/02: protocol changes
Date: Fri, 01 Nov 2019 18:39:28 +0100

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

dold pushed a commit to branch master
in repository wallet-core.

commit ae8a00527168b13aa59ddc2fbd1f88a0f1e2669c
Author: Florian Dold <address@hidden>
AuthorDate: Fri Nov 1 18:39:23 2019 +0100

    protocol changes
---
 src/talerTypes.ts       |  4 ++--
 src/taleruri-test.ts    | 56 ++++++++++++++++++++++++++++++++++++++++++++++++-
 src/taleruri.ts         | 27 ++++++++++++------------
 src/types-test.ts       |  2 +-
 src/wallet.ts           | 16 +++++++-------
 src/webex/pages/pay.tsx | 14 ++++++++++++-
 src/webex/wxApi.ts      |  1 +
 7 files changed, 95 insertions(+), 25 deletions(-)

diff --git a/src/talerTypes.ts b/src/talerTypes.ts
index 73b97c93..e28b35c7 100644
--- a/src/talerTypes.ts
+++ b/src/talerTypes.ts
@@ -402,10 +402,10 @@ export class ContractTerms {
   order_id: string;
 
   /**
-   * URL to post the payment to.
+   * Base URL of the merchant's backend.
    */
   @Checkable.String()
-  pay_url: string;
+  merchant_base_url: string;
 
   /**
    * Fulfillment URL to view the product or
diff --git a/src/taleruri-test.ts b/src/taleruri-test.ts
index bf4e9d49..360f565f 100644
--- a/src/taleruri-test.ts
+++ b/src/taleruri-test.ts
@@ -15,7 +15,7 @@
  */
 
 import test from "ava";
-import { parsePayUri, parseWithdrawUri } from "./taleruri";
+import { parsePayUri, parseWithdrawUri, parseRefundUri, parseTipUri } from 
"./taleruri";
 
 test("taler pay url parsing: http(s)", (t) => {
   const url1 = "https://example.com/bar?spam=eggs";;
@@ -150,3 +150,57 @@ test("taler withdraw uri parsing", (t) => {
   }
   t.is(r1.statusUrl, "https://bank.example.com/api/withdraw-operation/12345";);
 });
+
+
+test("taler refund uri parsing", (t) => {
+  const url1 = "taler://refund/merchant.example.com/-/-/1234";
+  const r1 = parseRefundUri(url1);
+  if (!r1) {
+    t.fail();
+    return;
+  }
+  t.is(r1.refundUrl, 
"https://merchant.example.com/public/refund?order_id=1234";);
+});
+
+
+test("taler refund uri parsing with instance", (t) => {
+  const url1 = "taler://refund/merchant.example.com/-/myinst/1234";
+  const r1 = parseRefundUri(url1);
+  if (!r1) {
+    t.fail();
+    return;
+  }
+  t.is(r1.refundUrl, 
"https://merchant.example.com/public/instances/myinst/refund?order_id=1234";);
+});
+
+test("taler tip pickup uri", (t) => {
+  const url1 = "taler://tip/merchant.example.com/-/-/tipid";
+  const r1 = parseTipUri(url1);
+  if (!r1) {
+    t.fail();
+    return;
+  }
+  t.is(r1.tipPickupUrl, 
"https://merchant.example.com/public/tip-pickup?tip_id=tipid";);
+});
+
+
+test("taler tip pickup uri with instance", (t) => {
+  const url1 = "taler://tip/merchant.example.com/-/tipm/tipid";
+  const r1 = parseTipUri(url1);
+  if (!r1) {
+    t.fail();
+    return;
+  }
+  t.is(r1.tipPickupUrl, 
"https://merchant.example.com/public/instances/tipm/tip-pickup?tip_id=tipid";);
+});
+
+
+test("taler tip pickup uri with instance and prefix", (t) => {
+  const url1 = "taler://tip/merchant.example.com/my%2fpfx/tipm/tipid";
+  const r1 = parseTipUri(url1);
+  if (!r1) {
+    t.fail();
+    return;
+  }
+  t.is(r1.tipPickupUrl, 
"https://merchant.example.com/my/pfx/instances/tipm/tip-pickup?tip_id=tipid";);
+});
diff --git a/src/taleruri.ts b/src/taleruri.ts
index 0af5c4c9..c810def2 100644
--- a/src/taleruri.ts
+++ b/src/taleruri.ts
@@ -147,17 +147,18 @@ export function parseTipUri(s: string): TipUriResult | 
undefined {
   }
 
   if (maybePath === "-") {
-    maybePath = "public/tip-pickup";
+    maybePath = "public/";
   } else {
-    maybePath = decodeURIComponent(maybePath);
+    maybePath = decodeURIComponent(maybePath) + "/";
   }
-  if (maybeInstance === "-") {
-    maybeInstance = "default";
+  let maybeInstancePath = "";
+  if (maybeInstance !== "-") {
+    maybeInstancePath = `instances/${maybeInstance}/`;
   }
 
   const tipPickupUrl = new URI(
-    "https://"; + host + "/" + decodeURIComponent(maybePath),
-  ).href();
+    "https://"; + host + "/" + maybePath + maybeInstancePath + "tip-pickup",
+  ).addQuery({ tip_id: tipId }).href();
 
   return {
     tipPickupUrl,
@@ -197,20 +198,20 @@ export function parseRefundUri(s: string): 
RefundUriResult | undefined {
   }
 
   if (maybePath === "-") {
-    maybePath = "public/refund";
+    maybePath = "public/";
   } else {
-    maybePath = decodeURIComponent(maybePath);
+    maybePath = decodeURIComponent(maybePath) + "/";
   }
-  if (maybeInstance === "-") {
-    maybeInstance = "default";
+  let maybeInstancePath = "";
+  if (maybeInstance !== "-") {
+    maybeInstancePath = `instances/${maybeInstance}/`;
   }
 
   const refundUrl = new URI(
-    "https://"; + host + "/" + decodeURIComponent(maybePath),
+    "https://"; + host + "/" + maybePath + maybeInstancePath + "refund",
   )
-    .addQuery({ instance: maybeInstance, order_id: orderId })
+    .addQuery({ order_id: orderId })
     .href();
-
   return {
     refundUrl,
   };
diff --git a/src/types-test.ts b/src/types-test.ts
index 51c4d69c..3ba059de 100644
--- a/src/types-test.ts
+++ b/src/types-test.ts
@@ -115,7 +115,7 @@ test("contract terms validation", (t) => {
     merchant_pub: "12345",
     order_id: "test_order",
     pay_deadline: "Date(12346)",
-    pay_url: "https://example.com/pay";,
+    merchant_base_url: "https://example.com/pay";,
     products: [],
     refund_deadline: "Date(12345)",
     summary: "hello",
diff --git a/src/wallet.ts b/src/wallet.ts
index 25857870..29475cc7 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -965,15 +965,17 @@ export class Wallet {
     let resp;
     const payReq = { ...purchase.payReq, session_id: sessionId };
 
+    const payUrl = new 
URI("pay").absoluteTo(purchase.contractTerms.merchant_base_url).href()
+
     try {
-      resp = await this.http.postJson(purchase.contractTerms.pay_url, payReq);
+      resp = await this.http.postJson(payUrl, payReq);
     } catch (e) {
       // Gives the user the option to retry / abort and refresh
       console.log("payment failed", e);
       throw e;
     }
     const merchantResp = resp.responseJson;
-    console.log("got success from pay_url");
+    console.log("got success from pay URL");
 
     const merchantPub = purchase.contractTerms.merchant_pub;
     const valid: boolean = await this.cryptoApi.isValidPaymentSignature(
@@ -3033,7 +3035,7 @@ export class Wallet {
       merchant_pub: pub,
       order_id: "none",
       pay_deadline: `/Date(${stampSecNow + 60 * 5})/`,
-      pay_url: "",
+      merchant_base_url: "taler://return-to-account",
       products: [],
       refund_deadline: `/Date(${stampSecNow + 60 * 5})/`,
       timestamp: `/Date(${stampSecNow})/`,
@@ -3466,9 +3468,7 @@ export class Wallet {
       throw Error("invalid taler://tip URI");
     }
 
-    const tipStatusUrl = new URI(res.tipPickupUrl)
-      .addQuery({ tip_id: res.tipId })
-      .href();
+    const tipStatusUrl = new URI(res.tipPickupUrl).href();
     console.log("checking tip status from", tipStatusUrl);
     const merchantResp = await this.http.get(tipStatusUrl);
     console.log("resp:", merchantResp.responseJson);
@@ -3552,8 +3552,10 @@ export class Wallet {
 
     const abortReq = { ...purchase.payReq, mode: "abort-refund" };
 
+    const payUrl = new 
URI("pay").absoluteTo(purchase.contractTerms.merchant_base_url).href()
+
     try {
-      resp = await this.http.postJson(purchase.contractTerms.pay_url, 
abortReq);
+      resp = await this.http.postJson(payUrl, abortReq);
     } catch (e) {
       // Gives the user the option to retry / abort and refresh
       console.log("aborting payment failed", e);
diff --git a/src/webex/pages/pay.tsx b/src/webex/pages/pay.tsx
index 579688db..7f2a174b 100644
--- a/src/webex/pages/pay.tsx
+++ b/src/webex/pages/pay.tsx
@@ -53,6 +53,11 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: 
string }) {
     return <span>Loading payment information ...</span>;
   }
 
+  let insufficientBalance = false;
+  if (payStatus.status == "insufficient-balance") {
+    insufficientBalance = true;
+  }
+
   if (payStatus.status === "error") {
     return <span>Error: {payStatus.error}</span>;
   }
@@ -93,7 +98,7 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: 
string }) {
 
   const doPayment = async () => {
     if (payStatus.status !== "payment-possible") {
-      throw Error("invalid state");
+      throw Error(`invalid state: ${payStatus.status}`);
     }
     const proposalId = payStatus.proposalId;
     setNumTries(numTries + 1);
@@ -128,6 +133,12 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: 
string }) {
         )}
       </p>
 
+      {insufficientBalance ? (
+        <div>
+          <p style={{color: "red", fontWeight: "bold"}}>Unable to pay: Your 
balance is insufficient.</p>
+        </div>
+      ) : null}
+
       {payErrMsg ? (
         <div>
           <p>Payment failed: {payErrMsg}</p>
@@ -142,6 +153,7 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: 
string }) {
         <div>
           <ProgressButton
             loading={loading}
+            disabled={insufficientBalance}
             onClick={() => doPayment()}>
             {i18n.str`Confirm payment`}
           </ProgressButton>
diff --git a/src/webex/wxApi.ts b/src/webex/wxApi.ts
index 65c14ac4..39c31ca5 100644
--- a/src/webex/wxApi.ts
+++ b/src/webex/wxApi.ts
@@ -86,6 +86,7 @@ async function callBackend<T extends MessageType>(
   return new Promise<MessageMap[T]["response"]>((resolve, reject) => {
     chrome.runtime.sendMessage({ type, detail }, (resp) => {
       if (typeof resp === "object" && resp && resp.error) {
+        console.warn("response error:", resp)
         const e = new WalletApiError(resp.error.message, resp.error);
         reject(e);
       } else {

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



reply via email to

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