merchant_api_common.h (3479B)
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_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_PostOrdersCallback 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 enum GNUNET_GenericReturnValue 62 TALER_MERCHANT_parse_fractional_string (bool allow_negative, 63 const char *value, 64 int64_t *integer_part, 65 uint32_t *fractional_part); 66 67 68 /** 69 * Format a quantity into its decimal string representation using the merchant 70 * fixed-point base (MERCHANT_UNIT_FRAC_BASE). 71 * 72 * @param quantity integer part 73 * @param quantity_frac fractional part (0..MERCHANT_UNIT_FRAC_BASE-1) 74 * @param[out] buffer output buffer 75 * @param buffer_length size of @a buffer 76 */ 77 void 78 TALER_MERCHANT_format_quantity_string (uint64_t quantity, 79 uint32_t quantity_frac, 80 char *buffer, 81 size_t buffer_length); 82 83 84 /** 85 * Format a stock value into its decimal string representation using the 86 * merchant fixed-point base (MERCHANT_UNIT_FRAC_BASE). 87 * 88 * @param total_stock integer part 89 * @param total_stock_frac fractional part (0..MERCHANT_UNIT_FRAC_BASE-1) 90 * @param[out] buffer output buffer 91 * @param buffer_length size of @a buffer 92 */ 93 void 94 TALER_MERCHANT_format_stock_string (uint64_t total_stock, 95 uint32_t total_stock_frac, 96 char *buffer, 97 size_t buffer_length); 98 99 100 #endif