LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_private-delete-orders-ID.c (source / functions) Hit Total Coverage
Test: GNU Taler merchant coverage report Lines: 0 40 0.0 %
Date: 2022-08-25 06:17:04 Functions: 0 1 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14