merchant

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

get_kyc_status.c (4386B)


      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_pq_lib.h>
     23 #include "merchant-database/get_kyc_status.h"
     24 #include "helper.h"
     25 
     26 
     27 enum GNUNET_DB_QueryStatus
     28 TALER_MERCHANTDB_get_kyc_status (
     29   struct TALER_MERCHANTDB_PostgresContext *pg,
     30   struct TALER_FullPayto merchant_account_uri,
     31   const char *instance_id,
     32   const char *exchange_url,
     33   bool *auth_ok,
     34   struct TALER_AccountAccessTokenP *access_token,
     35   bool *kyc_ok,
     36   unsigned int *last_http_status,
     37   enum TALER_ErrorCode *last_ec,
     38   uint64_t *rule_gen,
     39   struct GNUNET_TIME_Timestamp *last_kyc_check,
     40   struct GNUNET_TIME_Absolute *next_kyc_poll,
     41   struct GNUNET_TIME_Relative *kyc_backoff,
     42   bool *aml_review,
     43   json_t **jlimits)
     44 {
     45   struct GNUNET_PQ_QueryParam params[] = {
     46     GNUNET_PQ_query_param_string (merchant_account_uri.full_payto),
     47     GNUNET_PQ_query_param_string (exchange_url),
     48     GNUNET_PQ_query_param_end
     49   };
     50   uint32_t h32 = 0;
     51   uint32_t e32 = 0;
     52   bool token_is_null = true;
     53   struct GNUNET_PQ_ResultSpec rs[] = {
     54     GNUNET_PQ_result_spec_allow_null (
     55       GNUNET_PQ_result_spec_auto_from_type ("access_token",
     56                                             access_token),
     57       &token_is_null),
     58     GNUNET_PQ_result_spec_uint32 ("exchange_http_status",
     59                                   &h32),
     60     GNUNET_PQ_result_spec_uint32 ("exchange_ec_code",
     61                                   &e32),
     62     GNUNET_PQ_result_spec_uint64 ("last_rule_gen",
     63                                   rule_gen),
     64     GNUNET_PQ_result_spec_bool ("kyc_ok",
     65                                 kyc_ok),
     66     GNUNET_PQ_result_spec_timestamp ("kyc_timestamp",
     67                                      last_kyc_check),
     68     GNUNET_PQ_result_spec_absolute_time ("next_kyc_poll",
     69                                          next_kyc_poll),
     70     GNUNET_PQ_result_spec_relative_time ("kyc_backoff",
     71                                          kyc_backoff),
     72     GNUNET_PQ_result_spec_bool ("aml_review",
     73                                 aml_review),
     74     GNUNET_PQ_result_spec_allow_null (
     75       TALER_PQ_result_spec_json ("jaccount_limits",
     76                                  jlimits),
     77       NULL),
     78     GNUNET_PQ_result_spec_end
     79   };
     80   enum GNUNET_DB_QueryStatus qs;
     81 
     82   GNUNET_assert (NULL != pg->current_merchant_id);
     83   GNUNET_assert (0 == strcmp (instance_id,
     84                               pg->current_merchant_id));
     85   check_connection (pg);
     86   TMH_PQ_prepare_anon (pg,
     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=$2"
    100                        "   AND mk.account_serial="
    101                        "   (SELECT account_serial"
    102                        "      FROM merchant_accounts"
    103                        "     WHERE payto_uri=$1);");
    104   *jlimits = NULL;
    105   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
    106                                                  "",
    107                                                  params,
    108                                                  rs);
    109   *last_ec = (enum TALER_ErrorCode) (int) e32;
    110   *last_http_status = (unsigned int) h32;
    111   *auth_ok = ! token_is_null;
    112   return qs;
    113 }