taler-merchant-httpd_post-orders-ORDER_ID-unclaim.c (4454B)
1 /* 2 This file is part of TALER 3 (C) 2026 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify 6 it under the terms of the GNU Affero General Public License as 7 published by the Free Software Foundation; either version 3, 8 or (at your option) any later version. 9 10 TALER is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public 16 License along with TALER; see the file COPYING. If not, 17 see <http://www.gnu.org/licenses/> 18 */ 19 20 /** 21 * @file src/backend/taler-merchant-httpd_post-orders-ORDER_ID-unclaim.c 22 * @brief headers for POST /orders/$ID/unclaim handler 23 * @author Christian Grothoff 24 */ 25 #include "platform.h" 26 #include <jansson.h> 27 #include <taler/taler_signatures.h> 28 #include <taler/taler_dbevents.h> 29 #include <taler/taler_json_lib.h> 30 #include "taler-merchant-httpd_get-private-orders.h" 31 #include "taler-merchant-httpd_post-orders-ORDER_ID-unclaim.h" 32 #include "merchant-database/insert_unclaim_signature.h" 33 #include "merchant-database/preflight.h" 34 35 36 enum MHD_Result 37 TMH_post_orders_ID_unclaim (const struct TMH_RequestHandler *rh, 38 struct MHD_Connection *connection, 39 struct TMH_HandlerContext *hc) 40 { 41 const char *order_id = hc->infix; 42 struct GNUNET_CRYPTO_EddsaPublicKey nonce; 43 struct GNUNET_CRYPTO_EddsaSignature nsig; 44 struct GNUNET_HashCode h_contract; 45 enum GNUNET_DB_QueryStatus qs; 46 47 { 48 struct GNUNET_JSON_Specification spec[] = { 49 GNUNET_JSON_spec_fixed_auto ("unclaim_sig", 50 &nsig), 51 GNUNET_JSON_spec_fixed_auto ("nonce", 52 &nonce), 53 GNUNET_JSON_spec_fixed_auto ("h_contract", 54 &h_contract), 55 GNUNET_JSON_spec_end () 56 }; 57 enum GNUNET_GenericReturnValue res; 58 59 res = TALER_MHD_parse_json_data (connection, 60 hc->request_body, 61 spec); 62 if (GNUNET_OK != res) 63 { 64 GNUNET_break_op (0); 65 return (GNUNET_NO == res) 66 ? MHD_YES 67 : MHD_NO; 68 } 69 } 70 71 if (GNUNET_OK != 72 TALER_wallet_order_unclaim_verify (&h_contract, 73 &nonce, 74 &nsig)) 75 { 76 GNUNET_break_op (0); 77 return TALER_MHD_reply_with_error ( 78 connection, 79 MHD_HTTP_FORBIDDEN, 80 TALER_EC_MERCHANT_POST_ORDERS_UNCLAIM_SIGNATURE_INVALID, 81 "unclaim_sig"); 82 } 83 TALER_MERCHANTDB_preflight (TMH_db); 84 qs = TALER_MERCHANTDB_insert_unclaim_signature (TMH_db, 85 hc->instance->settings.id, 86 &hc->instance->merchant_pub, 87 order_id, 88 &nonce, 89 &h_contract, 90 &nsig); 91 switch (qs) 92 { 93 case GNUNET_DB_STATUS_HARD_ERROR: 94 GNUNET_break (0); 95 return TALER_MHD_reply_with_error (connection, 96 MHD_HTTP_INTERNAL_SERVER_ERROR, 97 TALER_EC_GENERIC_DB_COMMIT_FAILED, 98 "insert_unclaim_signature"); 99 case GNUNET_DB_STATUS_SOFT_ERROR: 100 GNUNET_break (0); 101 return TALER_MHD_reply_with_error (connection, 102 MHD_HTTP_INTERNAL_SERVER_ERROR, 103 TALER_EC_GENERIC_DB_SOFT_FAILURE, 104 "insert_unclaim_signature"); 105 case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: 106 GNUNET_break (0); 107 return TALER_MHD_reply_with_error ( 108 connection, 109 MHD_HTTP_NOT_FOUND, 110 TALER_EC_MERCHANT_POST_ORDERS_ID_CLAIM_NOT_FOUND, 111 order_id); 112 case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: 113 break; /* Good! return signature (below) */ 114 } 115 116 return TALER_MHD_reply_static (connection, 117 MHD_HTTP_NO_CONTENT, 118 NULL, 119 NULL, 120 0); 121 } 122 123 124 /* end of taler-merchant-httpd_post-orders-ORDER_ID-unclaim.c */