merchant

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

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


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