LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_private-delete-orders-ID.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 81.0 % 42 34
Test Date: 2025-10-31 14:20:14 Functions: 100.0 % 1 1

            Line data    Source code
       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            6 : TMH_private_delete_orders_ID (const struct TMH_RequestHandler *rh,
      37              :                               struct MHD_Connection *connection,
      38              :                               struct TMH_HandlerContext *hc)
      39              : {
      40            6 :   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            6 :   force_s = MHD_lookup_connection_value (connection,
      47              :                                          MHD_GET_ARGUMENT_KIND,
      48              :                                          "force");
      49            6 :   if (NULL == force_s)
      50            6 :     force_s = "no";
      51            6 :   force = (0 == strcasecmp (force_s,
      52              :                             "yes"));
      53              : 
      54            6 :   GNUNET_assert (NULL != mi);
      55            6 :   qs = TMH_db->delete_order (TMH_db->cls,
      56            6 :                              mi->settings.id,
      57            6 :                              hc->infix,
      58              :                              force);
      59            6 :   if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
      60            4 :     qs = TMH_db->delete_contract_terms (TMH_db->cls,
      61            4 :                                         mi->settings.id,
      62            4 :                                         hc->infix,
      63              :                                         TMH_legal_expiration);
      64            6 :   switch (qs)
      65              :   {
      66            0 :   case GNUNET_DB_STATUS_HARD_ERROR:
      67            0 :     return TALER_MHD_reply_with_error (connection,
      68              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      69              :                                        TALER_EC_GENERIC_DB_COMMIT_FAILED,
      70              :                                        NULL);
      71            0 :   case GNUNET_DB_STATUS_SOFT_ERROR:
      72            0 :     GNUNET_break (0);
      73            0 :     return TALER_MHD_reply_with_error (connection,
      74              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      75              :                                        TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
      76              :                                        NULL);
      77            4 :   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
      78              :     {
      79              :       struct TALER_MerchantPostDataHashP unused;
      80              :       uint64_t order_serial;
      81            4 :       bool paid = false;
      82            4 :       bool wired = false;
      83            4 :       bool matches = false;
      84              :       int16_t choice_index;
      85              : 
      86            4 :       qs = TMH_db->lookup_order (TMH_db->cls,
      87            4 :                                  mi->settings.id,
      88            4 :                                  hc->infix,
      89              :                                  NULL,
      90              :                                  &unused,
      91              :                                  NULL);
      92            4 :       if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
      93              :       {
      94            4 :         qs = TMH_db->lookup_contract_terms3 (TMH_db->cls,
      95            4 :                                              mi->settings.id,
      96            4 :                                              hc->infix,
      97              :                                              NULL,
      98              :                                              NULL,
      99              :                                              &order_serial,
     100              :                                              &paid,
     101              :                                              &wired,
     102              :                                              &matches,
     103              :                                              NULL,
     104              :                                              &choice_index);
     105              :       }
     106            4 :       if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
     107            2 :         return TALER_MHD_reply_with_error (connection,
     108              :                                            MHD_HTTP_NOT_FOUND,
     109              :                                            TALER_EC_MERCHANT_GENERIC_ORDER_UNKNOWN,
     110            2 :                                            hc->infix);
     111            2 :       if (paid)
     112            2 :         return TALER_MHD_reply_with_error (connection,
     113              :                                            MHD_HTTP_CONFLICT,
     114              :                                            TALER_EC_MERCHANT_PRIVATE_DELETE_ORDERS_ALREADY_PAID,
     115            2 :                                            hc->infix);
     116            0 :       return TALER_MHD_reply_with_error (connection,
     117              :                                          MHD_HTTP_CONFLICT,
     118              :                                          TALER_EC_MERCHANT_PRIVATE_DELETE_ORDERS_AWAITING_PAYMENT,
     119            0 :                                          hc->infix);
     120              :     }
     121            2 :   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
     122            2 :     return TALER_MHD_reply_static (connection,
     123              :                                    MHD_HTTP_NO_CONTENT,
     124              :                                    NULL,
     125              :                                    NULL,
     126              :                                    0);
     127              :   }
     128            0 :   GNUNET_assert (0);
     129              :   return MHD_NO;
     130              : }
     131              : 
     132              : 
     133              : /* end of taler-merchant-httpd_private-delete-orders-ID.c */
        

Generated by: LCOV version 2.0-1