taler-merchant-httpd_private-delete-orders-ID.c (5310B)
1 /* 2 This file is part of TALER 3 (C) 2020 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 taler-merchant-httpd_private-delete-orders-ID.c 18 * @brief implement DELETE /orders/$ID 19 * @author Christian Grothoff 20 */ 21 #include "platform.h" 22 #include "taler-merchant-httpd_private-delete-orders-ID.h" 23 #include <stdint.h> 24 #include <taler/taler_json_lib.h> 25 26 27 /** 28 * Handle a DELETE "/orders/$ID" request. 29 * 30 * @param rh context of the handler 31 * @param connection the MHD connection to handle 32 * @param[in,out] hc context with further information about the request 33 * @return MHD result code 34 */ 35 MHD_RESULT 36 TMH_private_delete_orders_ID (const struct TMH_RequestHandler *rh, 37 struct MHD_Connection *connection, 38 struct TMH_HandlerContext *hc) 39 { 40 struct TMH_MerchantInstance *mi = hc->instance; 41 enum GNUNET_DB_QueryStatus qs; 42 const char *force_s; 43 bool force; 44 45 (void) rh; 46 force_s = MHD_lookup_connection_value (connection, 47 MHD_GET_ARGUMENT_KIND, 48 "force"); 49 if (NULL == force_s) 50 force_s = "no"; 51 force = (0 == strcasecmp (force_s, 52 "yes")); 53 54 GNUNET_assert (NULL != mi); 55 qs = TMH_db->delete_order (TMH_db->cls, 56 mi->settings.id, 57 hc->infix, 58 force); 59 if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) 60 qs = TMH_db->delete_contract_terms (TMH_db->cls, 61 mi->settings.id, 62 hc->infix, 63 TMH_legal_expiration); 64 switch (qs) 65 { 66 case GNUNET_DB_STATUS_HARD_ERROR: 67 return TALER_MHD_reply_with_error (connection, 68 MHD_HTTP_INTERNAL_SERVER_ERROR, 69 TALER_EC_GENERIC_DB_COMMIT_FAILED, 70 NULL); 71 case GNUNET_DB_STATUS_SOFT_ERROR: 72 GNUNET_break (0); 73 return TALER_MHD_reply_with_error (connection, 74 MHD_HTTP_INTERNAL_SERVER_ERROR, 75 TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE, 76 NULL); 77 case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: 78 { 79 struct TALER_MerchantPostDataHashP unused; 80 uint64_t order_serial; 81 bool paid = false; 82 bool wired = false; 83 bool matches = false; 84 int16_t choice_index; 85 86 qs = TMH_db->lookup_order (TMH_db->cls, 87 mi->settings.id, 88 hc->infix, 89 NULL, 90 &unused, 91 NULL); 92 if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) 93 { 94 qs = TMH_db->lookup_contract_terms3 (TMH_db->cls, 95 mi->settings.id, 96 hc->infix, 97 NULL, 98 NULL, 99 &order_serial, 100 &paid, 101 &wired, 102 &matches, 103 NULL, 104 &choice_index); 105 } 106 if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) 107 return TALER_MHD_reply_with_error (connection, 108 MHD_HTTP_NOT_FOUND, 109 TALER_EC_MERCHANT_GENERIC_ORDER_UNKNOWN, 110 hc->infix); 111 if (paid) 112 return TALER_MHD_reply_with_error (connection, 113 MHD_HTTP_CONFLICT, 114 TALER_EC_MERCHANT_PRIVATE_DELETE_ORDERS_ALREADY_PAID, 115 hc->infix); 116 return TALER_MHD_reply_with_error (connection, 117 MHD_HTTP_CONFLICT, 118 TALER_EC_MERCHANT_PRIVATE_DELETE_ORDERS_AWAITING_PAYMENT, 119 hc->infix); 120 } 121 case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: 122 return TALER_MHD_reply_static (connection, 123 MHD_HTTP_NO_CONTENT, 124 NULL, 125 NULL, 126 0); 127 } 128 GNUNET_assert (0); 129 return MHD_NO; 130 } 131 132 133 /* end of taler-merchant-httpd_private-delete-orders-ID.c */