taler-merchant-httpd_delete-private-accounts-H_WIRE.c (4302B)
1 /* 2 This file is part of TALER 3 (C) 2023 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU Affero 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/backend/taler-merchant-httpd_delete-private-accounts-H_WIRE.c 18 * @brief implement DELETE /account/$H_WIRE 19 * @author Christian Grothoff 20 */ 21 #include "platform.h" 22 #include "taler-merchant-httpd_delete-private-accounts-H_WIRE.h" 23 #include <taler/taler_json_lib.h> 24 #include <taler/taler_dbevents.h> 25 #include "taler-merchant-httpd_mfa.h" 26 #include "merchant-database/inactivate_account.h" 27 #include "merchant-database/event_notify.h" 28 29 30 enum MHD_Result 31 TMH_private_delete_account_ID (const struct TMH_RequestHandler *rh, 32 struct MHD_Connection *connection, 33 struct TMH_HandlerContext *hc) 34 { 35 struct TMH_MerchantInstance *mi = hc->instance; 36 struct TALER_MerchantWireHashP h_wire; 37 enum GNUNET_DB_QueryStatus qs; 38 39 (void) rh; 40 if (GNUNET_OK != 41 GNUNET_STRINGS_string_to_data (hc->infix, 42 strlen (hc->infix), 43 &h_wire, 44 sizeof (h_wire))) 45 { 46 GNUNET_break_op (0); 47 return TALER_MHD_reply_with_error (connection, 48 MHD_HTTP_BAD_REQUEST, 49 TALER_EC_GENERIC_PARAMETER_MALFORMED, 50 "h_wire"); 51 } 52 GNUNET_assert (NULL != mi); 53 { 54 /* MFA needed: deleting a bank account changes the 55 account configuration of the instance. */ 56 enum GNUNET_GenericReturnValue ret; 57 58 ret = TMH_mfa_check_simple ( 59 hc, 60 TALER_MERCHANT_MFA_CO_ACCOUNT_CONFIGURATION, 61 mi); 62 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 63 "Account deletion MFA check returned %d\n", 64 (int) ret); 65 if (GNUNET_OK != ret) 66 { 67 return (GNUNET_NO == ret) 68 ? MHD_YES 69 : MHD_NO; 70 } 71 } 72 qs = TALER_MERCHANTDB_inactivate_account (TMH_db, 73 mi->settings.id, 74 &h_wire); 75 switch (qs) 76 { 77 case GNUNET_DB_STATUS_HARD_ERROR: 78 return TALER_MHD_reply_with_error (connection, 79 MHD_HTTP_INTERNAL_SERVER_ERROR, 80 TALER_EC_GENERIC_DB_STORE_FAILED, 81 "inactivate_account"); 82 case GNUNET_DB_STATUS_SOFT_ERROR: 83 GNUNET_break (0); 84 return TALER_MHD_reply_with_error (connection, 85 MHD_HTTP_INTERNAL_SERVER_ERROR, 86 TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE, 87 NULL); 88 case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: 89 return TALER_MHD_reply_with_error (connection, 90 MHD_HTTP_NOT_FOUND, 91 TALER_EC_MERCHANT_PRIVATE_ACCOUNT_DELETE_UNKNOWN_ACCOUNT, 92 "account unknown"); 93 case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: 94 break; 95 } 96 { 97 struct GNUNET_DB_EventHeaderP es = { 98 .size = htons (sizeof (es)), 99 .type = htons (TALER_DBEVENT_MERCHANT_ACCOUNTS_CHANGED) 100 }; 101 102 TALER_MERCHANTDB_event_notify (TMH_db, 103 &es, 104 NULL, 105 0); 106 } 107 TMH_reload_instances (mi->settings.id); 108 return TALER_MHD_reply_static (connection, 109 MHD_HTTP_NO_CONTENT, 110 NULL, 111 NULL, 112 0); 113 } 114 115 116 /* end of taler-merchant-httpd_delete-private-accounts-H_WIRE.c */