merchant

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

commit 1de87fc27f26ce5e1d54526ae66d45f9e35b13ac
parent b9b230e7079bb9e1eb937ef07e1b6b7408176f3d
Author: Christian Grothoff <christian@grothoff.org>
Date:   Thu, 20 Oct 2016 21:23:14 +0200

have merchant C API also return taler error codes (at least those from the merchant for now)

Diffstat:
Msrc/include/taler_merchant_service.h | 11+++++++++++
Msrc/lib/merchant_api_contract.c | 1+
Msrc/lib/merchant_api_history.c | 16++++++++++------
Msrc/lib/merchant_api_pay.c | 1+
Msrc/lib/merchant_api_track_transaction.c | 2++
Msrc/lib/merchant_api_track_transfer.c | 2++
Msrc/lib/test_merchant_api.c | 13++++++++++++-
7 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h @@ -23,6 +23,7 @@ #define _TALER_MERCHANT_SERVICE_H #include <taler/taler_util.h> +#include <taler/taler_error_codes.h> #include <gnunet/gnunet_curl_lib.h> #include <jansson.h> @@ -43,6 +44,7 @@ struct TALER_MERCHANT_ContractOperation; * @param cls closure * @param http_status HTTP response code, 200 indicates success; * 0 if the backend's reply is bogus (fails to follow the protocol) + * @param ec taler-specific error code * @param obj the full received JSON reply, or * error details if the request failed * @param contract completed contract, NULL on error @@ -52,6 +54,7 @@ struct TALER_MERCHANT_ContractOperation; typedef void (*TALER_MERCHANT_ContractCallback) (void *cls, unsigned int http_status, + enum TALER_ErrorCode ec, const json_t *obj, const json_t *contract, const struct TALER_MerchantSignatureP *sig, @@ -110,11 +113,13 @@ struct TALER_MERCHANT_Pay; * can indicate success, depending on whether the interaction * was with a merchant frontend or backend; * 0 if the merchant's reply is bogus (fails to follow the protocol) + * @param ec taler-specific error code * @param obj the received JSON reply, with error details if the request failed */ typedef void (*TALER_MERCHANT_PayCallback) (void *cls, unsigned int http_status, + enum TALER_ErrorCode ec, const json_t *obj); @@ -317,6 +322,7 @@ struct TALER_MERCHANT_TrackTransferHandle; * * @param cls closure * @param http_status HTTP status code we got, 0 on exchange protocol violation + * @param ec taler-specific error code * @param sign_key exchange key used to sign @a json, or NULL * @param json original json reply (may include signatures, those have then been * validated already) @@ -329,6 +335,7 @@ struct TALER_MERCHANT_TrackTransferHandle; typedef void (*TALER_MERCHANT_TrackTransferCallback) (void *cls, unsigned int http_status, + enum TALER_ErrorCode ec, const struct TALER_ExchangePublicKeyP *sign_key, const json_t *json, const struct GNUNET_HashCode *h_wire, @@ -436,6 +443,7 @@ struct TALER_MERCHANT_TransactionWireTransfer * * @param cls closure * @param http_status HTTP status code we got, 0 on exchange protocol violation + * @param ec taler-specific error code * @param json original json reply from the backend * @param num_transfers number of wire transfers the exchange used for the transaction * @param transfers details about each transfer and which coins are aggregated in it @@ -443,6 +451,7 @@ struct TALER_MERCHANT_TransactionWireTransfer typedef void (*TALER_MERCHANT_TrackTransactionCallback) (void *cls, unsigned int http_status, + enum TALER_ErrorCode ec, const json_t *json, unsigned int num_transfers, const struct TALER_MERCHANT_TransactionWireTransfer *transfers); @@ -488,11 +497,13 @@ struct TALER_MERCHANT_HistoryOperation; * * @param cls closure * @param http_status HTTP status returned by the merchant backend + * @param ec taler-specific error code * @param json actual body containing history */ typedef void (*TALER_MERCHANT_HistoryOperationCallback) (void *cls, unsigned int http_status, + enum TALER_ErrorCode ec, const json_t *json); /** diff --git a/src/lib/merchant_api_contract.c b/src/lib/merchant_api_contract.c @@ -148,6 +148,7 @@ handle_contract_finished (void *cls, } co->cb (co->cb_cls, response_code, + TALER_JSON_get_error_code (json), json, contract, sigp, diff --git a/src/lib/merchant_api_history.c b/src/lib/merchant_api_history.c @@ -81,7 +81,7 @@ TALER_MERCHANT_history_cancel (struct TALER_MERCHANT_HistoryOperation *ho) /** * Function called when we're done processing the - * HTTP /track/transaction request. + * HTTP /history request. * * @param cls the `struct TALER_MERCHANT_TrackTransactionHandle` * @param response_code HTTP response code, 0 on error @@ -102,16 +102,18 @@ history_raw_cb (void *cls, break; case MHD_HTTP_OK: ho->cb (ho->cb_cls, - response_code, + MHD_HTTP_OK, + TALER_EC_NONE, json); return; break; case MHD_HTTP_INTERNAL_SERVER_ERROR: - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "history URI not found\n"); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "/history URI not found\n"); break; - case MHD_HTTP_BAD_REQUEST: - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Wrong parameter passed in URL\n"); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Wrong parameter passed in URL\n"); break; default: /* unexpected response code */ @@ -124,10 +126,12 @@ history_raw_cb (void *cls, } ho->cb (ho->cb_cls, response_code, + TALER_JSON_get_error_code (json), json); TALER_MERCHANT_history_cancel (ho); } + /** * Issue a /history request to the backend. * @@ -135,7 +139,7 @@ history_raw_cb (void *cls, * @param backend_uri base URL of the merchant backend * @param date only transactions younger than/equals to date will be returned * @param history_cb callback which will work the response gotten from the backend - * @param history_cb_cls closure to pass to history_cb + * @param history_cb_cls closure to pass to @a history_cb * @return handle for this operation, NULL upon errors */ struct TALER_MERCHANT_HistoryOperation * diff --git a/src/lib/merchant_api_pay.c b/src/lib/merchant_api_pay.c @@ -241,6 +241,7 @@ handle_pay_finished (void *cls, (unsigned int) response_code); ph->cb (ph->cb_cls, response_code, + TALER_JSON_get_error_code (json), json); TALER_MERCHANT_pay_cancel (ph); } diff --git a/src/lib/merchant_api_track_transaction.c b/src/lib/merchant_api_track_transaction.c @@ -155,6 +155,7 @@ parse_track_transaction_ok (struct TALER_MERCHANT_TrackTransactionHandle *tdo, } tdo->cb (tdo->cb_cls, MHD_HTTP_OK, + TALER_EC_NONE, json, num_transfers, transfers); @@ -218,6 +219,7 @@ handle_track_transaction_finished (void *cls, } tdo->cb (tdo->cb_cls, response_code, + TALER_JSON_get_error_code (json), json, 0, NULL); diff --git a/src/lib/merchant_api_track_transfer.c b/src/lib/merchant_api_track_transfer.c @@ -138,6 +138,7 @@ check_track_transfer_response_ok (struct TALER_MERCHANT_TrackTransferHandle *wdh } wdh->cb (wdh->cb_cls, MHD_HTTP_OK, + TALER_EC_NONE, &exchange_pub, json, &h_wire, @@ -198,6 +199,7 @@ handle_track_transfer_finished (void *cls, } tdo->cb (tdo->cb_cls, response_code, + TALER_JSON_get_error_code (json), NULL, json, NULL, diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c @@ -744,11 +744,13 @@ add_incoming_cb (void *cls, * * @param cls closure * @param http_status HTTP status returned by the merchant backend + * @param ec taler-specific error code * @param json actual body containing history */ -void +static void history_cb (void *cls, unsigned int http_status, + enum TALER_ErrorCode ec, const json_t *json) { struct InterpreterState *is = cls; @@ -962,6 +964,7 @@ reserve_status_cb (void *cls, * @param cls closure with the interpreter state * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request * 0 if the exchange's reply is bogus (fails to follow the protocol) + * @param ec taler-specific error code * @param sig signature over the coin, NULL on error * @param full_response full response from the exchange (for logging, in case of errors) */ @@ -1018,6 +1021,7 @@ reserve_withdraw_cb (void *cls, * @param cls closure * @param http_status HTTP response code, 200 indicates success; * 0 if the backend's reply is bogus (fails to follow the protocol) + * @param ec taler-specific error code * @param obj the full received JSON reply, or * error details if the request failed * @param contract completed contract, NULL on error @@ -1027,6 +1031,7 @@ reserve_withdraw_cb (void *cls, static void contract_cb (void *cls, unsigned int http_status, + enum TALER_ErrorCode ec, const json_t *obj, const json_t *contract, const struct TALER_MerchantSignatureP *sig, @@ -1063,12 +1068,14 @@ contract_cb (void *cls, * @param cls closure with the interpreter state * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful deposit; * 0 if the exchange's reply is bogus (fails to follow the protocol) + * @param ec taler-specific error code * @param obj the received JSON reply, should be kept as proof (and, in case of errors, * be forwarded to the customer) */ static void pay_cb (void *cls, unsigned int http_status, + enum TALER_ErrorCode ec, const json_t *obj) { struct InterpreterState *is = cls; @@ -1162,6 +1169,7 @@ maint_child_death (void *cls) * * @param cls closure for this function * @param http_status HTTP response code returned by the server + * @param ec taler-specific error code * @param sign_key exchange key used to sign @a json, or NULL * @param json original json reply (may include signatures, those have then been * validated already) @@ -1174,6 +1182,7 @@ maint_child_death (void *cls) static void track_transfer_cb (void *cls, unsigned int http_status, + enum TALER_ErrorCode ec, const struct TALER_ExchangePublicKeyP *sign_key, const json_t *json, const struct GNUNET_HashCode *h_wire, @@ -1270,6 +1279,7 @@ track_transfer_cb (void *cls, * * @param cls closure * @param http_status HTTP status code we got, 0 on exchange protocol violation + * @param ec taler-specific error code * @param json original json reply * @param num_transfers number of wire transfers involved in setting the transaction * @param transfers detailed list of transfers involved and their coins @@ -1277,6 +1287,7 @@ track_transfer_cb (void *cls, static void track_transaction_cb (void *cls, unsigned int http_status, + enum TALER_ErrorCode ec, const json_t *json, unsigned int num_transfers, const struct TALER_MERCHANT_TransactionWireTransfer *transfers)