merchant

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

get-private-products-PRODUCT_ID.h (6117B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2014-2026 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 include/taler/taler-merchant/get-private-products-PRODUCT_ID.h
     19  * @brief C interface for GET /private/products/$PRODUCT_ID of the merchant backend
     20  * @author Christian Grothoff
     21  */
     22 #ifndef _TALER_MERCHANT__GET_PRIVATE_PRODUCTS_PRODUCT_ID_H
     23 #define _TALER_MERCHANT__GET_PRIVATE_PRODUCTS_PRODUCT_ID_H
     24 
     25 #include <taler/taler-merchant/common.h>
     26 
     27 
     28 /**
     29  * Handle for a GET /private/products/$PRODUCT_ID request.
     30  */
     31 struct TALER_MERCHANT_GetPrivateProductHandle;
     32 
     33 
     34 /**
     35  * Response details for a GET /private/products/$PRODUCT_ID request.
     36  */
     37 struct TALER_MERCHANT_GetPrivateProductResponse
     38 {
     39 
     40   /**
     41    * HTTP response details.
     42    */
     43   struct TALER_MERCHANT_HttpResponse hr;
     44 
     45   /**
     46    * Details depending on the HTTP status code.
     47    */
     48   union
     49   {
     50 
     51     /**
     52      * Details on #MHD_HTTP_OK.
     53      */
     54     struct
     55     {
     56 
     57       /**
     58        * Human-readable product name.
     59        */
     60       const char *product_name;
     61 
     62       /**
     63        * Human-readable product description.
     64        */
     65       const char *description;
     66 
     67       /**
     68        * Internationalized descriptions (JSON object), or NULL.
     69        */
     70       const json_t *description_i18n;
     71 
     72       /**
     73        * Unit of measurement for this product.
     74        */
     75       const char *unit;
     76 
     77       /**
     78        * Number of prices in @a unit_price.
     79        */
     80       size_t unit_price_len;
     81 
     82       /**
     83        * Array of unit prices (for different payment options).
     84        */
     85       const struct TALER_Amount *unit_price;
     86 
     87       /**
     88        * Single unit price (first element of @a unit_price, for backwards compatibility).
     89        */
     90       struct TALER_Amount price;
     91 
     92       /**
     93        * Base64-encoded product image, or empty string.
     94        */
     95       const char *image;
     96 
     97       /**
     98        * Tax information (JSON array), or NULL.
     99        */
    100       const json_t *taxes;
    101 
    102       /**
    103        * Total available stock (-1 for unlimited).
    104        */
    105       int64_t total_stock;
    106 
    107       /**
    108        * Total stock in fractional unit representation.
    109        * Stock level encoded as a decimal string. Preferred source of truth for fractional stock.
    110        */
    111       const char *unit_total_stock;
    112 
    113       /**
    114        * Whether fractional quantities are allowed.
    115        */
    116       bool unit_allow_fraction;
    117 
    118       /**
    119        * Precision level for fractional quantities.
    120        */
    121       uint32_t unit_precision_level;
    122 
    123       /**
    124        * Total number of units sold.
    125        */
    126       uint64_t total_sold;
    127 
    128       /**
    129        * Total number of units lost/expired.
    130        */
    131       uint64_t total_lost;
    132 
    133       /**
    134        * Storage location (JSON), or NULL.
    135        */
    136       const json_t *location;
    137 
    138       /**
    139        * Expected time of next restock (may be zero if unknown).
    140        */
    141       struct GNUNET_TIME_Timestamp next_restock;
    142 
    143       /**
    144        * Number of categories in @a categories.
    145        */
    146       unsigned int categories_len;
    147 
    148       /**
    149        * Array of category IDs this product belongs to.
    150        */
    151       const uint64_t *categories;
    152 
    153       /**
    154        * Product group ID (0 if not set).
    155        */
    156       uint64_t product_group_id;
    157 
    158       /**
    159        * Money pot ID (0 if not set).
    160        */
    161       uint64_t money_pot_id;
    162 
    163       /**
    164        * Whether the price is net (excluding taxes).
    165        */
    166       bool price_is_net;
    167 
    168       /**
    169        * Minimum age required to purchase this product (0 if not set).
    170        */
    171       uint16_t minimum_age;
    172 
    173     } ok;
    174 
    175   } details;
    176 
    177 };
    178 
    179 
    180 /**
    181  * Set up GET /private/products/$PRODUCT_ID operation.
    182  * Note that you must explicitly start the operation after
    183  * possibly setting options.
    184  *
    185  * @param ctx the context
    186  * @param url base URL of the merchant backend
    187  * @param product_id identifier of the product to retrieve
    188  * @return handle to operation
    189  */
    190 struct TALER_MERCHANT_GetPrivateProductHandle *
    191 TALER_MERCHANT_get_private_product_create (
    192   struct GNUNET_CURL_Context *ctx,
    193   const char *url,
    194   const char *product_id);
    195 
    196 
    197 #ifndef TALER_MERCHANT_GET_PRIVATE_PRODUCT_RESULT_CLOSURE
    198 /**
    199  * Type of the closure used by
    200  * the #TALER_MERCHANT_GetPrivateProductCallback.
    201  */
    202 #define TALER_MERCHANT_GET_PRIVATE_PRODUCT_RESULT_CLOSURE void
    203 #endif /* TALER_MERCHANT_GET_PRIVATE_PRODUCT_RESULT_CLOSURE */
    204 
    205 /**
    206  * Callback for a GET /private/products/$PRODUCT_ID request.
    207  *
    208  * @param cls closure
    209  * @param pgr response details
    210  */
    211 typedef void
    212 (*TALER_MERCHANT_GetPrivateProductCallback)(
    213   TALER_MERCHANT_GET_PRIVATE_PRODUCT_RESULT_CLOSURE *cls,
    214   const struct TALER_MERCHANT_GetPrivateProductResponse *pgr);
    215 
    216 
    217 /**
    218  * Start GET /private/products/$PRODUCT_ID operation.
    219  *
    220  * @param[in,out] gpp operation to start
    221  * @param cb function to call with the merchant's result
    222  * @param cb_cls closure for @a cb
    223  * @return status code, #TALER_EC_NONE on success
    224  */
    225 enum TALER_ErrorCode
    226 TALER_MERCHANT_get_private_product_start (
    227   struct TALER_MERCHANT_GetPrivateProductHandle *gpp,
    228   TALER_MERCHANT_GetPrivateProductCallback cb,
    229   TALER_MERCHANT_GET_PRIVATE_PRODUCT_RESULT_CLOSURE *cb_cls);
    230 
    231 
    232 /**
    233  * Cancel GET /private/products/$PRODUCT_ID operation.  This function
    234  * must not be called by clients after the
    235  * TALER_MERCHANT_GetPrivateProductCallback has been invoked
    236  * (as in those cases it'll be called internally by the
    237  * implementation already).
    238  *
    239  * @param[in] gpp operation to cancel
    240  */
    241 void
    242 TALER_MERCHANT_get_private_product_cancel (
    243   struct TALER_MERCHANT_GetPrivateProductHandle *gpp);
    244 
    245 
    246 #endif /* _TALER_MERCHANT__GET_PRIVATE_PRODUCTS_PRODUCT_ID_H */