gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-wallet-webex] branch master updated: merchant QR cod


From: gnunet
Subject: [GNUnet-SVN] [taler-wallet-webex] branch master updated: merchant QR code tool
Date: Tue, 20 Aug 2019 15:59:18 +0200

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

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

The following commit(s) were added to refs/heads/master by this push:
     new 28be8c85 merchant QR code tool
28be8c85 is described below

commit 28be8c8555f8ca2f809fa878d653f2170a2f999c
Author: Florian Dold <address@hidden>
AuthorDate: Tue Aug 20 15:59:05 2019 +0200

    merchant QR code tool
---
 package.json                     |  1 +
 src/headless/taler-wallet-cli.ts | 91 +++++++++++++++++++++++++++++++++-------
 yarn.lock                        |  5 +++
 3 files changed, 82 insertions(+), 15 deletions(-)

diff --git a/package.json b/package.json
index af8d2346..b0a22151 100644
--- a/package.json
+++ b/package.json
@@ -55,6 +55,7 @@
     "axios": "^0.19.0",
     "commander": "^3.0.0",
     "idb-bridge": "^0.0.7",
+    "qrcode-generator": "^1.4.3",
     "source-map-support": "^0.5.12",
     "urijs": "^1.18.10"
   }
diff --git a/src/headless/taler-wallet-cli.ts b/src/headless/taler-wallet-cli.ts
index 0f40c473..0a7529e4 100644
--- a/src/headless/taler-wallet-cli.ts
+++ b/src/headless/taler-wallet-cli.ts
@@ -20,11 +20,11 @@ import { getDefaultNodeWallet, withdrawTestBalance } from 
"./helpers";
 import { MerchantBackendConnection } from "./merchant";
 import { runIntegrationTest } from "./integrationtest";
 import { Wallet } from "../wallet";
+import querystring = require("querystring");
+import qrcodeGenerator = require("qrcode-generator")
 
 const program = new commander.Command();
-program
-  .version("0.0.1")
-  .option('--verbose', "enable verbose output", false);
+program.version("0.0.1").option("--verbose", "enable verbose output", false);
 
 const walletDbPath = os.homedir + "/" + ".talerwalletdb.json";
 
