merchant

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

pg_get_kyc_status.c (4342B)


      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 backenddb/pg_get_kyc_status.c
     18  * @brief Implementation of the get_kyc_status function for Postgres
     19  * @author Christian Grothoff
     20  */
     21 #include "taler/platform.h"
     22 #include <taler/taler_error_codes.h>
     23 #include <taler/taler_dbevents.h>
     24 #include <taler/taler_pq_lib.h>
     25 #include "pg_get_kyc_status.h"
     26 #include "pg_helper.h"
     27 
     28 
     29 enum GNUNET_DB_QueryStatus
     30 TMH_PG_get_kyc_status (
     31   void *cls,
     32   struct TALER_FullPayto merchant_account_uri,
     33   const char *instance_id,
     34   const char *exchange_url,
     35   bool *auth_ok,
     36   struct TALER_AccountAccessTokenP *access_token,
     37   bool *kyc_ok,
     38   unsigned int *last_http_status,
     39   enum TALER_ErrorCode *last_ec,
     40   uint64_t *rule_gen,
     41   struct GNUNET_TIME_Timestamp *last_kyc_check,
     42   struct GNUNET_TIME_Absolute *next_kyc_poll,
     43   struct GNUNET_TIME_Relative *kyc_backoff,
     44   bool *aml_review,
     45   json_t **jlimits)
     46 {
     47   struct PostgresClosure *pg = cls;
     48   struct GNUNET_PQ_QueryParam params[] = {
     49     GNUNET_PQ_query_param_string (merchant_account_uri.full_payto),
     50     GNUNET_PQ_query_param_string (instance_id),
     51     GNUNET_PQ_query_param_string (exchange_url),
     52     GNUNET_PQ_query_param_end
     53   };
     54   uint32_t h32 = 0;
     55   uint32_t e32 = 0;
     56   bool token_is_null = true;
     57   struct GNUNET_PQ_ResultSpec rs[] = {
     58     GNUNET_PQ_result_spec_allow_null (
     59       GNUNET_PQ_result_spec_auto_from_type ("access_token",
     60                                             access_token),
     61       &token_is_null),
     62     GNUNET_PQ_result_spec_uint32 ("exchange_http_status",
     63                                   &h32),
     64     GNUNET_PQ_result_spec_uint32 ("exchange_ec_code",
     65                                   &e32),
     66     GNUNET_PQ_result_spec_uint64 ("last_rule_gen",
     67                                   rule_gen),
     68     GNUNET_PQ_result_spec_bool ("kyc_ok",
     69                                 kyc_ok),
     70     GNUNET_PQ_result_spec_timestamp ("kyc_timestamp",
     71                                      last_kyc_check),
     72     GNUNET_PQ_result_spec_absolute_time ("next_kyc_poll",
     73                                          next_kyc_poll),
     74     GNUNET_PQ_result_spec_relative_time ("kyc_backoff",
     75                                          kyc_backoff),
     76     GNUNET_PQ_result_spec_bool ("aml_review",
     77                                 aml_review),
     78     GNUNET_PQ_result_spec_allow_null (
     79       TALER_PQ_result_spec_json ("jaccount_limits",
     80                                  jlimits),
     81       NULL),
     82     GNUNET_PQ_result_spec_end
     83   };
     84   enum GNUNET_DB_QueryStatus qs;
     85 
     86   check_connection (pg);
     87   PREPARE (pg,
     88            "get_kyc_status",
     89            "SELECT"
     90            " mk.access_token"
     91            ",mk.exchange_http_status"
     92            ",mk.exchange_ec_code"
     93            ",mk.kyc_ok"
     94            ",mk.last_rule_gen"
     95            ",mk.kyc_timestamp"
     96            ",mk.next_kyc_poll"
     97            ",mk.kyc_backoff"
     98            ",mk.aml_review"
     99            ",mk.jaccount_limits::TEXT"
    100            " FROM merchant_kyc mk"
    101            " WHERE mk.exchange_url=$3"
    102            "   AND mk.account_serial="
    103            "   (SELECT account_serial"
    104            "      FROM merchant_accounts"
    105            "     WHERE payto_uri=$1"
    106            "       AND merchant_serial="
    107            "       (SELECT merchant_serial"
    108            "          FROM merchant_instances"
    109            "         WHERE merchant_id=$2));");
    110   *jlimits = NULL;
    111   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
    112                                                  "get_kyc_status",
    113                                                  params,
    114                                                  rs);
    115   *last_ec = (enum TALER_ErrorCode) (int) e32;
    116   *last_http_status = (unsigned int) h32;
    117   *auth_ok = ! token_is_null;
    118   return qs;
    119 }