merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

merchant_api_common.h (3888B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2020-2023 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU Lesser General Public License as published by the Free Software
      7   Foundation; either version 2.1, or (at your option) any later version.
      8 
      9   TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     10   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11   A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
     12 
     13   You should have received a copy of the GNU Lesser General Public License along with
     14   TALER; see the file COPYING.LGPL.  If not, see
     15   <http://www.gnu.org/licenses/>
     16 */
     17 /**
     18  * @file merchant_api_common.h
     19  * @brief Implementation of common logic for libtalermerchant
     20  * @author Christian Grothoff
     21  * @author Priscilla Huang
     22  */
     23 #ifndef MERCHANT_API_COMMON_H
     24 #define MERCHANT_API_COMMON_H
     25 #include "taler/taler_merchant_service.h"
     26 
     27 
     28 /**
     29  * Function called when we're done processing a
     30  * HTTP POST request to create an order.
     31  *
     32  * @param cb callback
     33  * @param cb_cls closure for @a cb
     34  * @param response_code HTTP response code, 0 on error
     35  * @param json response body, NULL if not JSON
     36  */
     37 void
     38 TALER_MERCHANT_handle_order_creation_response_ (
     39   TALER_MERCHANT_PostPrivateOrdersCallback cb,
     40   void *cb_cls,
     41   long response_code,
     42   const json_t *json);
     43 
     44 
     45 /**
     46  * Take a @a response from the merchant API that (presumably) contains
     47  * error details and setup the corresponding @a hr structure.  Internally
     48  * used to convert merchant's responses in to @a hr.
     49  *
     50  * @param response if NULL we will report #TALER_EC_GENERIC_INVALID_RESPONSE in `ec`
     51  * @param http_status http status to use
     52  * @param[out] hr response object to initialize, fields will
     53  *        only be valid as long as @a response is valid as well
     54  */
     55 void
     56 TALER_MERCHANT_parse_error_details_ (const json_t *response,
     57                                      unsigned int http_status,
     58                                      struct TALER_MERCHANT_HttpResponse *hr);
     59 
     60 
     61 /**
     62  * Parse a 202 Accepted MFA challenge response from JSON.
     63  *
     64  * @param json the JSON response body
     65  * @param[out] cr challenge response to fill in
     66  * @return #GNUNET_OK on success, #GNUNET_SYSERR on parse error
     67  */
     68 enum GNUNET_GenericReturnValue
     69 TALER_MERCHANT_parse_mfa_challenge_response_ (
     70   const json_t *json,
     71   struct TALER_MERCHANT_MfaChallengeResponse *cr);
     72 
     73 
     74 enum GNUNET_GenericReturnValue
     75 TALER_MERCHANT_parse_fractional_string (bool allow_negative,
     76                                         const char *value,
     77                                         int64_t *integer_part,
     78                                         uint32_t *fractional_part);
     79 
     80 
     81 /**
     82  * Format a quantity into its decimal string representation using the merchant
     83  * fixed-point base (TALER_MERCHANT_UNIT_FRAC_BASE).
     84  *
     85  * @param quantity integer part
     86  * @param quantity_frac fractional part (0..TALER_MERCHANT_UNIT_FRAC_BASE-1)
     87  * @param[out] buffer output buffer
     88  * @param buffer_length size of @a buffer
     89  */
     90 void
     91 TALER_MERCHANT_format_quantity_string (uint64_t quantity,
     92                                        uint32_t quantity_frac,
     93                                        char *buffer,
     94                                        size_t buffer_length);
     95 
     96 
     97 /**
     98  * Format a stock value into its decimal string representation using the
     99  * merchant fixed-point base (TALER_MERCHANT_UNIT_FRAC_BASE).
    100  *
    101  * @param total_stock integer part
    102  * @param total_stock_frac fractional part (0..TALER_MERCHANT_UNIT_FRAC_BASE-1)
    103  * @param[out] buffer output buffer
    104  * @param buffer_length size of @a buffer
    105  */
    106 void
    107 TALER_MERCHANT_format_stock_string (uint64_t total_stock,
    108                                     uint32_t total_stock_frac,
    109                                     char *buffer,
    110                                     size_t buffer_length);
    111 
    112 
    113 #endif