@@ -39,7 +39,7 @@ program
   .command("test-withdraw")
   .description("withdraw test currency from the test bank")
   .action(async () => {
-    applyVerbose(program.verbose)
+    applyVerbose(program.verbose);
     console.log("test-withdraw command called");
     const wallet = await getDefaultNodeWallet({
       persistentStoragePath: walletDbPath,
@@ -52,7 +52,7 @@ program
   .command("balance")
   .description("show wallet balance")
   .action(async () => {
-    applyVerbose(program.verbose)
+    applyVerbose(program.verbose);
     console.log("balance command called");
     const wallet = await getDefaultNodeWallet({
       persistentStoragePath: walletDbPath,
@@ -63,19 +63,80 @@ program
     process.exit(0);
   });
 
+async function asyncSleep(milliSeconds: number): Promise<void> {
+  return new Promise<void>((resolve, reject) =>{
+    setTimeout(() => resolve(), milliSeconds)
+  });
+}
+
+program
+  .command("test-merchant-qrcode")
+  .option("-a, --amount <spend-amt>", "amount to spend", "TESTKUDOS:1")
+  .option("-s, --summary <summary>", "contract summary", "Test Payment")
+  .action(async cmdObj => {
+    applyVerbose(program.verbose);
+    console.log("creating order");
+    const merchantBackend = new 
MerchantBackendConnection("https://backend.test.taler.net";, "default", 
"sandbox");
+    const orderResp = await merchantBackend.createOrder(cmdObj.amount, 
cmdObj.summary, "");
+    console.log("created new order with order ID", orderResp.orderId);
+    const checkPayResp = await merchantBackend.checkPayment(orderResp.orderId);
+    const qrcode = qrcodeGenerator(0, "M");
+    const contractUrl = checkPayResp.contract_url;
+    if (typeof contractUrl !== "string") {
+      console.error("fata: no contract url received from backend");
+      process.exit(1);
+      return;
+    }
+    qrcode.addData("talerpay:" + querystring.escape(contractUrl));
+    qrcode.make();
+    console.log(qrcode.createASCII());
+    console.log("waiting for payment ...")
+    while (1) {
+      await asyncSleep(500);
+      const checkPayResp2 = await 
merchantBackend.checkPayment(orderResp.orderId);
+      if (checkPayResp2.paid) {
+        console.log("payment successfully received!")
+        break;
+      }
+    }
+  });
 
 program
   .command("integrationtest")
-  .option('-e, --exchange <exchange-url>', 'exchange base URL', 
"https://exchange.test.taler.net/";)
-  .option('-m, --merchant <merchant-url>', 'merchant base URL', 
"https://backend.test.taler.net/";)
-  .option('-m, --merchant-instance <merchant-instance>', 'merchant instance', 
"default")
-  .option('-m, --merchant-api-key <merchant-api-key>', 'merchant API key', 
"sandbox")
-  .option('-b, --bank <bank-url>', 'bank base URL', 
"https://bank.test.taler.net/";)
-  .option('-w, --withdraw-amount <withdraw-amt>', 'amount to withdraw', 
"TESTKUDOS:10")
-  .option('-s, --spend-amount <spend-amt>', 'amount to spend', "TESTKUDOS:5")
+  .option(
+    "-e, --exchange <exchange-url>",
+    "exchange base URL",
+    "https://exchange.test.taler.net/";,
+  )
+  .option(
+    "-m, --merchant <merchant-url>",
+    "merchant base URL",
+    "https://backend.test.taler.net/";,
+  )
+  .option(
+    "-m, --merchant-instance <merchant-instance>",
+    "merchant instance",
+    "default",
+  )
+  .option(
+    "-m, --merchant-api-key <merchant-api-key>",
+    "merchant API key",
+    "sandbox",
+  )
+  .option(
+    "-b, --bank <bank-url>",
+    "bank base URL",
+    "https://bank.test.taler.net/";,
+  )
+  .option(
+    "-w, --withdraw-amount <withdraw-amt>",
+    "amount to withdraw",
+    "TESTKUDOS:10",
+  )
+  .option("-s, --spend-amount <spend-amt>", "amount to spend", "TESTKUDOS:5")
   .description("Run integration test with bank, exchange and merchant.")
-  .action(async (cmdObj) => {
-    applyVerbose(program.verbose)
+  .action(async cmdObj => {
+    applyVerbose(program.verbose);
 
     await runIntegrationTest({
       amountToSpend: cmdObj.spendAmount,
@@ -106,5 +167,5 @@ program.parse(process.argv);
 
 if (process.argv.length <= 2) {
   console.error("Error: No command given.");
-  program.help();  
+  program.help();
 }
diff --git a/yarn.lock b/yarn.lock
index 370b4e7b..54ad479d 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -5138,6 +5138,11 @@ punycode@^2.1.0:
   resolved 
"https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec";
   integrity 
sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==
 
+qrcode-generator@^1.4.3:
+  version "1.4.3"
+  resolved 
"https://registry.yarnpkg.com/qrcode-generator/-/qrcode-generator-1.4.3.tgz#4876e8f280e65b6c94615f4c19c484f6b964b199";
+  integrity 
sha512-++rVRvMRq5BlHfmAafl8a4ppUntzUxCCUTT2t0siUgqKwdnqRzY8IH6f6WSX5dZUhD2Ul5/MIKuTJddflwrGzw==
+
 qs@6.7.0:
   version "6.7.0"
   resolved 
"https://registry.yarnpkg.com/qs/-/qs-6.7.0.tgz#41dc1a015e3d581f1621776be31afb2876a9b1bc";

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



reply via email to

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