merchant

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

taler-merchant-httpd_delete-private-transfers-TID.c (3733B)


      1 /*
      2   This file is part of TALER
      3   (C) 2021 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-transfers-TID.c
     18  * @brief implement DELETE /transfers/$ID
     19  * @author Christian Grothoff
     20  */
     21 #include "platform.h"
     22 #include "taler-merchant-httpd_delete-private-transfers-TID.h"
     23 #include <taler/taler_json_lib.h>
     24 #include "merchant-database/check_transfer_exists.h"
     25 #include "merchant-database/delete_transfer.h"
     26 
     27 
     28 enum MHD_Result
     29 TMH_private_delete_transfers_ID (const struct TMH_RequestHandler *rh,
     30                                  struct MHD_Connection *connection,
     31                                  struct TMH_HandlerContext *hc)
     32 {
     33   struct TMH_MerchantInstance *mi = hc->instance;
     34   enum GNUNET_DB_QueryStatus qs;
     35   unsigned long long serial;
     36   char dummy;
     37 
     38   (void) rh;
     39   GNUNET_assert (NULL != mi);
     40   if (1 !=
     41       sscanf (hc->infix,
     42               "%llu%c",
     43               &serial,
     44               &dummy))
     45   {
     46     return TALER_MHD_reply_with_error (connection,
     47                                        MHD_HTTP_BAD_REQUEST,
     48                                        TALER_EC_GENERIC_PARAMETER_MALFORMED,
     49                                        hc->infix);
     50   }
     51   qs = TALER_MERCHANTDB_delete_transfer (TMH_db,
     52                                          mi->settings.id,
     53                                          serial);
     54   switch (qs)
     55   {
     56   case GNUNET_DB_STATUS_HARD_ERROR:
     57     return TALER_MHD_reply_with_error (connection,
     58                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     59                                        TALER_EC_GENERIC_DB_COMMIT_FAILED,
     60                                        NULL);
     61   case GNUNET_DB_STATUS_SOFT_ERROR:
     62     GNUNET_break (0);
     63     return TALER_MHD_reply_with_error (connection,
     64                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     65                                        TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
     66                                        NULL);
     67   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
     68     qs = TALER_MERCHANTDB_check_transfer_exists (TMH_db,
     69                                                  mi->settings.id,
     70                                                  serial);
     71     if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
     72       return TALER_MHD_reply_with_error (connection,
     73                                          MHD_HTTP_NOT_FOUND,
     74                                          TALER_EC_MERCHANT_GENERIC_TRANSFER_UNKNOWN,
     75                                          hc->infix);
     76     return TALER_MHD_reply_with_error (connection,
     77                                        MHD_HTTP_CONFLICT,
     78                                        TALER_EC_MERCHANT_PRIVATE_DELETE_TRANSFERS_ALREADY_CONFIRMED,
     79                                        hc->infix);
     80   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
     81     return TALER_MHD_reply_static (connection,
     82                                    MHD_HTTP_NO_CONTENT,
     83                                    NULL,
     84                                    NULL,
     85                                    0);
     86   }
     87   GNUNET_assert (0);
     88   return MHD_NO;
     89 }
     90 
     91 
     92 /* end of taler-merchant-httpd_delete-private-transfers-TID.c */