/*
  This file is part of TALER
  Copyright (C) 2014-2026 Taler Systems SA

  TALER is free software; you can redistribute it and/or modify it under the
  terms of the GNU Lesser General Public License as published by the Free Software
  Foundation; either version 2.1, or (at your option) any later version.

  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public License along with
  TALER; see the file COPYING.LGPL.  If not, see
  <http://www.gnu.org/licenses/>
*/
/**
 * @file include/taler/taler-merchant/post-private-orders-ORDER_ID-refund.h
 * @brief C interface for POST /private/orders/$ORDER_ID/refund of the merchant backend
 * @author Christian Grothoff
 */
#ifndef _TALER_MERCHANT__POST_PRIVATE_ORDERS_ORDER_ID_REFUND_H
#define _TALER_MERCHANT__POST_PRIVATE_ORDERS_ORDER_ID_REFUND_H

#include <taler/taler-merchant/common.h>


/**
 * Handle for a POST /private/orders/$ORDER_ID/refund request.
 */
struct TALER_MERCHANT_OrderRefundHandle;


/**
 * Response details for a POST /private/orders/$ORDER_ID/refund request.
 */
struct TALER_MERCHANT_RefundResponse
{

  /**
   * HTTP response details.
   */
  struct TALER_MERCHANT_HttpResponse hr;

  /**
   * Details depending on the HTTP status code.
   */
  union
  {

    /**
     * Details on #MHD_HTTP_OK.
     */
    struct
    {

      /**
       * Taler refund URI for the wallet.
       */
      const char *taler_refund_uri;

      /**
       * Hash of the contract terms for this order.
       */
      struct TALER_PrivateContractHashP h_contract;

    } ok;

  } details;

};


/**
 * Callback for a POST /private/orders/$ORDER_ID/refund request.
 *
 * @param cls closure
 * @param rr response details
 */
typedef void
(*TALER_MERCHANT_RefundCallback)(
  void *cls,
  const struct TALER_MERCHANT_RefundResponse *rr);


/**
 * Issue a POST /private/orders/$ORDER_ID/refund request to grant a refund.
 *
 * @param ctx CURL context to use
 * @param backend_url base URL of the merchant backend
 * @param order_id identifier of the order to refund
 * @param refund amount to refund
 * @param reason human-readable reason for the refund
 * @param cb callback to invoke with the result
 * @param cb_cls closure for @a cb
 * @return handle for the request, NULL on hard error
 */
struct TALER_MERCHANT_OrderRefundHandle *
TALER_MERCHANT_post_order_refund (
  struct GNUNET_CURL_Context *ctx,
  const char *backend_url,
  const char *order_id,
  const struct TALER_Amount *refund,
  const char *reason,
  TALER_MERCHANT_RefundCallback cb,
  void *cb_cls);


/**
 * Cancel a POST /private/orders/$ORDER_ID/refund request.
 *
 * @param[in] orh handle to cancel
 */
void
TALER_MERCHANT_post_order_refund_cancel (
  struct TALER_MERCHANT_OrderRefundHandle *orh);


#endif
