/*
  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-orders-ORDER_ID-paid.h
 * @brief C interface for the POST /orders/$ORDER_ID/paid endpoint
 * @author Christian Grothoff
 */
#ifndef _TALER_MERCHANT__POST_ORDERS_ORDER_ID_PAID_H
#define _TALER_MERCHANT__POST_ORDERS_ORDER_ID_PAID_H

#include <taler/merchant/common.h>


/**
 * Possible options for the POST /orders/$ORDER_ID/paid request.
 */
enum TALER_MERCHANT_PostOrdersPaidOption
{
  /**
   * End of list of options.
   */
  TALER_MERCHANT_POST_ORDERS_PAID_OPTION_END = 0,

};


/**
 * Value for an option for the POST /orders/$ORDER_ID/paid request.
 */
struct TALER_MERCHANT_PostOrdersPaidOptionValue
{

  /**
   * Type of the option being set.
   */
  enum TALER_MERCHANT_PostOrdersPaidOption option;

  /**
   * Specific option value.
   */
  union
  {

  } details;

};


/**
 * Handle for a POST /orders/$ORDER_ID/paid request.
 */
struct TALER_MERCHANT_PostOrdersPaidHandle;


/**
 * Response details for a POST /orders/$ORDER_ID/paid request.
 */
struct TALER_MERCHANT_PostOrdersPaidResponse
{

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

  /**
   * Response details depending on HTTP status.
   */
  union
  {

    /**
     * Details if HTTP status is #MHD_HTTP_OK.
     */
    struct
    {

      /**
       * POS confirmation string, or NULL if not available.
       */
      const char *pos_confirmation;

      /**
       * True if the order has been refunded.
       */
      bool refunded;

    } ok;

  } details;

};


/**
 * Terminate the list of the options.
 *
 * @return the terminating object of struct TALER_MERCHANT_PostOrdersPaidOptionValue
 */
#define TALER_MERCHANT_post_orders_paid_option_end_()                \
        (const struct TALER_MERCHANT_PostOrdersPaidOptionValue)      \
        {                                                             \
          .option = TALER_MERCHANT_POST_ORDERS_PAID_OPTION_END       \
        }


/**
 * Set the requested options for the operation.
 *
 * @param poph the request to set the options for
 * @param num_options length of the @a options array
 * @param options an array of options
 * @return #GNUNET_OK on success,
 *         #GNUNET_NO on failure,
 *         #GNUNET_SYSERR on internal error
 */
enum GNUNET_GenericReturnValue
TALER_MERCHANT_post_orders_paid_set_options_ (
  struct TALER_MERCHANT_PostOrdersPaidHandle *poph,
  unsigned int num_options,
  const struct TALER_MERCHANT_PostOrdersPaidOptionValue *options);


/**
 * Set the requested options for the operation.
 *
 * @param poph the request to set the options for
 * @param ... the list of the options
 * @return #GNUNET_OK on success,
 *         #GNUNET_NO on failure,
 *         #GNUNET_SYSERR on internal error
 */
#define TALER_MERCHANT_post_orders_paid_set_options(poph,...)                \
        TALER_MERCHANT_post_orders_paid_set_options_ (                       \
          poph,                                                              \
          TALER_MERCHANT_COMMON_OPTIONS_ARRAY_MAX_SIZE,                     \
          ((const struct TALER_MERCHANT_PostOrdersPaidOptionValue[])        \
           {__VA_ARGS__, TALER_MERCHANT_post_orders_paid_option_end_ () }  \
          ))


/**
 * Set up POST /orders/$ORDER_ID/paid 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
 * @param session_id session identifier
 * @param h_contract_terms hash of the contract terms
 * @param merchant_sig merchant signature over the session data
 * @return handle to operation
 */
struct TALER_MERCHANT_PostOrdersPaidHandle *
TALER_MERCHANT_post_orders_paid_create (
  struct GNUNET_CURL_Context *ctx,
  const char *url,
  const char *order_id,
  const char *session_id,
  const struct TALER_PrivateContractHashP *h_contract_terms,
  const struct TALER_MerchantSignatureP *merchant_sig);


#ifndef TALER_MERCHANT_POST_ORDERS_PAID_RESULT_CLOSURE
/**
 * Type of the closure used by
 * the #TALER_MERCHANT_PostOrdersPaidCallback.
 */
#define TALER_MERCHANT_POST_ORDERS_PAID_RESULT_CLOSURE void
#endif /* TALER_MERCHANT_POST_ORDERS_PAID_RESULT_CLOSURE */

/**
 * Callback for a POST /orders/$ORDER_ID/paid request.
 *
 * @param cls closure
 * @param opr response details
 */
typedef void
(*TALER_MERCHANT_PostOrdersPaidCallback)(
  TALER_MERCHANT_POST_ORDERS_PAID_RESULT_CLOSURE *cls,
  const struct TALER_MERCHANT_PostOrdersPaidResponse *opr);


/**
 * Start POST /orders/$ORDER_ID/paid operation.
 *
 * @param[in,out] poph 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_orders_paid_start (
  struct TALER_MERCHANT_PostOrdersPaidHandle *poph,
  TALER_MERCHANT_PostOrdersPaidCallback cb,
  TALER_MERCHANT_POST_ORDERS_PAID_RESULT_CLOSURE *cb_cls);


/**
 * Cancel POST /orders/$ORDER_ID/paid operation.  This function must not be
 * called by clients after the TALER_MERCHANT_PostOrdersPaidCallback has
 * been invoked (as in those cases it'll be called internally by the
 * implementation already).
 *
 * @param[in] poph operation to cancel
 */
void
TALER_MERCHANT_post_orders_paid_cancel (
  struct TALER_MERCHANT_PostOrdersPaidHandle *poph);


#endif /* _TALER_MERCHANT__POST_ORDERS_ORDER_ID_PAID_H */
