post-orders-ORDER_ID-abort.h (6946B)
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-orders-ORDER_ID-abort.h 19 * @brief C interface for the POST /orders/$ORDER_ID/abort endpoint 20 * @author Christian Grothoff 21 */ 22 #ifndef _TALER_MERCHANT__POST_ORDERS_ORDER_ID_ABORT_H 23 #define _TALER_MERCHANT__POST_ORDERS_ORDER_ID_ABORT_H 24 25 #include <taler/merchant/common.h> 26 27 28 /** 29 * Handle for a POST /orders/$ORDER_ID/abort request. 30 */ 31 struct TALER_MERCHANT_PostOrdersAbortHandle; 32 33 34 /** 35 * One coin used in an abort request. 36 */ 37 struct TALER_MERCHANT_PostOrdersAbortCoin 38 { 39 40 /** 41 * Base URL of the exchange this coin was issued by. 42 */ 43 const char *exchange_url; 44 45 /** 46 * Public key of the coin. 47 */ 48 struct TALER_CoinSpendPublicKeyP coin_pub; 49 50 /** 51 * Total amount contributed including deposit fee. 52 */ 53 struct TALER_Amount amount_with_fee; 54 55 /** 56 * Hash of the denomination public key. 57 */ 58 struct TALER_DenominationHashP denom_pub_hash; 59 60 /** 61 * Denomination signature over the coin. 62 */ 63 struct TALER_DenominationSignature denom_sig; 64 65 }; 66 67 68 /** 69 * Result for one coin from an abort operation. 70 */ 71 struct TALER_MERCHANT_PostOrdersAbortedCoin 72 { 73 /** 74 * Type of status for this coin, determines content of @e details 75 */ 76 enum 77 { 78 TALER_MERCHANT_POAC_UNDEPOSITED = 0, 79 TALER_MERCHANT_POAC_SUCCESS, 80 TALER_MERCHANT_POAC_FAILURE, 81 } type; 82 83 /** 84 * Public key of the coin. 85 */ 86 struct TALER_CoinSpendPublicKeyP coin_pub; 87 88 /** 89 * Details depending on @e type 90 */ 91 union 92 { 93 94 /** 95 * Details on #TALER_MERCHANT_POAC_SUCCESS. 96 */ 97 struct 98 { 99 100 /** 101 * Exchange signature confirming the refund. 102 */ 103 struct TALER_ExchangeSignatureP exchange_sig; 104 105 /** 106 * Exchange public key used for @e exchange_sig. 107 */ 108 struct TALER_ExchangePublicKeyP exchange_pub; 109 110 /** 111 * HTTP status of the abort from the exchange. 112 */ 113 uint32_t exchange_status; 114 } success; 115 116 /** 117 * Details on #TALER_MERCHANT_POAC_FAILURE. 118 */ 119 struct 120 { 121 122 /** 123 * HTTP status of the abort from the exchange. 124 */ 125 uint32_t exchange_status; 126 127 /** 128 * Error code from the exchange. 129 */ 130 enum TALER_ErrorCode exchange_code; 131 132 /** 133 * Full exchange reply, could be NULL. 134 */ 135 const json_t *exchange_reply; 136 137 } failure; 138 139 } details; 140 141 }; 142 143 144 /** 145 * Response details for a POST /orders/$ORDER_ID/abort request. 146 */ 147 struct TALER_MERCHANT_PostOrdersAbortResponse 148 { 149 150 /** 151 * HTTP response details. 152 */ 153 struct TALER_MERCHANT_HttpResponse hr; 154 155 /** 156 * Details depending on the HTTP status code. 157 */ 158 union 159 { 160 161 /** 162 * Details on #MHD_HTTP_OK. 163 */ 164 struct 165 { 166 167 /** 168 * Number of aborted coins in @a aborts. 169 */ 170 unsigned int num_aborts; 171 172 /** 173 * Array of aborted coin results. 174 */ 175 const struct TALER_MERCHANT_PostOrdersAbortedCoin *aborts; 176 177 } ok; 178 179 /** 180 * Details on #MHD_HTTP_BAD_GATEWAY. 181 * The response body has the same refunds array as on 182 * #MHD_HTTP_OK, but at least one coin had an exchange error. 183 */ 184 struct 185 { 186 187 /** 188 * Number of aborted coins in @a aborts. 189 */ 190 unsigned int num_aborts; 191 192 /** 193 * Array of aborted coin results. 194 */ 195 const struct TALER_MERCHANT_PostOrdersAbortedCoin *aborts; 196 197 } bad_gateway; 198 199 /** 200 * Details on #MHD_HTTP_GATEWAY_TIMEOUT. 201 */ 202 struct 203 { 204 205 /** 206 * Taler error code from the exchange, if available. 207 */ 208 enum TALER_ErrorCode exchange_ec; 209 210 /** 211 * HTTP status code returned by the exchange, if available. 212 * 0 if no exchange was involved or the request timed out 213 * before a response was received. 214 */ 215 unsigned int exchange_http_status; 216 217 } gateway_timeout; 218 219 } details; 220 221 }; 222 223 224 /** 225 * Set up POST /orders/$ORDER_ID/abort operation. 226 * Note that you must explicitly start the operation after 227 * possibly setting options. 228 * 229 * @param ctx the context 230 * @param url base URL of the merchant backend 231 * @param order_id identifier of the order to abort 232 * @param merchant_pub merchant public key 233 * @param h_contract hash of the contract terms 234 * @param num_coins number of coins in @a coins 235 * @param coins array of coins used in the aborted payment 236 * @return handle to operation 237 */ 238 struct TALER_MERCHANT_PostOrdersAbortHandle * 239 TALER_MERCHANT_post_orders_abort_create ( 240 struct GNUNET_CURL_Context *ctx, 241 const char *url, 242 const char *order_id, 243 const struct TALER_MerchantPublicKeyP *merchant_pub, 244 const struct TALER_PrivateContractHashP *h_contract, 245 unsigned int num_coins, 246 const struct TALER_MERCHANT_PostOrdersAbortCoin coins[static num_coins]); 247 248 249 #ifndef TALER_MERCHANT_POST_ORDERS_ABORT_RESULT_CLOSURE 250 /** 251 * Type of the closure used by 252 * the #TALER_MERCHANT_PostOrdersAbortCallback. 253 */ 254 #define TALER_MERCHANT_POST_ORDERS_ABORT_RESULT_CLOSURE void 255 #endif /* TALER_MERCHANT_POST_ORDERS_ABORT_RESULT_CLOSURE */ 256 257 /** 258 * Callback for a POST /orders/$ORDER_ID/abort request. 259 * 260 * @param cls closure 261 * @param oar response details 262 */ 263 typedef void 264 (*TALER_MERCHANT_PostOrdersAbortCallback)( 265 TALER_MERCHANT_POST_ORDERS_ABORT_RESULT_CLOSURE *cls, 266 const struct TALER_MERCHANT_PostOrdersAbortResponse *oar); 267 268 269 /** 270 * Start POST /orders/$ORDER_ID/abort operation. 271 * 272 * @param[in,out] poah operation to start 273 * @param cb function to call with the merchant's result 274 * @param cb_cls closure for @a cb 275 * @return status code, #TALER_EC_NONE on success 276 */ 277 enum TALER_ErrorCode 278 TALER_MERCHANT_post_orders_abort_start ( 279 struct TALER_MERCHANT_PostOrdersAbortHandle *poah, 280 TALER_MERCHANT_PostOrdersAbortCallback cb, 281 TALER_MERCHANT_POST_ORDERS_ABORT_RESULT_CLOSURE *cb_cls); 282 283 284 /** 285 * Cancel POST /orders/$ORDER_ID/abort operation. This function must not be 286 * called by clients after the TALER_MERCHANT_PostOrdersAbortCallback has 287 * been invoked (as in those cases it'll be called internally by the 288 * implementation already). 289 * 290 * @param[in] poah operation to cancel 291 */ 292 void 293 TALER_MERCHANT_post_orders_abort_cancel ( 294 struct TALER_MERCHANT_PostOrdersAbortHandle *poah); 295 296 297 #endif /* _TALER_MERCHANT__POST_ORDERS_ORDER_ID_ABORT_H */