/*
  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-orders-ORDER_ID-abort.h
 * @brief C interface for POST /orders/$ORDER_ID/abort of the merchant backend
 * @author Christian Grothoff
 */
#ifndef _TALER_MERCHANT__POST_ORDERS_ORDER_ID_ABORT_H
#define _TALER_MERCHANT__POST_ORDERS_ORDER_ID_ABORT_H

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


/**
 * Handle for a POST /orders/$ORDER_ID/abort request.
 */
struct TALER_MERCHANT_OrderAbortHandle;


/**
 * Coin sent with an abort request.
 */
struct TALER_MERCHANT_AbortCoin
{

  /**
   * Public key of the coin.
   */
  struct TALER_CoinSpendPublicKeyP coin_pub;

  /**
   * Amount contributed by this coin including deposit fee.
   */
  struct TALER_Amount amount_with_fee;

  /**
   * Hash of the coin's denomination public key.
   */
  struct TALER_DenominationHashP h_denom;

  /**
   * Base URL of the exchange this coin was issued by.
   */
  const char *exchange_url;

};


/**
 * Result for one coin in an abort response.
 */
struct TALER_MERCHANT_AbortedCoin
{

  /**
   * Exchange public key used for the refund.
   */
  struct TALER_ExchangePublicKeyP exchange_pub;

  /**
   * Exchange signature over the refund.
   */
  struct TALER_ExchangeSignatureP exchange_sig;

};


/**
 * Response details for a POST /orders/$ORDER_ID/abort request.
 */
struct TALER_MERCHANT_AbortResponse
{

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

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

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

      /**
       * Public key of the merchant.
       */
      const struct TALER_MerchantPublicKeyP *merchant_pub;

      /**
       * Number of aborted coins in @a aborts.
       */
      unsigned int num_aborts;

      /**
       * Array of per-coin abort results.
       */
      const struct TALER_MERCHANT_AbortedCoin *aborts;

    } ok;

  } details;

};


/**
 * Callback for a POST /orders/$ORDER_ID/abort request.
 *
 * @param cls closure
 * @param ar response details
 */
typedef void
(*TALER_MERCHANT_AbortCallback)(
  void *cls,
  const struct TALER_MERCHANT_AbortResponse *ar);


/**
 * Issue a POST /orders/$ORDER_ID/abort request to abort a payment
 * and obtain refund signatures for the coins used.
 *
 * @param ctx CURL context to use
 * @param merchant_url base URL of the merchant backend
 * @param order_id identifier of the order to abort
 * @param merchant_pub public key of the merchant instance
 * @param h_contract hash of the contract terms
 * @param num_coins number of coins in @a coins
 * @param coins array of coins that were used for payment
 * @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_OrderAbortHandle *
TALER_MERCHANT_order_abort (
  struct GNUNET_CURL_Context *ctx,
  const char *merchant_url,
  const char *order_id,
  const struct TALER_MerchantPublicKeyP *merchant_pub,
  const struct TALER_PrivateContractHashP *h_contract,
  unsigned int num_coins,
  const struct TALER_MERCHANT_AbortCoin coins[static num_coins],
  TALER_MERCHANT_AbortCallback cb,
  void *cb_cls);


/**
 * Cancel a POST /orders/$ORDER_ID/abort request.
 *
 * @param[in] oah handle to cancel
 */
void
TALER_MERCHANT_order_abort_cancel (
  struct TALER_MERCHANT_OrderAbortHandle *oah);


#endif
