merchant

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

testing_api_cmd_delete_unit.c (4042B)


      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 "platform.h"
     25 #include <taler/taler_testing_lib.h>
     26 #include "taler_merchant_service.h"
     27 #include "taler_merchant_testing_lib.h"
     28 
     29 
     30 /**
     31  * State for a DELETE /private/units/$ID command.
     32  */
     33 struct DeleteUnitState
     34 {
     35   /**
     36    * In-flight request handle.
     37    */
     38   struct TALER_MERCHANT_UnitDeleteHandle *udh;
     39 
     40   /**
     41    * Interpreter context.
     42    */
     43   struct TALER_TESTING_Interpreter *is;
     44 
     45   /**
     46    * Merchant backend base URL.
     47    */
     48   const char *merchant_url;
     49 
     50   /**
     51    * Unit identifier to delete.
     52    */
     53   const char *unit_id;
     54 
     55   /**
     56    * Expected HTTP status.
     57    */
     58   unsigned int http_status;
     59 };
     60 
     61 
     62 /**
     63  * Completion callback.
     64  */
     65 static void
     66 delete_unit_cb (void *cls,
     67                 const struct TALER_MERCHANT_HttpResponse *hr)
     68 {
     69   struct DeleteUnitState *dus = cls;
     70 
     71   dus->udh = NULL;
     72   if (dus->http_status != hr->http_status)
     73   {
     74     TALER_TESTING_unexpected_status_with_body (dus->is,
     75                                                hr->http_status,
     76                                                dus->http_status,
     77                                                hr->reply);
     78     return;
     79   }
     80   TALER_TESTING_interpreter_next (dus->is);
     81 }
     82 
     83 
     84 /**
     85  * Issue DELETE request.
     86  */
     87 static void
     88 delete_unit_run (void *cls,
     89                  const struct TALER_TESTING_Command *cmd,
     90                  struct TALER_TESTING_Interpreter *is)
     91 {
     92   struct DeleteUnitState *dus = cls;
     93 
     94   dus->is = is;
     95   dus->udh = TALER_MERCHANT_unit_delete (
     96     TALER_TESTING_interpreter_get_context (is),
     97     dus->merchant_url,
     98     dus->unit_id,
     99     &delete_unit_cb,
    100     dus);
    101   if (NULL == dus->udh)
    102   {
    103     GNUNET_break (0);
    104     TALER_TESTING_interpreter_fail (is);
    105   }
    106 }
    107 
    108 
    109 /**
    110  * Provide traits.
    111  */
    112 static enum GNUNET_GenericReturnValue
    113 delete_unit_traits (void *cls,
    114                     const void **ret,
    115                     const char *trait,
    116                     unsigned int index)
    117 {
    118   struct DeleteUnitState *dus = cls;
    119   struct TALER_TESTING_Trait traits[] = {
    120     TALER_TESTING_make_trait_unit_id (dus->unit_id),
    121     TALER_TESTING_trait_end ()
    122   };
    123 
    124   return TALER_TESTING_get_trait (traits,
    125                                   ret,
    126                                   trait,
    127                                   index);
    128 }
    129 
    130 
    131 /**
    132  * Cleanup.
    133  */
    134 static void
    135 delete_unit_cleanup (void *cls,
    136                      const struct TALER_TESTING_Command *cmd)
    137 {
    138   struct DeleteUnitState *dus = cls;
    139 
    140   if (NULL != dus->udh)
    141   {
    142     TALER_MERCHANT_unit_delete_cancel (dus->udh);
    143     dus->udh = NULL;
    144   }
    145   GNUNET_free (dus);
    146 }
    147 
    148 
    149 struct TALER_TESTING_Command
    150 TALER_TESTING_cmd_merchant_delete_unit (const char *label,
    151                                         const char *merchant_url,
    152                                         const char *unit_id,
    153                                         unsigned int http_status)
    154 {
    155   struct DeleteUnitState *dus;
    156 
    157   dus = GNUNET_new (struct DeleteUnitState);
    158   dus->merchant_url = merchant_url;
    159   dus->unit_id = unit_id;
    160   dus->http_status = http_status;
    161 
    162   {
    163     struct TALER_TESTING_Command cmd = {
    164       .cls = dus,
    165       .label = label,
    166       .run = &delete_unit_run,
    167       .cleanup = &delete_unit_cleanup,
    168       .traits = &delete_unit_traits
    169     };
    170 
    171     return cmd;
    172   }
    173 }
    174 
    175 
    176 /* end of testing_api_cmd_delete_unit.c */