/*
  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 src/include/taler/merchant/post-private-orders-ORDER_ID-refund.h
 * @brief C interface for the POST /private/orders/$ORDER_ID/refund endpoint
 * @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/merchant/common.h>


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


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

  /**
   * 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;

};


/**
 * Set up POST /private/orders/$ORDER_ID/refund operation.
 * Note that you must explicitly start the operation after
 * possibly setting options.
 *
 * @param ctx the context
 * @param 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
 * @return handle to operation
 */
struct TALER_MERCHANT_PostPrivateOrdersRefundHandle *
TALER_MERCHANT_post_private_orders_refund_create (
  struct GNUNET_CURL_Context *ctx,
  const char *url,
  const char *order_id,
  const struct TALER_Amount *refund,
  const char *reason);


#ifndef TALER_MERCHANT_POST_PRIVATE_ORDERS_REFUND_RESULT_CLOSURE
/**
 * Type of the closure used by
 * the #TALER_MERCHANT_PostPrivateOrdersRefundCallback.
 */
#define TALER_MERCHANT_POST_PRIVATE_ORDERS_REFUND_RESULT_CLOSURE void
#endif /* TALER_MERCHANT_POST_PRIVATE_ORDERS_REFUND_RESULT_CLOSURE */

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


/**
 * Start POST /private/orders/$ORDER_ID/refund operation.
 *
 * @param[in,out] porh operation to start
 * @param cb function to call with the merchant's result
 * @param cb_cls closure for @a cb
 * @return status code, #TALER_EC_NONE on success
 */
enum TALER_ErrorCode
TALER_MERCHANT_post_private_orders_refund_start (
  struct TALER_MERCHANT_PostPrivateOrdersRefundHandle *porh,
  TALER_MERCHANT_PostPrivateOrdersRefundCallback cb,
  TALER_MERCHANT_POST_PRIVATE_ORDERS_REFUND_RESULT_CLOSURE *cb_cls);


/**
 * Cancel POST /private/orders/$ORDER_ID/refund operation.  This function
 * must not be called by clients after the
 * TALER_MERCHANT_PostPrivateOrdersRefundCallback has been invoked (as in
 * those cases it'll be called internally by the implementation already).
 *
 * @param[in] porh operation to cancel
 */
void
TALER_MERCHANT_post_private_orders_refund_cancel (
  struct TALER_MERCHANT_PostPrivateOrdersRefundHandle *porh);


#endif /* _TALER_MERCHANT__POST_PRIVATE_ORDERS_ORDER_ID_REFUND_H */
