merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

taler-merchant-httpd_post-orders-ORDER_ID-unclaim.c (4267B)


      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 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 "taler/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 
     33 
     34 MHD_RESULT
     35 TMH_post_orders_ID_unclaim (const struct TMH_RequestHandler *rh,
     36                             struct MHD_Connection *connection,
     37                             struct TMH_HandlerContext *hc)
     38 {
     39   const char *order_id = hc->infix;
     40   struct GNUNET_CRYPTO_EddsaPublicKey nonce;
     41   struct GNUNET_CRYPTO_EddsaSignature nsig;
     42   struct GNUNET_HashCode h_contract;
     43   enum GNUNET_DB_QueryStatus qs;
     44 
     45   {
     46     struct GNUNET_JSON_Specification spec[] = {
     47       GNUNET_JSON_spec_fixed_auto ("unclaim_sig",
     48                                    &nsig),
     49       GNUNET_JSON_spec_fixed_auto ("nonce",
     50                                    &nonce),
     51       GNUNET_JSON_spec_fixed_auto ("h_contract",
     52                                    &h_contract),
     53       GNUNET_JSON_spec_end ()
     54     };
     55     enum GNUNET_GenericReturnValue res;
     56 
     57     res = TALER_MHD_parse_json_data (connection,
     58                                      hc->request_body,
     59                                      spec);
     60     if (GNUNET_OK != res)
     61     {
     62       GNUNET_break_op (0);
     63       return (GNUNET_NO == res)
     64              ? MHD_YES
     65              : MHD_NO;
     66     }
     67   }
     68 
     69   if (GNUNET_OK !=
     70       TALER_wallet_order_unclaim_verify (&h_contract,
     71                                          &nonce,
     72                                          &nsig))
     73   {
     74     GNUNET_break_op (0);
     75     return TALER_MHD_reply_with_error (
     76       connection,
     77       MHD_HTTP_BAD_REQUEST,
     78       TALER_EC_GENERIC_PARAMETER_MALFORMED,
     79       "unclaim_sig");
     80   }
     81   TMH_db->preflight (TMH_db->cls);
     82   qs = TMH_db->insert_unclaim_signature (TMH_db->cls,
     83                                          hc->instance->settings.id,
     84                                          &hc->instance->merchant_pub,
     85                                          order_id,
     86                                          &nonce,
     87                                          &h_contract,
     88                                          &nsig);
     89   switch (qs)
     90   {
     91   case GNUNET_DB_STATUS_HARD_ERROR:
     92     GNUNET_break (0);
     93     return TALER_MHD_reply_with_error (connection,
     94                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     95                                        TALER_EC_GENERIC_DB_COMMIT_FAILED,
     96                                        "insert_unclaim_signature");
     97   case GNUNET_DB_STATUS_SOFT_ERROR:
     98     GNUNET_break (0);
     99     return TALER_MHD_reply_with_error (connection,
    100                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
    101                                        TALER_EC_GENERIC_DB_SOFT_FAILURE,
    102                                        "insert_unclaim_signature");
    103   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
    104     GNUNET_break (0);
    105     return TALER_MHD_reply_with_error (
    106       connection,
    107       MHD_HTTP_NOT_FOUND,
    108       TALER_EC_MERCHANT_POST_ORDERS_ID_CLAIM_NOT_FOUND,
    109       order_id);
    110   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
    111     break; /* Good! return signature (below) */
    112   }
    113 
    114   return TALER_MHD_reply_static (connection,
    115                                  MHD_HTTP_NO_CONTENT,
    116                                  NULL,
    117                                  NULL,
    118                                  0);
    119 }
    120 
    121 
    122 /* end of taler-merchant-httpd_post-orders-ORDER_ID-unclaim.c */