/*
  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/get-orders-ORDER_ID.h
 * @brief C interface for GET /orders/$ORDER_ID (wallet-facing) of the merchant backend
 * @author Christian Grothoff
 */
#ifndef _TALER_MERCHANT__GET_ORDERS_ORDER_ID_H
#define _TALER_MERCHANT__GET_ORDERS_ORDER_ID_H

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


/**
 * Handle for a GET /orders/$ORDER_ID request (wallet-facing).
 */
struct TALER_MERCHANT_OrderWalletGetHandle;


/**
 * Response details for a GET /orders/$ORDER_ID request (wallet-facing).
 */
struct TALER_MERCHANT_OrderWalletGetResponse
{

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

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

    /**
     * Details on #MHD_HTTP_OK (order is paid, refund info available).
     */
    struct
    {

      /**
       * True if a refund has been granted.
       */
      bool refunded;

      /**
       * True if a refund is still pending.
       */
      bool refund_pending;

      /**
       * Total amount refunded.
       */
      struct TALER_Amount refund_amount;

    } ok;

    /**
     * Details on #MHD_HTTP_PAYMENT_REQUIRED (order not yet paid).
     */
    struct
    {

      /**
       * Taler pay URI for this order.
       */
      const char *taler_pay_uri;

      /**
       * Order ID of a previously paid order that covers this one,
       * or NULL if none.
       */
      const char *already_paid_order_id;

    } payment_required;

  } details;

};


/**
 * Callback for a GET /orders/$ORDER_ID request (wallet-facing).
 *
 * @param cls closure
 * @param owgr response details
 */
typedef void
(*TALER_MERCHANT_OrderWalletGetCallback)(
  void *cls,
  const struct TALER_MERCHANT_OrderWalletGetResponse *owgr);


/**
 * Issue a GET /orders/$ORDER_ID request (wallet-facing).
 *
 * @param ctx CURL context to use
 * @param backend_url base URL of the merchant backend
 * @param order_id identifier of the order to check
 * @param h_contract hash of the contract terms (to verify), or NULL
 * @param timeout long-polling timeout
 * @param session_id session identifier for repurchase, or NULL
 * @param min_refund minimum refund amount to wait for, or NULL
 * @param await_refund_obtained if true, wait until refund is confirmed obtained
 * @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_OrderWalletGetHandle *
TALER_MERCHANT_wallet_order_get (
  struct GNUNET_CURL_Context *ctx,
  const char *backend_url,
  const char *order_id,
  const struct TALER_PrivateContractHashP *h_contract,
  struct GNUNET_TIME_Relative timeout,
  const char *session_id,
  const struct TALER_Amount *min_refund,
  bool await_refund_obtained,
  TALER_MERCHANT_OrderWalletGetCallback cb,
  void *cb_cls);


/**
 * Cancel a GET /orders/$ORDER_ID request (wallet-facing).
 *
 * @param[in] owgh handle to cancel
 */
void
TALER_MERCHANT_wallet_order_get_cancel (
  struct TALER_MERCHANT_OrderWalletGetHandle *owgh);


#endif
