cash2ecash

cash2ecash: cash acceptor that issues digital cash (experimental)
Log | Files | Refs | Submodules | README | LICENSE

taler_bank_service_cash2ecash.h (8056B)


      1 #include <jansson.h>
      2 #include <gnunet/gnunet_curl_lib.h>
      3 #include <taler/taler_util.h>
      4 #include <taler/taler_error_codes.h>
      5 
      6 #include <taler/taler_bank_service.h>
      7 
      8 
      9 
     10 /* ********************* /accounts/$ACC/withdrawals *********************** */
     11 
     12 
     13 /**
     14  * @brief A /accounts/$USERNAME/withdrawals request handle
     15  */
     16 struct TALER_BANK_AccountWithdrawalHandle;
     17 
     18 
     19 /**
     20  * Response details for a withdrawal request.
     21  */
     22 struct TALER_BANK_AccountWithdrawalResponse
     23 {
     24 
     25   /**
     26    * HTTP status.
     27    */
     28   unsigned int http_status;
     29 
     30   /**
     31    * Taler error code, #TALER_EC_NONE on success.
     32    */
     33   enum TALER_ErrorCode ec;
     34 
     35   /**
     36    * Full response, NULL if body was not in JSON format.
     37    */
     38   const json_t *response;
     39 
     40   /**
     41    * Details returned depending on the @e http_status.
     42    */
     43   union
     44   {
     45 
     46     /**
     47      * Details if status was #MHD_HTTP_OK
     48      */
     49     struct
     50     {
     51       /**
     52        * Withdrawal ID
     53        */
     54       const char *withdrawal_id;
     55 
     56       /**
     57        * Taler Withdraw URI
     58        */
     59       const char *taler_withdraw_uri;
     60 
     61     } ok;
     62 
     63   } details;
     64 
     65 };
     66 
     67 
     68 /**
     69  * Callbacks of this type are used to return the result of submitting
     70  * a request for an withdrawal to the bank.
     71  *
     72  * @param cls closure
     73  * @param awr response details
     74  */
     75 typedef void
     76 (*TALER_BANK_AccountWithdrawalCallback) (
     77   void *cls,
     78   const struct TALER_BANK_AccountWithdrawalResponse *awr);
     79 
     80 
     81 
     82 
     83 /**
     84  * Posts a withdrawal request to the bank
     85  *
     86  * @param ctx curl context for the event loop
     87  * @param auth authentication data to send to the bank
     88  * @param account_name username of the bank account to which the withdrawal request is sent.
     89  * @param amount amount to withdraw (not mandatory, NULL if unspecified)
     90  * #param suggested_amount suggesiton for the amount, which can be changed by the wallet. (NULL if unspecified)
     91  * @param res_cb the callback to call when the final result for this request is available
     92  * @param res_cb_cls closure for the above callback
     93  * @return NULL
     94  *         if the inputs are invalid (i.e. invalid amount) or internal errors.
     95  *         In this case, the callback is not called.
     96  */
     97 struct TALER_BANK_AccountWithdrawalHandle *
     98 TALER_BANK_account_withdrawal (
     99   struct GNUNET_CURL_Context *ctx,
    100   const struct TALER_BANK_AuthenticationData *auth,
    101   const char *account_name,
    102   const struct TALER_Amount *amount,
    103   const struct TALER_Amount *suggested_amount,
    104   const bool *no_amount_to_wallet,
    105   TALER_BANK_AccountWithdrawalCallback res_cb,
    106   void *res_cb_cls);
    107 
    108 
    109 /**
    110  * Cancel an account withdrawal operation.  This function cannot be used on a
    111  * request handle if a response is already served for it.
    112  *
    113  * @param[in] awh the withdrawal request handle
    114  */
    115 void
    116 TALER_BANK_account_withdrawal_cancel (
    117   struct TALER_BANK_AccountWithdrawalHandle *awh);
    118 
    119 
    120 /* ********************* /accounts/$ACC/withdrawals/$WITHDRAWAL_ID/confirm *********************** */
    121 
    122 /**
    123  * @brief A /accounts/$USERNAME/withdrawals/$WITHDRAWAL_ID/confirm request handle
    124  */
    125 struct TALER_BANK_AccountWithdrawalConfirmHandle;
    126 
    127 
    128 /**
    129  * Response details for a withdrawal confirmation request.
    130  */
    131 struct TALER_BANK_AccountWithdrawalConfirmResponse
    132 {
    133 
    134   /**
    135    * HTTP status.
    136    */
    137   unsigned int http_status;
    138 
    139   /**
    140    * Taler error code, #TALER_EC_NONE on success.
    141    */
    142   enum TALER_ErrorCode ec;
    143 
    144   /**
    145    * Full response, NULL if body was not in JSON format.
    146    */
    147   const json_t *response;
    148 
    149 };
    150 
    151 
    152 /**
    153  * Callbacks of this type are used to return the result of submitting
    154  * a request for an withdrawal confirmation to the bank.
    155  *
    156  * @param cls closure
    157  * @param awr response details
    158  */
    159 typedef void
    160 (*TALER_BANK_AccountWithdrawalConfirmCallback) (
    161   void *cls,
    162   const struct TALER_BANK_AccountWithdrawalConfirmResponse *awcr);
    163 
    164 
    165 
    166 
    167 /**
    168  * Posts a withdrawal confirmation request to the bank
    169  *
    170  * @param ctx curl context for the event loop
    171  * @param auth authentication data to send to the bank
    172  * @param account_name username of the bank account to which the withdrawal request is sent.
    173  * #param withdrawal_id id of the withdrawal to confirm
    174  * @param amount amount to withdraw (not mandatory, NULL if unspecified)
    175  * @param res_cb the callback to call when the final result for this request is available
    176  * @param res_cb_cls closure for the above callback
    177  * @return NULL
    178  *         if the inputs are invalid (i.e. invalid amount) or internal errors.
    179  *         In this case, the callback is not called.
    180  */
    181 struct TALER_BANK_AccountWithdrawalConfirmHandle *
    182 TALER_BANK_account_withdrawal_confirm (
    183   struct GNUNET_CURL_Context *ctx,
    184   const struct TALER_BANK_AuthenticationData *auth,
    185   const char *account_name,
    186   const char *withdrawal_id,
    187   const struct TALER_Amount *amount,
    188   TALER_BANK_AccountWithdrawalConfirmCallback res_cb,
    189   void *res_cb_cls);
    190 
    191 
    192 /**
    193  * Cancel an account withdrawal confirm operation.  This function cannot be used on a
    194  * request handle if a response is already served for it.
    195  *
    196  * @param[in] awch the withdrawal confirm request handle
    197  */
    198 void
    199 TALER_BANK_account_withdrawal_confirm_cancel (
    200   struct TALER_BANK_AccountWithdrawalConfirmHandle *awch);
    201 
    202 
    203 
    204 /* ********************* /withdrawals/$WITHDRAWAL_ID *********************** */
    205 
    206 /**
    207  * @brief A /withdrawals/$WITHDRAWAL_ID request handle
    208  */
    209 struct TALER_BANK_ithdrawalIDInfoHandle;
    210 
    211 
    212 /**
    213  * Response details for a withdrawalID info request.
    214  */
    215 struct TALER_BANK_WithdrawalIDInfoResponse
    216 {
    217 
    218   /**
    219    * HTTP status.
    220    */
    221   unsigned int http_status;
    222 
    223   /**
    224    * Taler error code, #TALER_EC_NONE on success.
    225    */
    226   enum TALER_ErrorCode ec;
    227 
    228   /**
    229    * Full response, NULL if body was not in JSON format.
    230    */
    231   const json_t *response;
    232 
    233   /**
    234    * Details returned depending on the @e http_status.
    235    */
    236   union
    237   {
    238 
    239     /**
    240      * Details if status was #MHD_HTTP_OK
    241      */
    242     struct
    243     {
    244       /**
    245        * Status
    246        */
    247       const char *status;
    248 
    249       /**
    250        * Amount (optional)
    251        */
    252       struct TALER_Amount amount;
    253 
    254       /**
    255        * Suggested Amount (optional)
    256        */
    257       struct TALER_Amount suggested_amount;
    258 
    259       /**
    260        * If true, the wallet must not allow the user to specify an amount to withdraw (optional)
    261        */
    262       bool no_amount_to_wallet;
    263 
    264       /**
    265        * Account username
    266        */
    267       const char *username;
    268 
    269       /**
    270        * Reserve public key selected by the exchange,
    271        * only non-null, if status is selected or confirmed
    272        */
    273       const char *selected_reserve_pub;
    274 
    275       /**
    276        * Exchange account selected by the wallet
    277        * only non-null if status is selected or confirmed
    278        */
    279       const char *selected_exchange_account;
    280 
    281     } ok;
    282 
    283   } details;
    284 
    285 };
    286 
    287 
    288 /**
    289  * Callbacks of this type are used to return the result of submitting
    290  * a request for an withdrawal id info to the bank.
    291  *
    292  * @param cls closure
    293  * @param awr response details
    294  */
    295 typedef void
    296 (*TALER_BANK_WithdrawalIDInfoCallback) (
    297   void *cls,
    298   const struct TALER_BANK_WithdrawalIDInfoResponse *awcr);
    299 
    300 
    301 
    302 
    303 /**
    304  * Posts a withdrawal id info request to the bank
    305  *
    306  * @param ctx curl context for the event loop
    307  * @param auth authentication data to send to the bank, only url is used for this request
    308  * #param withdrawal_id id of the withdrawal for which information should be obtained. 
    309  * @param res_cb the callback to call when the final result for this request is available
    310  * @param res_cb_cls closure for the above callback
    311  * @return NULL
    312  *         if the inputs are invalid (i.e. invalid amount) or internal errors.
    313  *         In this case, the callback is not called.
    314  */
    315 struct TALER_BANK_WithdrawalIDInfoHandle *
    316 TALER_BANK_withdrawalID_info (
    317   struct GNUNET_CURL_Context *ctx,
    318   const struct TALER_BANK_AuthenticationData *auth,
    319   const char *withdrawal_id,
    320   TALER_BANK_WithdrawalIDInfoCallback res_cb,
    321   void *res_cb_cls);
    322 
    323 
    324 /**
    325  * Cancel an withdrawal id info operation.  This function cannot be used on a
    326  * request handle if a response is already served for it.
    327  *
    328  * @param[in] awch the withdrawal id info request handle
    329  */
    330 void
    331 TALER_BANK_withdrawalID_info_cancel (
    332   struct TALER_BANK_WithdrawalIDInfoHandle *awch);
    333