merchant

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

post-private-products-PRODUCT_ID-lock.h (7871B)


      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 src/include/taler/merchant/post-private-products-PRODUCT_ID-lock.h
     19  * @brief C interface for the POST /private/products/$PRODUCT_ID/lock endpoint
     20  * @author Christian Grothoff
     21  */
     22 #ifndef _TALER_MERCHANT__POST_PRIVATE_PRODUCTS_PRODUCT_ID_LOCK_H
     23 #define _TALER_MERCHANT__POST_PRIVATE_PRODUCTS_PRODUCT_ID_LOCK_H
     24 
     25 #include <taler/merchant/common.h>
     26 
     27 
     28 /**
     29  * Possible options for the POST /private/products/$PRODUCT_ID/lock request.
     30  */
     31 enum TALER_MERCHANT_PostPrivateProductsLockOption
     32 {
     33   /**
     34    * End of list of options.
     35    */
     36   TALER_MERCHANT_POST_PRIVATE_PRODUCTS_LOCK_OPTION_END = 0,
     37 
     38   /**
     39    * Fractional part of the quantity to lock.
     40    */
     41   TALER_MERCHANT_POST_PRIVATE_PRODUCTS_LOCK_OPTION_QUANTITY_FRAC,
     42 
     43   /**
     44    * Whether to use fractional quantity.
     45    */
     46   TALER_MERCHANT_POST_PRIVATE_PRODUCTS_LOCK_OPTION_USE_FRACTIONAL_QUANTITY
     47 
     48 };
     49 
     50 
     51 /**
     52  * Value for an option for the POST /private/products/$PRODUCT_ID/lock request.
     53  */
     54 struct TALER_MERCHANT_PostPrivateProductsLockOptionValue
     55 {
     56 
     57   /**
     58    * Type of the option being set.
     59    */
     60   enum TALER_MERCHANT_PostPrivateProductsLockOption option;
     61 
     62   /**
     63    * Specific option value.
     64    */
     65   union
     66   {
     67 
     68     /**
     69      * Value if @e option is
     70      * #TALER_MERCHANT_POST_PRIVATE_PRODUCTS_LOCK_OPTION_QUANTITY_FRAC.
     71      */
     72     uint32_t quantity_frac;
     73 
     74     /**
     75      * Value if @e option is
     76      * #TALER_MERCHANT_POST_PRIVATE_PRODUCTS_LOCK_OPTION_USE_FRACTIONAL_QUANTITY.
     77      */
     78     bool use_fractional_quantity;
     79 
     80   } details;
     81 
     82 };
     83 
     84 
     85 /**
     86  * Handle for a POST /private/products/$PRODUCT_ID/lock request.
     87  */
     88 struct TALER_MERCHANT_PostPrivateProductsLockHandle;
     89 
     90 
     91 /**
     92  * Response details for a POST /private/products/$PRODUCT_ID/lock request.
     93  */
     94 struct TALER_MERCHANT_PostPrivateProductsLockResponse
     95 {
     96 
     97   /**
     98    * HTTP response details.
     99    */
    100   struct TALER_MERCHANT_HttpResponse hr;
    101 
    102 };
    103 
    104 
    105 /**
    106  * Terminate the list of the options.
    107  *
    108  * @return the terminating object
    109  */
    110 #define TALER_MERCHANT_post_private_products_lock_option_end_()                \
    111         (const struct TALER_MERCHANT_PostPrivateProductsLockOptionValue)       \
    112         {                                                                       \
    113           .option = TALER_MERCHANT_POST_PRIVATE_PRODUCTS_LOCK_OPTION_END       \
    114         }
    115 
    116 /**
    117  * Set fractional part of quantity.
    118  *
    119  * @param f fractional part
    120  * @return representation of the option
    121  */
    122 #define TALER_MERCHANT_post_private_products_lock_option_quantity_frac(f)       \
    123         (const struct TALER_MERCHANT_PostPrivateProductsLockOptionValue)        \
    124         {                                                                        \
    125           .option = \
    126             TALER_MERCHANT_POST_PRIVATE_PRODUCTS_LOCK_OPTION_QUANTITY_FRAC, \
    127           .details.quantity_frac = (f)                                            \
    128         }
    129 
    130 /**
    131  * Set to use fractional quantity.
    132  *
    133  * @return representation of the option
    134  */
    135 #define TALER_MERCHANT_post_private_products_lock_option_use_frac_quantity() \
    136         (const struct TALER_MERCHANT_PostPrivateProductsLockOptionValue)            \
    137         {                                                                            \
    138           .option = \
    139             TALER_MERCHANT_POST_PRIVATE_PRODUCTS_LOCK_OPTION_USE_FRACTIONAL_QUANTITY, \
    140           .details.use_fractional_quantity = true                                    \
    141         }
    142 
    143 
    144 /**
    145  * Set the requested options for the operation.
    146  *
    147  * @param pplh the request to set the options for
    148  * @param num_options length of the @a options array
    149  * @param options an array of options
    150  * @return #GNUNET_OK on success,
    151  *         #GNUNET_NO on failure,
    152  *         #GNUNET_SYSERR on internal error
    153  */
    154 enum GNUNET_GenericReturnValue
    155 TALER_MERCHANT_post_private_products_lock_set_options_ (
    156   struct TALER_MERCHANT_PostPrivateProductsLockHandle *pplh,
    157   unsigned int num_options,
    158   const struct TALER_MERCHANT_PostPrivateProductsLockOptionValue *options);
    159 
    160 
    161 /**
    162  * Set the requested options for the operation.
    163  *
    164  * @param pplh the request to set the options for
    165  * @param ... the list of the options
    166  * @return #GNUNET_OK on success,
    167  *         #GNUNET_NO on failure,
    168  *         #GNUNET_SYSERR on internal error
    169  */
    170 #define TALER_MERCHANT_post_private_products_lock_set_options(pplh,...)                \
    171         TALER_MERCHANT_post_private_products_lock_set_options_ (                       \
    172           pplh,                                                                        \
    173           TALER_MERCHANT_COMMON_OPTIONS_ARRAY_MAX_SIZE,                               \
    174           ((const struct TALER_MERCHANT_PostPrivateProductsLockOptionValue[])          \
    175            {__VA_ARGS__, TALER_MERCHANT_post_private_products_lock_option_end_ \
    176               () }   \
    177           ))
    178 
    179 
    180 /**
    181  * Set up POST /private/products/$PRODUCT_ID/lock 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 lock
    188  * @param uuid idempotency UUID for this lock operation
    189  * @param duration how long to lock the inventory
    190  * @param quantity number of units to lock
    191  * @return handle to operation
    192  */
    193 struct TALER_MERCHANT_PostPrivateProductsLockHandle *
    194 TALER_MERCHANT_post_private_products_lock_create (
    195   struct GNUNET_CURL_Context *ctx,
    196   const char *url,
    197   const char *product_id,
    198   const char *uuid,
    199   struct GNUNET_TIME_Relative duration,
    200   uint64_t quantity);
    201 
    202 
    203 #ifndef TALER_MERCHANT_POST_PRIVATE_PRODUCTS_LOCK_RESULT_CLOSURE
    204 /**
    205  * Type of the closure used by
    206  * the #TALER_MERCHANT_PostPrivateProductsLockCallback.
    207  */
    208 #define TALER_MERCHANT_POST_PRIVATE_PRODUCTS_LOCK_RESULT_CLOSURE void
    209 #endif /* TALER_MERCHANT_POST_PRIVATE_PRODUCTS_LOCK_RESULT_CLOSURE */
    210 
    211 /**
    212  * Callback for a POST /private/products/$PRODUCT_ID/lock request.
    213  *
    214  * @param cls closure
    215  * @param plr response details
    216  */
    217 typedef void
    218 (*TALER_MERCHANT_PostPrivateProductsLockCallback)(
    219   TALER_MERCHANT_POST_PRIVATE_PRODUCTS_LOCK_RESULT_CLOSURE *cls,
    220   const struct TALER_MERCHANT_PostPrivateProductsLockResponse *plr);
    221 
    222 
    223 /**
    224  * Start POST /private/products/$PRODUCT_ID/lock operation.
    225  *
    226  * @param[in,out] pplh operation to start
    227  * @param cb function to call with the merchant's result
    228  * @param cb_cls closure for @a cb
    229  * @return status code, #TALER_EC_NONE on success
    230  */
    231 enum TALER_ErrorCode
    232 TALER_MERCHANT_post_private_products_lock_start (
    233   struct TALER_MERCHANT_PostPrivateProductsLockHandle *pplh,
    234   TALER_MERCHANT_PostPrivateProductsLockCallback cb,
    235   TALER_MERCHANT_POST_PRIVATE_PRODUCTS_LOCK_RESULT_CLOSURE *cb_cls);
    236 
    237 
    238 /**
    239  * Cancel POST /private/products/$PRODUCT_ID/lock operation.  This function
    240  * must not be called by clients after the
    241  * TALER_MERCHANT_PostPrivateProductsLockCallback has been invoked (as in
    242  * those cases it'll be called internally by the implementation already).
    243  *
    244  * @param[in] pplh operation to cancel
    245  */
    246 void
    247 TALER_MERCHANT_post_private_products_lock_cancel (
    248   struct TALER_MERCHANT_PostPrivateProductsLockHandle *pplh);
    249 
    250 
    251 #endif /* _TALER_MERCHANT__POST_PRIVATE_PRODUCTS_PRODUCT_ID_LOCK_H */