merchant

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

taler-merchant-httpd_delete-private-orders-ORDER_ID.c (5600B)


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