merchant

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

testing_api_cmd_delete_unit.c (4316B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2025 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify
      6   it under the terms of the GNU General Public License as
      7   published by the Free Software Foundation; either version 3, or
      8   (at your option) any later version.
      9 
     10   TALER is distributed in the hope that it will be useful, but
     11   WITHOUT ANY WARRANTY; without even the implied warranty of
     12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13   GNU General Public License for more details.
     14 
     15   You should have received a copy of the GNU General Public
     16   License along with TALER; see the file COPYING.  If not, see
     17   <http://www.gnu.org/licenses/>
     18 */
     19 /**
     20  * @file testing_api_cmd_delete_unit.c
     21  * @brief command to test DELETE /private/units/$ID
     22  * @author Bohdan Potuzhnyi
     23  */
     24 #include "taler/platform.h"
     25 #include <taler/taler_testing_lib.h>
     26 #include "taler/taler_merchant_service.h"
     27 #include "taler/taler_merchant_testing_lib.h"
     28 #include <taler/taler-merchant/delete-private-units-UNIT.h>
     29 
     30 
     31 /**
     32  * State for a DELETE /private/units/$ID command.
     33  */
     34 struct DeleteUnitState
     35 {
     36   /**
     37    * In-flight request handle.
     38    */
     39   struct TALER_MERCHANT_DeletePrivateUnitHandle *udh;
     40 
     41   /**
     42    * Interpreter context.
     43    */
     44   struct TALER_TESTING_Interpreter *is;
     45 
     46   /**
     47    * Merchant backend base URL.
     48    */
     49   const char *merchant_url;
     50 
     51   /**
     52    * Unit identifier to delete.
     53    */
     54   const char *unit_id;
     55 
     56   /**
     57    * Expected HTTP status.
     58    */
     59   unsigned int http_status;
     60 };
     61 
     62 
     63 /**
     64  * Completion callback.
     65  */
     66 static void
     67 delete_unit_cb (void *cls,
     68                 const struct TALER_MERCHANT_DeletePrivateUnitResponse *dur)
     69 {
     70   struct DeleteUnitState *dus = cls;
     71 
     72   dus->udh = NULL;
     73   if (dus->http_status != dur->hr.http_status)
     74   {
     75     TALER_TESTING_unexpected_status_with_body (dus->is,
     76                                                dur->hr.http_status,
     77                                                dus->http_status,
     78                                                dur->hr.reply);
     79     return;
     80   }
     81   TALER_TESTING_interpreter_next (dus->is);
     82 }
     83 
     84 
     85 /**
     86  * Issue DELETE request.
     87  */
     88 static void
     89 delete_unit_run (void *cls,
     90                  const struct TALER_TESTING_Command *cmd,
     91                  struct TALER_TESTING_Interpreter *is)
     92 {
     93   struct DeleteUnitState *dus = cls;
     94 
     95   dus->is = is;
     96   dus->udh = TALER_MERCHANT_delete_private_unit_create (
     97     TALER_TESTING_interpreter_get_context (is),
     98     dus->merchant_url,
     99     dus->unit_id);
    100   {
    101     enum TALER_ErrorCode ec;
    102 
    103     ec = TALER_MERCHANT_delete_private_unit_start (dus->udh,
    104                                                    &delete_unit_cb,
    105                                                    dus);
    106     GNUNET_assert (TALER_EC_NONE == ec);
    107   }
    108 }
    109 
    110 
    111 /**
    112  * Provide traits.
    113  */
    114 static enum GNUNET_GenericReturnValue
    115 delete_unit_traits (void *cls,
    116                     const void **ret,
    117                     const char *trait,
    118                     unsigned int index)
    119 {
    120   struct DeleteUnitState *dus = cls;
    121   struct TALER_TESTING_Trait traits[] = {
    122     TALER_TESTING_make_trait_unit_id (dus->unit_id),
    123     TALER_TESTING_trait_end ()
    124   };
    125 
    126   return TALER_TESTING_get_trait (traits,
    127                                   ret,
    128                                   trait,
    129                                   index);
    130 }
    131 
    132 
    133 /**
    134  * Cleanup.
    135  */
    136 static void
    137 delete_unit_cleanup (void *cls,
    138                      const struct TALER_TESTING_Command *cmd)
    139 {
    140   struct DeleteUnitState *dus = cls;
    141 
    142   if (NULL != dus->udh)
    143   {
    144     TALER_MERCHANT_delete_private_unit_cancel (dus->udh);
    145     dus->udh = NULL;
    146   }
    147   GNUNET_free (dus);
    148 }
    149 
    150 
    151 struct TALER_TESTING_Command
    152 TALER_TESTING_cmd_merchant_delete_unit (const char *label,
    153                                         const char *merchant_url,
    154                                         const char *unit_id,
    155                                         unsigned int http_status)
    156 {
    157   struct DeleteUnitState *dus;
    158 
    159   dus = GNUNET_new (struct DeleteUnitState);
    160   dus->merchant_url = merchant_url;
    161   dus->unit_id = unit_id;
    162   dus->http_status = http_status;
    163 
    164   {
    165     struct TALER_TESTING_Command cmd = {
    166       .cls = dus,
    167       .label = label,
    168       .run = &delete_unit_run,
    169       .cleanup = &delete_unit_cleanup,
    170       .traits = &delete_unit_traits
    171     };
    172 
    173     return cmd;
    174   }
    175 }
    176 
    177 
    178 /* end of testing_api_cmd_delete_unit.c */