merchant

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

testing_api_cmd_delete_webhook.c (4785B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2022 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_webhook.c
     21  * @brief command to test DELETE /webhooks/$ID
     22  * @author Priscilla HUANG
     23  */
     24 #include "taler/platform.h"
     25 #include <taler/taler_exchange_service.h>
     26 #include <taler/taler_testing_lib.h>
     27 #include "taler/taler_merchant_service.h"
     28 #include "taler/taler_merchant_testing_lib.h"
     29 #include <taler/taler-merchant/delete-private-webhooks-WEBHOOK_ID.h>
     30 
     31 
     32 /**
     33  * State of a "DELETE /webhooks/$ID" CMD.
     34  */
     35 struct DeleteWebhookState
     36 {
     37 
     38   /**
     39    * Handle for a "DELETE webhook" request.
     40    */
     41   struct TALER_MERCHANT_DeletePrivateWebhookHandle *wdh;
     42 
     43   /**
     44    * The interpreter state.
     45    */
     46   struct TALER_TESTING_Interpreter *is;
     47 
     48   /**
     49    * Base URL of the merchant serving the request.
     50    */
     51   const char *merchant_url;
     52 
     53   /**
     54    * ID of the webhook to run DELETE for.
     55    */
     56   const char *webhook_id;
     57 
     58   /**
     59    * Expected HTTP response code.
     60    */
     61   unsigned int http_status;
     62 
     63 };
     64 
     65 
     66 /**
     67  * Callback for a /delete/webhooks/$ID operation.
     68  *
     69  * @param cls closure for this function
     70  * @param hr response being processed
     71  */
     72 static void
     73 delete_webhook_cb (void *cls,
     74                    const struct TALER_MERCHANT_DeletePrivateWebhookResponse *dwr
     75                    )
     76 {
     77   struct DeleteWebhookState *dis = cls;
     78 
     79   dis->wdh = NULL;
     80   if (dis->http_status != dwr->hr.http_status)
     81   {
     82     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     83                 "Unexpected response code %u (%d) to command %s\n",
     84                 dwr->hr.http_status,
     85                 (int) dwr->hr.ec,
     86                 TALER_TESTING_interpreter_get_current_label (dis->is));
     87     TALER_TESTING_interpreter_fail (dis->is);
     88     return;
     89   }
     90   switch (dwr->hr.http_status)
     91   {
     92   case MHD_HTTP_NO_CONTENT:
     93     break;
     94   case MHD_HTTP_UNAUTHORIZED:
     95     break;
     96   case MHD_HTTP_NOT_FOUND:
     97     break;
     98   case MHD_HTTP_CONFLICT:
     99     break;
    100   default:
    101     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
    102                 "Unhandled HTTP status %u for DELETE webhook.\n",
    103                 dwr->hr.http_status);
    104   }
    105   TALER_TESTING_interpreter_next (dis->is);
    106 }
    107 
    108 
    109 /**
    110  * Run the "DELETE webhook" CMD.
    111  *
    112  *
    113  * @param cls closure.
    114  * @param cmd command being run now.
    115  * @param is interpreter state.
    116  */
    117 static void
    118 delete_webhook_run (void *cls,
    119                     const struct TALER_TESTING_Command *cmd,
    120                     struct TALER_TESTING_Interpreter *is)
    121 {
    122   struct DeleteWebhookState *dis = cls;
    123 
    124   dis->is = is;
    125   dis->wdh = TALER_MERCHANT_delete_private_webhook_create (
    126     TALER_TESTING_interpreter_get_context (is),
    127     dis->merchant_url,
    128     dis->webhook_id);
    129   {
    130     enum TALER_ErrorCode ec;
    131 
    132     ec = TALER_MERCHANT_delete_private_webhook_start (dis->wdh,
    133                                                       &delete_webhook_cb,
    134                                                       dis);
    135     GNUNET_assert (TALER_EC_NONE == ec);
    136   }
    137 }
    138 
    139 
    140 /**
    141  * Free the state of a "DELETE webhook" CMD, and possibly
    142  * cancel a pending operation thereof.
    143  *
    144  * @param cls closure.
    145  * @param cmd command being run.
    146  */
    147 static void
    148 delete_webhook_cleanup (void *cls,
    149                         const struct TALER_TESTING_Command *cmd)
    150 {
    151   struct DeleteWebhookState *dis = cls;
    152 
    153   if (NULL != dis->wdh)
    154   {
    155     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
    156                 "DELETE /webhooks/$ID operation did not complete\n");
    157     TALER_MERCHANT_delete_private_webhook_cancel (dis->wdh);
    158   }
    159   GNUNET_free (dis);
    160 }
    161 
    162 
    163 struct TALER_TESTING_Command
    164 TALER_TESTING_cmd_merchant_delete_webhook (const char *label,
    165                                            const char *merchant_url,
    166                                            const char *webhook_id,
    167                                            unsigned int http_status)
    168 {
    169   struct DeleteWebhookState *dis;
    170 
    171   dis = GNUNET_new (struct DeleteWebhookState);
    172   dis->merchant_url = merchant_url;
    173   dis->webhook_id = webhook_id;
    174   dis->http_status = http_status;
    175   {
    176     struct TALER_TESTING_Command cmd = {
    177       .cls = dis,
    178       .label = label,
    179       .run = &delete_webhook_run,
    180       .cleanup = &delete_webhook_cleanup
    181     };
    182 
    183     return cmd;
    184   }
    185 }
    186 
    187 
    188 /* end of testing_api_cmd_delete_webhook.c */