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