gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: add parsing of full kyc-status r


From: gnunet
Subject: [taler-merchant] branch master updated: add parsing of full kyc-status response to libtalermerchant
Date: Fri, 06 Sep 2024 18:17:54 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 39704d64 add parsing of full kyc-status response to libtalermerchant
39704d64 is described below

commit 39704d64354aec25ab944677265031fa3048b4fb
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Fri Sep 6 18:17:46 2024 +0200

    add parsing of full kyc-status response to libtalermerchant
---
 src/include/taler_merchant_service.h  |   9 +--
 src/lib/merchant_api_get_kyc.c        | 129 ++++++++++++++++++++++++++++++++--
 src/lib/merchant_api_post_order_pay.c |  16 ++---
 3 files changed, 135 insertions(+), 19 deletions(-)

diff --git a/src/include/taler_merchant_service.h 
b/src/include/taler_merchant_service.h
index c1861f64..b1840ea8 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -4381,7 +4381,8 @@ struct TALER_MERCHANT_AccountKycRedirectDetail
 {
 
   /**
-   * Access token the user needs to start a KYC process.
+   * Access token the user needs to start a KYC process,
+   * all zero if a KYC auth transfer must be made first.
    */
   struct TALER_AccountAccessTokenP access_token;
 
@@ -4407,18 +4408,14 @@ struct TALER_MERCHANT_AccountKycRedirectDetail
   /**
    * Array of length @e limits_array with (exposed) limits that apply to the
    * account.
-   *
-   * FIXME: not yet returned.
    */
-  struct TALER_EXCHANGE_AccountLimit *limits;
+  const struct TALER_EXCHANGE_AccountLimit *limits;
 
   /**
    * Array of payto://-URIs with instructions for wire
    * transfers to perform a KYC auth wire transfer for
    * the given account. Needed if @e kyc_url is NULL
    * and @e limits are to be passed.
-   *
-   * FIXME: not yet returned.
    */
   const char **payto_kycauths;
 
diff --git a/src/lib/merchant_api_get_kyc.c b/src/lib/merchant_api_get_kyc.c
index 0e35ee79..bf5d4300 100644
--- a/src/lib/merchant_api_get_kyc.c
+++ b/src/lib/merchant_api_get_kyc.c
@@ -1,6 +1,6 @@
 /*
   This file is part of TALER
-  Copyright (C) 2023 Taler Systems SA
+  Copyright (C) 2023--2024 Taler Systems SA
 
   TALER is free software; you can redistribute it and/or modify it under the
   terms of the GNU Lesser General Public License as published by the Free 
Software
@@ -86,6 +86,10 @@ parse_kyc (struct TALER_MERCHANT_KycGetHandle *kyc,
 {
   unsigned int num_pends = (unsigned int) json_array_size (pends);
   unsigned int num_touts = (unsigned int) json_array_size (touts);
+  unsigned int num_limits = 0;
+  unsigned int num_kycauths = 0;
+  unsigned int pos_limits = 0;
+  unsigned int pos_kycauths = 0;
 
   if ( (json_array_size (pends) != (size_t)  num_pends) ||
        (num_pends > MAX_KYC) )
@@ -100,32 +104,89 @@ parse_kyc (struct TALER_MERCHANT_KycGetHandle *kyc,
     return GNUNET_SYSERR;
   }
 
+  for (unsigned int i = 0; i<num_pends; i++)
+  {
+    const json_t *jlimits = NULL;
+    const json_t *jkycauths = NULL;
+    struct GNUNET_JSON_Specification spec[] = {
+      GNUNET_JSON_spec_mark_optional (
+        GNUNET_JSON_spec_array_const (
+          "limits",
+          &jlimits),
+        NULL),
+      GNUNET_JSON_spec_mark_optional (
+        GNUNET_JSON_spec_array_const (
+          "payto_kycauths",
+          &jkycauths),
+        NULL),
+      GNUNET_JSON_spec_end ()
+    };
+
+    if (GNUNET_OK !=
+        GNUNET_JSON_parse (json_array_get (pends,
+                                           i),
+                           spec,
+                           NULL, NULL))
+    {
+      GNUNET_break (0);
+      json_dumpf (json_array_get (pends,
+                                  i),
+                  stderr,
+                  JSON_INDENT (2));
+      return GNUNET_SYSERR;
+    }
+    num_limits += json_array_size (jlimits);
+    num_kycauths += json_array_size (jkycauths);
+  }
+
+
   {
     struct TALER_MERCHANT_AccountKycRedirectDetail pending_kycs[
       GNUNET_NZL (num_pends)];
     struct TALER_MERCHANT_ExchangeKycFailureDetail timeout_kycs[
       GNUNET_NZL (num_touts)];
+    struct TALER_EXCHANGE_AccountLimit limits[
+      GNUNET_NZL (num_limits)];
+    const char *payto_kycauths[
+      GNUNET_NZL (num_kycauths)];
 
     memset (pending_kycs,
             0,
             sizeof (pending_kycs));
     for (unsigned int i = 0; i<num_pends; i++)
     {
+      struct TALER_MERCHANT_AccountKycRedirectDetail *rd
+        = &pending_kycs[i];
+      const json_t *jlimits = NULL;
+      const json_t *jkycauths = NULL;
       struct GNUNET_JSON_Specification spec[] = {
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_array_const (
+            "limits",
+            &jlimits),
+          NULL),
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_array_const (
+            "payto_kycauths",
+            &jkycauths),
+          NULL),
         GNUNET_JSON_spec_fixed_auto (
           "access_token",
-          &pending_kycs[i].access_token),
+          &rd->access_token),
         TALER_JSON_spec_web_url (
           "kyc_url",
-          &pending_kycs[i].kyc_url),
+          &rd->kyc_url),
         TALER_JSON_spec_web_url (
           "exchange_url",
-          &pending_kycs[i].exchange_url),
+          &rd->exchange_url),
         TALER_JSON_spec_payto_uri (
           "payto_uri",
-          &pending_kycs[i].payto_uri),
+          &rd->payto_uri),
         GNUNET_JSON_spec_end ()
       };
+      size_t j;
+      json_t *jlimit;
+      json_t *jkycauth;
 
       if (GNUNET_OK !=
           GNUNET_JSON_parse (json_array_get (pends,
@@ -140,6 +201,64 @@ parse_kyc (struct TALER_MERCHANT_KycGetHandle *kyc,
                     JSON_INDENT (2));
         return GNUNET_SYSERR;
       }
+      rd->limits = &limits[pos_limits];
+      rd->limits_length = json_array_size (jlimits);
+      json_array_foreach (jlimits, j, jlimit)
+      {
+        struct TALER_EXCHANGE_AccountLimit *limit
+          = &limits[pos_limits];
+        struct GNUNET_JSON_Specification jspec[] = {
+          TALER_JSON_spec_kycte (
+            "operation_type",
+            &limit->operation_type),
+          GNUNET_JSON_spec_relative_time (
+            "timeframe",
+            &limit->timeframe),
+          TALER_JSON_spec_amount_any (
+            "threshold",
+            &limit->threshold),
+          GNUNET_JSON_spec_mark_optional (
+            GNUNET_JSON_spec_bool (
+              "soft_limit",
+              &limit->soft_limit),
+            NULL),
+          GNUNET_JSON_spec_end ()
+        };
+
+        GNUNET_assert (pos_limits < num_limits);
+        limit->soft_limit = false;
+        if (GNUNET_OK !=
+            GNUNET_JSON_parse (jlimit,
+                               jspec,
+                               NULL, NULL))
+        {
+          GNUNET_break (0);
+          json_dumpf (json_array_get (pends,
+                                      i),
+                      stderr,
+                      JSON_INDENT (2));
+          return GNUNET_SYSERR;
+        }
+        pos_limits++;
+      }
+      rd->payto_kycauths = &payto_kycauths[pos_kycauths];
+      rd->pkycauth_length = json_array_size (jkycauths);
+      json_array_foreach (jkycauths, j, jkycauth)
+      {
+        GNUNET_assert (pos_kycauths < num_kycauths);
+        payto_kycauths[pos_kycauths]
+          = json_string_value (jkycauth);
+        if (NULL == payto_kycauths[pos_kycauths])
+        {
+          GNUNET_break (0);
+          json_dumpf (json_array_get (pends,
+                                      i),
+                      stderr,
+                      JSON_INDENT (2));
+          return GNUNET_SYSERR;
+        }
+        pos_kycauths++;
+      }
     }
     for (unsigned int i = 0; i<num_touts; i++)
     {
diff --git a/src/lib/merchant_api_post_order_pay.c 
b/src/lib/merchant_api_post_order_pay.c
index 77e14c02..14eebd28 100644
--- a/src/lib/merchant_api_post_order_pay.c
+++ b/src/lib/merchant_api_post_order_pay.c
@@ -144,20 +144,20 @@ parse_tokens (const json_t *token_sigs,
   for (unsigned int i = 0; i<(*num_tokens); i++)
   {
     struct TALER_MERCHANT_OutputToken *token = &(*tokens)[i];
-    const json_t *jtoken = json_array_get (token_sigs,
-                                           i);
-
-    if (NULL == jtoken)
-    {
-      GNUNET_break (0);
-      return GNUNET_SYSERR;
-    }
     struct GNUNET_JSON_Specification spec[] = {
       TALER_JSON_spec_blinded_token_issue_sig ("blind_sig",
                                                &token->blinded_sig),
       GNUNET_JSON_spec_end ()
     };
+    const json_t *jtoken
+      = json_array_get (token_sigs,
+                        i);
 
+    if (NULL == jtoken)
+    {
+      GNUNET_break (0);
+      return GNUNET_SYSERR;
+    }
     if (GNUNET_OK !=
         GNUNET_JSON_parse (jtoken,
                            spec,

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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