merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

get_kyc_status.c (4788B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2024, 2026 Taler Systems SA
      4 
      5    TALER is free software; you can redistribute it and/or modify it under the
      6    terms of the GNU General Public License as published by the Free Software
      7    Foundation; either version 3, or (at your option) any later version.
      8 
      9    TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     10    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11    A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12 
     13    You should have received a copy of the GNU General Public License along with
     14    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15  */
     16 /**
     17  * @file src/backenddb/get_kyc_status.c
     18  * @brief Implementation of the get_kyc_status function for Postgres
     19  * @author Christian Grothoff
     20  */
     21 #include "platform.h"
     22 #include <taler/taler_error_codes.h>
     23 #include <taler/taler_dbevents.h>
     24 #include <taler/taler_pq_lib.h>
     25 #include "merchant-database/get_kyc_status.h"
     26 #include "helper.h"
     27 
     28 
     29 enum GNUNET_DB_QueryStatus
     30 TALER_MERCHANTDB_get_kyc_status (struct TALER_MERCHANTDB_PostgresContext *pg,
     31                                  struct TALER_FullPayto merchant_account_uri,
     32                                  const char *instance_id,
     33                                  const char *exchange_url,
     34                                  bool *auth_ok,
     35                                  struct TALER_AccountAccessTokenP *access_token,
     36                                  bool *kyc_ok,
     37                                  unsigned int *last_http_status,
     38                                  enum TALER_ErrorCode *last_ec,
     39                                  uint64_t *rule_gen,
     40                                  struct GNUNET_TIME_Timestamp *last_kyc_check,
     41                                  struct GNUNET_TIME_Absolute *next_kyc_poll,
     42                                  struct GNUNET_TIME_Relative *kyc_backoff,
     43                                  bool *aml_review,
     44                                  json_t **jlimits)
     45 {
     46   struct GNUNET_PQ_QueryParam params[] = {
     47     GNUNET_PQ_query_param_string (merchant_account_uri.full_payto),
     48     GNUNET_PQ_query_param_string (instance_id),
     49     GNUNET_PQ_query_param_string (exchange_url),
     50     GNUNET_PQ_query_param_end
     51   };
     52   uint32_t h32 = 0;
     53   uint32_t e32 = 0;
     54   bool token_is_null = true;
     55   struct GNUNET_PQ_ResultSpec rs[] = {
     56     GNUNET_PQ_result_spec_allow_null (
     57       GNUNET_PQ_result_spec_auto_from_type ("access_token",
     58                                             access_token),
     59       &token_is_null),
     60     GNUNET_PQ_result_spec_uint32 ("exchange_http_status",
     61                                   &h32),
     62     GNUNET_PQ_result_spec_uint32 ("exchange_ec_code",
     63                                   &e32),
     64     GNUNET_PQ_result_spec_uint64 ("last_rule_gen",
     65                                   rule_gen),
     66     GNUNET_PQ_result_spec_bool ("kyc_ok",
     67                                 kyc_ok),
     68     GNUNET_PQ_result_spec_timestamp ("kyc_timestamp",
     69                                      last_kyc_check),
     70     GNUNET_PQ_result_spec_absolute_time ("next_kyc_poll",
     71                                          next_kyc_poll),
     72     GNUNET_PQ_result_spec_relative_time ("kyc_backoff",
     73                                          kyc_backoff),
     74     GNUNET_PQ_result_spec_bool ("aml_review",
     75                                 aml_review),
     76     GNUNET_PQ_result_spec_allow_null (
     77       TALER_PQ_result_spec_json ("jaccount_limits",
     78                                  jlimits),
     79       NULL),
     80     GNUNET_PQ_result_spec_end
     81   };
     82   enum GNUNET_DB_QueryStatus qs;
     83 
     84   check_connection (pg);
     85   PREPARE (pg,
     86            "get_kyc_status",
     87            "SELECT"
     88            " mk.access_token"
     89            ",mk.exchange_http_status"
     90            ",mk.exchange_ec_code"
     91            ",mk.kyc_ok"
     92            ",mk.last_rule_gen"
     93            ",mk.kyc_timestamp"
     94            ",mk.next_kyc_poll"
     95            ",mk.kyc_backoff"
     96            ",mk.aml_review"
     97            ",mk.jaccount_limits::TEXT"
     98            " FROM merchant_kyc mk"
     99            " WHERE mk.exchange_url=$3"
    100            "   AND mk.account_serial="
    101            "   (SELECT account_serial"
    102            "      FROM merchant_accounts"
    103            "     WHERE payto_uri=$1"
    104            "       AND merchant_serial="
    105            "       (SELECT merchant_serial"
    106            "          FROM merchant_instances"
    107            "         WHERE merchant_id=$2));");
    108   *jlimits = NULL;
    109   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
    110                                                  "get_kyc_status",
    111                                                  params,
    112                                                  rs);
    113   *last_ec = (enum TALER_ErrorCode) (int) e32;
    114   *last_http_status = (unsigned int) h32;
    115   *auth_ok = ! token_is_null;
    116   return qs;
    117 }