exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

update_kyc_process_by_row.c (4608B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2022, 2024 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 exchangedb/update_kyc_process_by_row.c
     18  * @brief Implementation of the update_kyc_process_by_row function for Postgres
     19  * @author Christian Grothoff
     20  */
     21 #include "taler/taler_error_codes.h"
     22 #include "taler/taler_pq_lib.h"
     23 #include "exchange-database/update_kyc_process_by_row.h"
     24 #include "helper.h"
     25 
     26 
     27 enum GNUNET_DB_QueryStatus
     28 TALER_EXCHANGEDB_update_kyc_process_by_row (
     29   struct TALER_EXCHANGEDB_PostgresContext *pg,
     30   uint64_t process_row,
     31   const char *provider_name,
     32   const struct TALER_NormalizedPaytoHashP *h_payto,
     33   const char *provider_account_id,
     34   const char *provider_legitimization_id,
     35   const char *redirect_url,
     36   struct GNUNET_TIME_Absolute expiration,
     37   enum TALER_ErrorCode ec,
     38   const char *error_message_hint,
     39   bool finished)
     40 {
     41   uint32_t ec32 = (uint32_t) ec;
     42   struct GNUNET_PQ_QueryParam params[] = {
     43     GNUNET_PQ_query_param_uint64 (&process_row),
     44     GNUNET_PQ_query_param_string (provider_name),
     45     GNUNET_PQ_query_param_auto_from_type (h_payto), /*3*/
     46     (NULL != provider_account_id)
     47     ? GNUNET_PQ_query_param_string (provider_account_id)
     48     : GNUNET_PQ_query_param_null (), /*4*/
     49     (NULL != provider_legitimization_id)
     50     ? GNUNET_PQ_query_param_string (provider_legitimization_id)
     51     : GNUNET_PQ_query_param_null (), /*5*/
     52     (NULL != redirect_url)
     53     ? GNUNET_PQ_query_param_string (redirect_url)
     54     : GNUNET_PQ_query_param_null (), /*6*/
     55     GNUNET_PQ_query_param_absolute_time (&expiration),
     56     GNUNET_PQ_query_param_uint32 (&ec32), /* 8 */
     57     (NULL != error_message_hint)
     58     ? GNUNET_PQ_query_param_string (error_message_hint)
     59     : GNUNET_PQ_query_param_null (),
     60     GNUNET_PQ_query_param_bool (finished), /* 10 */
     61     GNUNET_PQ_query_param_end
     62   };
     63   enum GNUNET_DB_QueryStatus qs;
     64 
     65   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     66               "Updating KYC data for %llu (%s)\n",
     67               (unsigned long long) process_row,
     68               provider_name);
     69   PREPARE (pg,
     70            "update_legitimization_process",
     71            "UPDATE legitimization_processes"
     72            " SET provider_user_id=$4"
     73            "    ,provider_legitimization_id=$5"
     74            "    ,redirect_url=$6"
     75            "    ,expiration_time=GREATEST(expiration_time,$7)"
     76            "    ,error_code=$8"
     77            "    ,error_message=$9"
     78            "    ,finished=$10"
     79            " WHERE"
     80            "      h_payto=$3"
     81            "  AND legitimization_process_serial_id=$1"
     82            "  AND provider_name=$2;");
     83   qs = GNUNET_PQ_eval_prepared_non_select (
     84     pg->conn,
     85     "update_legitimization_process",
     86     params);
     87   if (qs <= 0)
     88   {
     89     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     90                 "Failed to update legitimization process %llu: %d\n",
     91                 (unsigned long long) process_row,
     92                 qs);
     93     return qs;
     94   }
     95   if (GNUNET_TIME_absolute_is_future (expiration))
     96   {
     97     enum GNUNET_DB_QueryStatus qs2;
     98     struct TALER_EXCHANGEDB_KycCompletedEventP rep = {
     99       .header.size = htons (sizeof (rep)),
    100       .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED),
    101       .h_payto = *h_payto
    102     };
    103     uint32_t trigger_type = 1;
    104     struct GNUNET_PQ_QueryParam params2[] = {
    105       GNUNET_PQ_query_param_auto_from_type (h_payto),
    106       GNUNET_PQ_query_param_uint32 (&trigger_type),
    107       GNUNET_PQ_query_param_end
    108     };
    109 
    110     GNUNET_PQ_event_notify (pg->conn,
    111                             &rep.header,
    112                             NULL,
    113                             0);
    114     PREPARE (pg,
    115              "alert_kyc_status_change",
    116              "INSERT INTO kyc_alerts"
    117              " (h_payto"
    118              " ,trigger_type)"
    119              " VALUES"
    120              " ($1,$2);");
    121     qs2 = GNUNET_PQ_eval_prepared_non_select (
    122       pg->conn,
    123       "alert_kyc_status_change",
    124       params2);
    125     if (qs2 < 0)
    126       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
    127                   "Failed to store KYC alert: %d\n",
    128                   qs2);
    129   }
    130   return qs;
    131 }