summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/taler_merchant_service.h1133
-rw-r--r--src/include/taler_merchant_testing_lib.h400
-rw-r--r--src/lib/Makefile.am12
-rw-r--r--src/lib/merchant_api_delete_reserve.c239
-rw-r--r--src/lib/merchant_api_get_config.c8
-rw-r--r--src/lib/merchant_api_get_reserve.c322
-rw-r--r--src/lib/merchant_api_get_reserves.c271
-rw-r--r--src/lib/merchant_api_get_rewards.c288
-rw-r--r--src/lib/merchant_api_merchant_get_reward.c303
-rw-r--r--src/lib/merchant_api_post_reserves.c261
-rw-r--r--src/lib/merchant_api_reward_authorize.c372
-rw-r--r--src/lib/merchant_api_reward_pickup.c440
-rw-r--r--src/lib/merchant_api_reward_pickup2.c356
-rw-r--r--src/lib/merchant_api_wallet_get_reward.c222
-rw-r--r--src/merchant-tools/Makefile.am11
-rw-r--r--src/testing/Makefile.am12
-rw-r--r--src/testing/test_merchant_api.c221
-rwxr-xr-xsrc/testing/test_merchant_reserve_creation.sh233
-rw-r--r--src/testing/testing_api_cmd_delete_reserve.c228
-rw-r--r--src/testing/testing_api_cmd_get_reserve.c334
-rw-r--r--src/testing/testing_api_cmd_get_reserves.c285
-rw-r--r--src/testing/testing_api_cmd_get_rewards.c311
-rw-r--r--src/testing/testing_api_cmd_merchant_get_reward.c373
-rw-r--r--src/testing/testing_api_cmd_post_reserves.c278
-rw-r--r--src/testing/testing_api_cmd_reward_authorize.c485
-rw-r--r--src/testing/testing_api_cmd_reward_pickup.c415
-rw-r--r--src/testing/testing_api_cmd_wallet_get_reward.c259
27 files changed, 26 insertions, 8046 deletions
diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h
index b4dda615..78212d86 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2023 Taler Systems SA
+ Copyright (C) 2014-2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -34,7 +34,7 @@
/**
* Library version (in hex) for compatibility tests.
*/
-#define TALER_MERCHANT_SERVICE_VERSION 0x00090401
+#define TALER_MERCHANT_SERVICE_VERSION 0x00090402
/**
@@ -3948,1135 +3948,6 @@ TALER_MERCHANT_transfers_get_cancel (
struct TALER_MERCHANT_GetTransfersHandle *gth);
-/* ******************* /reserves *************** */
-
-
-/**
- * @brief Handle to a POST /reserves operation at a merchant's backend.
- */
-struct TALER_MERCHANT_PostReservesHandle;
-
-
-/**
- * Response to a POST /reserves request.
- */
-struct TALER_MERCHANT_PostReservesResponse
-{
- /**
- * HTTP response details.
- */
- struct TALER_MERCHANT_HttpResponse hr;
-
- /**
- * Details depending on HTTP status.
- */
- union
- {
- /**
- * Response on #MHD_HTTP_OK.
- */
- struct
- {
- /**
- * Public key of the created reserve.
- */
- struct TALER_ReservePublicKeyP reserve_pub;
-
- /**
- * Accounts to credit to for filling the reserve.
- * Array of accounts of the exchange.
- */
- const struct TALER_EXCHANGE_WireAccount *accounts;
-
- /**
- * Length of @e accounts array.
- */
- unsigned int accounts_len;
-
- } ok;
- } details;
-};
-
-
-/**
- * Callbacks of this type are used to work the result of submitting a
- * POST /reserves request to a merchant
- *
- * @param cls closure
- * @param prr response details
- */
-typedef void
-(*TALER_MERCHANT_PostReservesCallback) (
- void *cls,
- const struct TALER_MERCHANT_PostReservesResponse *prr);
-
-
-/**
- * Request backend to create a reserve.
- *
- * @param ctx execution context
- * @param backend_url base URL of the backend
- * @param initial_balance desired initial balance for the reserve
- * @param exchange_url what is the URL of the exchange where the reserve should be set up
- * @param wire_method desired wire method, for example "iban" or "x-taler-bank"
- * @param cb the callback to call when a reply for this request is available
- * @param cb_cls closure for @a cb
- * @return a handle for this request
- */
-struct TALER_MERCHANT_PostReservesHandle *
-TALER_MERCHANT_reserves_post (
- struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const struct TALER_Amount *initial_balance,
- const char *exchange_url,
- const char *wire_method,
- TALER_MERCHANT_PostReservesCallback cb,
- void *cb_cls);
-
-
-/**
- * Cancel a POST /reserves request. This function cannot be used
- * on a request handle if a response is already served for it.
- *
- * @param prh the operation to cancel
- */
-void
-TALER_MERCHANT_reserves_post_cancel (
- struct TALER_MERCHANT_PostReservesHandle *prh);
-
-
-/**
- * Handle for a GET /reserves operation.
- */
-struct TALER_MERCHANT_ReservesGetHandle;
-
-
-/**
- * Information about a reserve.
- */
-struct TALER_MERCHANT_ReserveSummary
-{
- /**
- * Public key of the reserve
- */
- struct TALER_ReservePublicKeyP reserve_pub;
-
- /**
- * Timestamp when it was established
- */
- struct GNUNET_TIME_Timestamp creation_time;
-
- /**
- * Timestamp when it expires
- */
- struct GNUNET_TIME_Timestamp expiration_time;
-
- /**
- * Initial amount as per reserve creation call
- */
- struct TALER_Amount merchant_initial_amount;
-
- /**
- * Initial amount as per exchange, 0 if exchange did
- * not confirm reserve creation yet.
- */
- struct TALER_Amount exchange_initial_amount;
-
- /**
- * Amount picked up so far.
- */
- struct TALER_Amount pickup_amount;
-
- /**
- * Amount approved for rewards that exceeds the pickup_amount.
- */
- struct TALER_Amount committed_amount;
-
- /**
- * Is this reserve active (false if it was deleted but not purged)
- */
- bool active;
-};
-
-
-/**
- * Response to a GET /reserves request.
- */
-struct TALER_MERCHANT_ReservesGetResponse
-{
- /**
- * HTTP response details
- */
- struct TALER_MERCHANT_HttpResponse hr;
-
- /**
- * Details depending on status.
- */
- union
- {
-
- /**
- * Details if status is #MHD_HTTP_OK.
- */
- struct
- {
- /**
- * length of the @e reserves array
- */
- unsigned int reserves_length;
-
- /**
- * array with details about the reserves
- */
- const struct TALER_MERCHANT_ReserveSummary *reserves;
-
- } ok;
-
- } details;
-};
-
-
-/**
- * Callback to process a GET /reserves request
- *
- * @param cls closure
- * @param rgr response details
- */
-typedef void
-(*TALER_MERCHANT_ReservesGetCallback) (
- void *cls,
- const struct TALER_MERCHANT_ReservesGetResponse *rgr);
-
-
-/**
- * Issue a GET /reserves request to the backend. Informs the backend
- * that a customer wants to pick up a reserves.
- *
- * @param ctx execution context
- * @param backend_url base URL of the merchant backend
- * @param after filter for reserves created after this date, use 0 for no filtering
- * @param active filter for reserves that are active
- * @param failures filter for reserves where we disagree about the balance with
- * the exchange
- * @param cb function to call with the result(s)
- * @param cb_cls closure for @a cb
- * @return handle for this operation, NULL upon errors
- */
-struct TALER_MERCHANT_ReservesGetHandle *
-TALER_MERCHANT_reserves_get (struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- struct GNUNET_TIME_Timestamp after,
- enum TALER_EXCHANGE_YesNoAll active,
- enum TALER_EXCHANGE_YesNoAll failures,
- TALER_MERCHANT_ReservesGetCallback cb,
- void *cb_cls);
-
-
-/**
- * Cancel a GET /reserves request.
- *
- * @param rgh handle to the request to be canceled
- */
-void
-TALER_MERCHANT_reserves_get_cancel (
- struct TALER_MERCHANT_ReservesGetHandle *rgh);
-
-
-/**
- * Handle for a request to obtain details on a specific
- * (rewardping) reserve.
- */
-struct TALER_MERCHANT_ReserveGetHandle;
-
-
-/**
- * Details about a reward granted by the merchant.
- */
-struct TALER_MERCHANT_RewardDetails
-{
- /**
- * Identifier for the reward.
- */
- struct TALER_RewardIdentifierP reward_id;
-
- /**
- * Total value of the reward (including fees).
- */
- struct TALER_Amount amount;
-
- /**
- * Human-readable reason for why the reward was granted.
- */
- const char *reason;
-
-};
-
-
-/**
- * Response to a GET /reserves/$ID request.
- */
-struct TALER_MERCHANT_ReserveGetResponse
-{
- /**
- * HTTP response.
- */
- struct TALER_MERCHANT_HttpResponse hr;
-
- /**
- * Details depending on HTTP status.
- */
- union
- {
-
- /**
- * Details on #MHD_HTTP_OK.
- */
- struct
- {
-
- /**
- * reserve summary for the reserve
- */
- struct TALER_MERCHANT_ReserveSummary rs;
-
- /**
- * URL of the exchange hosting the reserve, NULL if not @a active
- */
- const char *exchange_url;
-
- /**
- * Accounts to credit to for filling the reserve.
- * Array of accounts of the exchange. Empty if
- * already filled.
- */
- const struct TALER_EXCHANGE_WireAccount *accounts;
-
- /**
- * Length of @e accounts array.
- */
- unsigned int accounts_len;
-
- /**
- * Array with details about the rewards granted.
- */
- const struct TALER_MERCHANT_RewardDetails *rewards;
-
- /**
- * Length of the @e rewards array
- */
- unsigned int rewards_length;
-
- /**
- * Is this reserve active (false if it was deleted but not purged)
- */
- bool active;
-
- } ok;
-
- } details;
-
-};
-
-
-/**
- * Callback to process a GET /reserve/$RESERVE_PUB request
- *
- * @param cls closure
- * @param rgr response details
- */
-typedef void
-(*TALER_MERCHANT_ReserveGetCallback) (
- void *cls,
- const struct TALER_MERCHANT_ReserveGetResponse *rgr);
-
-
-/**
- * Issue a GET /reserve/$RESERVE_ID request to the backend. Queries the backend
- * about the status of a reserve.
- *
- * @param ctx execution context
- * @param backend_url base URL of the merchant backend
- * @param reserve_pub which reserve should be queried
- * @param fetch_rewards should we return details about the rewards issued from the reserve
- * @param cb function to call with the result(s)
- * @param cb_cls closure for @a cb
- * @return handle for this operation, NULL upon errors
- */
-struct TALER_MERCHANT_ReserveGetHandle *
-TALER_MERCHANT_reserve_get (struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- bool fetch_rewards,
- TALER_MERCHANT_ReserveGetCallback cb,
- void *cb_cls);
-
-
-/**
- * Cancel a GET /reserve/$RESERVE_ID request.
- *
- * @param rgh handle to the request to be canceled
- */
-void
-TALER_MERCHANT_reserve_get_cancel (
- struct TALER_MERCHANT_ReserveGetHandle *rgh);
-
-
-/**
- * Handle for a /reward-authorize operation.
- */
-struct TALER_MERCHANT_RewardAuthorizeHandle;
-
-
-/**
- * Response to a /reward-authorize request.
- */
-struct TALER_MERCHANT_RewardAuthorizeResponse
-{
- /**
- * HTTP response details
- */
- struct TALER_MERCHANT_HttpResponse hr;
-
- /**
- * Details depending on HTTP status.
- */
- union
- {
-
- /**
- * Details if status is #MHD_HTTP_OK.
- */
- struct
- {
-
- /**
- * which reward ID should be used to pickup the reward
- */
- struct TALER_RewardIdentifierP reward_id;
-
- /**
- * URI for the reward
- */
- const char *reward_uri;
-
- /**
- * when does the reward expire
- */
- struct GNUNET_TIME_Timestamp reward_expiration;
-
- } ok;
-
- } details;
-
-};
-
-
-/**
- * Callback for a /reserves/$RESERVE_PUB/reward-authorize request. Returns the
- * result of the operation.
- *
- * @param cls closure
- * @param tar response
- */
-typedef void
-(*TALER_MERCHANT_RewardAuthorizeCallback) (
- void *cls,
- const struct TALER_MERCHANT_RewardAuthorizeResponse *tar);
-
-
-/**
- * Issue a /reward-authorize request to the backend. Informs the backend
- * that a reward should be created.
- *
- * @param ctx execution context
- * @param backend_url base URL of the merchant backend
- * @param reserve_pub public key of the reserve
- * @param next_url where the browser should proceed after picking up the reward
- * @param amount amount to be handed out as a reward
- * @param justification which justification should be stored (human-readable reason for the reward)
- * @param authorize_cb callback which will work the response gotten from the backend
- * @param authorize_cb_cls closure to pass to @a authorize_cb
- * @return handle for this operation, NULL upon errors
- */
-struct TALER_MERCHANT_RewardAuthorizeHandle *
-TALER_MERCHANT_reward_authorize2 (
- struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const char *next_url,
- const struct TALER_Amount *amount,
- const char *justification,
- TALER_MERCHANT_RewardAuthorizeCallback authorize_cb,
- void *authorize_cb_cls);
-
-
-/**
- * Issue a POST /rewards request to the backend. Informs the backend that a reward
- * should be created. In contrast to #TALER_MERCHANT_reward_authorize2(), the
- * backend gets to pick the reserve with this API.
- *
- * @param ctx execution context
- * @param backend_url base URL of the merchant backend
- * @param next_url where the browser should proceed after picking up the reward
- * @param amount amount to be handed out as a reward
- * @param justification which justification should be stored (human-readable reason for the reward)
- * @param authorize_cb callback which will work the response gotten from the backend
- * @param authorize_cb_cls closure to pass to @a authorize_cb
- * @return handle for this operation, NULL upon errors
- */
-struct TALER_MERCHANT_RewardAuthorizeHandle *
-TALER_MERCHANT_reward_authorize (
- struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const char *next_url,
- const struct TALER_Amount *amount,
- const char *justification,
- TALER_MERCHANT_RewardAuthorizeCallback authorize_cb,
- void *authorize_cb_cls);
-
-
-/**
- * Cancel a pending /reward-authorize request
- *
- * @param ta handle from the operation to cancel
- */
-void
-TALER_MERCHANT_reward_authorize_cancel (
- struct TALER_MERCHANT_RewardAuthorizeHandle *ta);
-
-
-/**
- * Handle for a request to delete or purge a specific reserve.
- */
-struct TALER_MERCHANT_ReserveDeleteHandle;
-
-
-/**
- * Callback to process a DELETE /reserve/$RESERVE_PUB request
- *
- * @param cls closure
- * @param hr HTTP response details
- */
-typedef void
-(*TALER_MERCHANT_ReserveDeleteCallback) (
- void *cls,
- const struct TALER_MERCHANT_HttpResponse *hr);
-
-
-/**
- * Issue a DELETE /reserve/$RESERVE_ID request to the backend. Only
- * deletes the private key of the reserve, preserves rewardping data.
- *
- * @param ctx execution context
- * @param backend_url base URL of the merchant backend
- * @param reserve_pub which reserve should be queried
- * @param cb function to call with the result
- * @param cb_cls closure for @a cb
- * @return handle for this operation, NULL upon errors
- */
-struct TALER_MERCHANT_ReserveDeleteHandle *
-TALER_MERCHANT_reserve_delete (
- struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- TALER_MERCHANT_ReserveDeleteCallback cb,
- void *cb_cls);
-
-
-/**
- * Issue a DELETE /reserve/$RESERVE_ID request to the backend.
- * Purges the reserve, deleting all associated data. DANGEROUS.
- *
- * @param ctx execution context
- * @param backend_url base URL of the merchant backend
- * @param reserve_pub which reserve should be queried
- * @param cb function to call with the result
- * @param cb_cls closure for @a cb
- * @return handle for this operation, NULL upon errors
- */
-struct TALER_MERCHANT_ReserveDeleteHandle *
-TALER_MERCHANT_reserve_purge (
- struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- TALER_MERCHANT_ReserveDeleteCallback cb,
- void *cb_cls);
-
-
-/**
- * Cancel a DELETE (or purge) /reserve/$RESERVE_ID request.
- *
- * @param[in] rdh handle to the request to be canceled
- */
-void
-TALER_MERCHANT_reserve_delete_cancel (
- struct TALER_MERCHANT_ReserveDeleteHandle *rdh);
-
-
-/* ********************* /rewards ************************** */
-
-
-/**
- * Handle for a GET /rewards/$REWARD_ID (public variant) operation.
- */
-struct TALER_MERCHANT_RewardWalletGetHandle;
-
-/**
- * Response to a wallet's GET /rewards/$REWARD_ID request.
- */
-struct TALER_MERCHANT_RewardWalletGetResponse
-{
- /**
- * HTTP response details
- */
- struct TALER_MERCHANT_HttpResponse hr;
-
- /**
- * Details depending on the HTTP status code.
- */
- union
- {
-
- /**
- * Details for #MHD_HTTP_OK status.
- */
- struct
- {
-
- /**
- * when the reward will expire
- */
- struct GNUNET_TIME_Timestamp expiration;
-
- /**
- * exchange from which the coins should be withdrawn
- */
- const char *exchange_url;
-
- /**
- * URL where the wallet should navigate after withdrawing the reward.
- */
- const char *next_url;
-
- /**
- * total amount still available for the reward
- */
- struct TALER_Amount amount_remaining;
- } ok;
-
- } details;
-};
-
-
-/**
- * Callback to process a GET /rewards/$REWARD_ID request
- *
- * @param cls closure
- * @param wgr response details
- */
-typedef void
-(*TALER_MERCHANT_RewardWalletGetCallback) (
- void *cls,
- const struct TALER_MERCHANT_RewardWalletGetResponse *wgr);
-
-
-/**
- * Issue a GET /rewards/$REWARD_ID (public variant) request to the backend. Returns
- * information needed to pick up a reward.
- *
- * @param ctx execution context
- * @param backend_url base URL of the merchant backend
- * @param reward_id which reward should we query
- * @param cb function to call with the result
- * @param cb_cls closure for @a cb
- * @return handle for this operation, NULL upon errors
- */
-struct TALER_MERCHANT_RewardWalletGetHandle *
-TALER_MERCHANT_wallet_reward_get (
- struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const struct TALER_RewardIdentifierP *reward_id,
- TALER_MERCHANT_RewardWalletGetCallback cb,
- void *cb_cls);
-
-
-/**
- * Cancel a GET /rewards/$REWARD_ID request.
- *
- * @param[in] tgh handle to the request to be canceled
- */
-void
-TALER_MERCHANT_wallet_reward_get_cancel (
- struct TALER_MERCHANT_RewardWalletGetHandle *tgh);
-
-
-/**
- * Handle for a GET /private/rewards/$REWARD_ID (private variant) operation.
- */
-struct TALER_MERCHANT_RewardMerchantGetHandle;
-
-
-/**
- * Summary information for a reward pickup.
- */
-struct TALER_MERCHANT_PickupDetail
-{
- /**
- * Identifier of the pickup.
- */
- struct TALER_PickupIdentifierP pickup_id;
-
- /**
- * Number of planchets involved.
- */
- uint64_t num_planchets;
-
- /**
- * Total amount requested for this pickup.
- */
- struct TALER_Amount requested_amount;
-};
-
-
-/**
- * Details returned about a reward by the merchant.
- */
-struct TALER_MERCHANT_RewardStatusResponse
-{
- /**
- * HTTP status of the response.
- */
- struct TALER_MERCHANT_HttpResponse hr;
-
- /**
- * Details depending on the HTTP status.
- */
- union
- {
-
- /**
- * Details on #MHD_HTTP_OK.
- */
- struct
- {
-
- /**
- * Amount that was authorized under this reward
- */
- struct TALER_Amount total_authorized;
-
- /**
- * Amount that has been picked up
- */
- struct TALER_Amount total_picked_up;
-
- /**
- * The reason given for the reward
- */
- const char *reason;
-
- /**
- * Time when the reward will expire
- */
- struct GNUNET_TIME_Timestamp expiration;
-
- /**
- * reserve which is funding this reward
- */
- struct TALER_ReservePublicKeyP reserve_pub;
-
- /**
- * Length of the @e pickups array
- */
- unsigned int pickups_length;
-
- /**
- * array of pickup operations performed for this reward
- */
- struct TALER_MERCHANT_PickupDetail *pickups;
- } ok;
-
- } details;
-
-};
-
-
-/**
- * Callback to process a GET /private/rewards/$REWARD_ID request
- *
- * @param cls closure
- * @param tsr response details
- */
-typedef void
-(*TALER_MERCHANT_RewardMerchantGetCallback) (
- void *cls,
- const struct TALER_MERCHANT_RewardStatusResponse *tsr);
-
-
-/**
- * Issue a GET /private/rewards/$REWARD_ID (private variant) request to the backend.
- * Returns information needed to pick up a reward.
- *
- * @param ctx execution context
- * @param backend_url base URL of the merchant backend
- * @param reward_id which reward should we query
- * @param min_pick_up minimum amount picked up to notify about
- * @param lp_timeout how long to wait for @a min_pick_up to be exceeded
- * @param pickups whether to fetch associated pickups
- * @param cb function to call with the result
- * @param cb_cls closure for @a cb
- * @return handle for this operation, NULL upon errors
- */
-struct TALER_MERCHANT_RewardMerchantGetHandle *
-TALER_MERCHANT_merchant_reward_get (
- struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const struct TALER_RewardIdentifierP *reward_id,
- const struct TALER_Amount *min_pick_up,
- struct GNUNET_TIME_Relative lp_timeout,
- bool pickups,
- TALER_MERCHANT_RewardMerchantGetCallback cb,
- void *cb_cls);
-
-
-/**
- * Cancel a GET /private/rewards/$REWARD_ID request.
- *
- * @param[in] tgh handle to the request to be canceled
- */
-void
-TALER_MERCHANT_merchant_reward_get_cancel (
- struct TALER_MERCHANT_RewardMerchantGetHandle *tgh);
-
-
-/**
- * Handle for a GET /private/rewards request.
- */
-struct TALER_MERCHANT_RewardsGetHandle;
-
-
-/**
- * Database entry information of a reward.
- */
-struct TALER_MERCHANT_RewardEntry
-{
- /**
- * Row number of the reward in the database.
- */
- uint64_t row_id;
-
- /**
- * Identifier for the reward.
- */
- struct TALER_RewardIdentifierP reward_id;
-
- /**
- * Total value of the reward (including fees).
- */
- struct TALER_Amount reward_amount;
-
-};
-
-
-/**
- * Response to a GET /private/rewards request.
- */
-struct TALER_MERCHANT_RewardsGetResponse
-{
- /**
- * HTTP response details
- */
- struct TALER_MERCHANT_HttpResponse hr;
-
- /**
- * Details depending on status.
- */
- union
- {
-
- /**
- * Details if status is #MHD_HTTP_OK.
- */
- struct
- {
- /**
- * length of the @e rewards array
- */
- unsigned int rewards_length;
-
- /**
- * the array of rewards
- */
- const struct TALER_MERCHANT_RewardEntry *rewards;
-
- } ok;
-
- } details;
-};
-
-
-/**
- * Callback to process a GET /private/rewards request.
- *
- * @param cls closure
- * @param tgr response details
- */
-typedef void
-(*TALER_MERCHANT_RewardsGetCallback) (
- void *cls,
- const struct TALER_MERCHANT_RewardsGetResponse *tgr);
-
-
-/**
- * Issue a GET /private/rewards request to the backend.
- *
- * @param ctx execution context
- * @param backend_url base URL of the merchant backend
- * @param cb function to call with the result
- * @param cb_cls closure for @a cb
- * @return handle for this operation, NULL upon errors
- */
-struct TALER_MERCHANT_RewardsGetHandle *
-TALER_MERCHANT_rewards_get (
- struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- TALER_MERCHANT_RewardsGetCallback cb,
- void *cb_cls);
-
-
-/**
- * Issue a GET /private/rewards request with filters to the backend.
- *
- * @param ctx execution context
- * @param backend_url base URL of the merchant backend
- * @param expired yes for expired rewards, no for unexpired rewards, all for all rewards
- * @param limit number of results to return, negative for descending row id, positive for ascending
- * @param offset row id to start returning results from
- * @param cb function to call with the result
- * @param cb_cls closure for @a cb
- * @return handle for this operation, NULL upon errors
- */
-struct TALER_MERCHANT_RewardsGetHandle *
-TALER_MERCHANT_rewards_get2 (
- struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- enum TALER_EXCHANGE_YesNoAll expired,
- int64_t limit,
- uint64_t offset,
- TALER_MERCHANT_RewardsGetCallback cb,
- void *cb_cls);
-
-
-/**
- * Cancel a GET /private/rewards request.
- *
- * @param tgh the operation to cancel
- */
-void
-TALER_MERCHANT_rewards_get_cancel (struct TALER_MERCHANT_RewardsGetHandle *tgh);
-
-
-/**
- * Handle for a POST /rewards/$REWARD_ID/pickup operation.
- */
-struct TALER_MERCHANT_RewardPickupHandle;
-
-
-/**
- * Details about a pickup operation, as returned to the application.
- */
-struct TALER_MERCHANT_PickupDetails
-{
- /**
- * HTTP response data.
- */
- struct TALER_MERCHANT_HttpResponse hr;
-
- /**
- * Details about the response.
- */
- union
- {
- /**
- * Details if the status is #MHD_HTTP_OK.
- */
- struct
- {
-
- /**
- * Array of length @e num_sigs with details about each of the coins that
- * were picked up.
- */
- struct TALER_EXCHANGE_PrivateCoinDetails *pcds;
-
- /**
- * Length of the @e pcds array.
- */
- unsigned int num_sigs;
- } ok;
-
- } details;
-
-};
-
-
-/**
- * Callback for a POST /rewards/$REWARD_ID/pickup request. Returns the result of
- * the operation.
- *
- * @param cls closure
- * @param pd HTTP response details
- */
-typedef void
-(*TALER_MERCHANT_RewardPickupCallback) (
- void *cls,
- const struct TALER_MERCHANT_PickupDetails *pd);
-
-
-/**
- * Information per planchet.
- */
-struct TALER_MERCHANT_PlanchetData
-{
- /**
- * Planchet secrets.
- */
- struct TALER_PlanchetMasterSecretP ps;
-
- /**
- * Denomination key desired.
- */
- const struct TALER_EXCHANGE_DenomPublicKey *pk;
-
-};
-
-/**
- * Issue a POST /rewards/$REWARD_ID/pickup request to the backend. Informs the
- * backend that a customer wants to pick up a reward.
- *
- * @param ctx execution context
- * @param exchange_url base URL of the exchange
- * @param backend_url base URL of the merchant backend
- * @param reward_id unique identifier for the reward
- * @param num_planchets number of planchets provided in @a pds
- * @param planchets array of planchet secrets to be signed into existence for the reward
- * @param pickup_cb callback which will work the response gotten from the backend
- * @param pickup_cb_cls closure to pass to @a pickup_cb
- * @return handle for this operation, NULL upon errors
- */
-struct TALER_MERCHANT_RewardPickupHandle *
-TALER_MERCHANT_reward_pickup (
- struct GNUNET_CURL_Context *ctx,
- const char *exchange_url,
- const char *backend_url,
- const struct TALER_RewardIdentifierP *reward_id,
- unsigned int num_planchets,
- const struct TALER_MERCHANT_PlanchetData planchets[static num_planchets],
- TALER_MERCHANT_RewardPickupCallback pickup_cb,
- void *pickup_cb_cls);
-
-
-/**
- * Cancel a pending /rewards/$REWARD_ID/pickup request
- *
- * @param tph handle from the operation to cancel
- */
-void
-TALER_MERCHANT_reward_pickup_cancel (struct
- TALER_MERCHANT_RewardPickupHandle *tph);
-
-
-/**
- * Handle for a low-level /reward-pickup operation (without unblinding).
- */
-struct TALER_MERCHANT_RewardPickup2Handle;
-
-
-/**
- * Response for a POST /rewards/$REWARD_ID/pickup request.
- */
-struct TALER_MERCHANT_RewardPickup2Response
-{
- /**
- * HTTP response details
- */
- struct TALER_MERCHANT_HttpResponse hr;
-
- /**
- * Details depending on status.
- */
- union
- {
-
- /**
- * Details if status is #MHD_HTTP_OK.
- */
- struct
- {
-
- /**
- * length of the @a blind_sigs array
- */
- unsigned int num_blind_sigs;
-
- /**
- * array of blind signatures over the planchets
- */
- const struct TALER_BlindedDenominationSignature *blind_sigs;
-
- } ok;
-
- } details;
-};
-
-
-/**
- * Callback for a POST /rewards/$REWARD_ID/pickup request. Returns the result of
- * the operation. Note that the client MUST still do the unblinding.
- *
- * @param cls closure
- * @param tpr response details
- */
-typedef void
-(*TALER_MERCHANT_RewardPickup2Callback) (
- void *cls,
- const struct TALER_MERCHANT_RewardPickup2Response *tpr);
-
-
-/**
- * Issue a POST /rewards/$REWARD_ID/pickup request to the backend. Informs the
- * backend that a customer wants to pick up a reward.
- *
- * @param ctx execution context
- * @param backend_url base URL of the merchant backend
- * @param reward_id unique identifier for the reward
- * @param num_planchets number of planchets provided in @a planchets
- * @param planchets array of planchets to be signed into existence for the reward
- * @param pickup_cb callback which will work the response gotten from the backend
- * @param pickup_cb_cls closure to pass to @a pickup_cb
- * @return handle for this operation, NULL upon errors
- */
-struct TALER_MERCHANT_RewardPickup2Handle *
-TALER_MERCHANT_reward_pickup2 (
- struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const struct TALER_RewardIdentifierP *reward_id,
- unsigned int num_planchets,
- const struct TALER_PlanchetDetail planchets[static num_planchets],
- TALER_MERCHANT_RewardPickup2Callback pickup_cb,
- void *pickup_cb_cls);
-
-
-/**
- * Cancel a pending /reward-pickup request.
- *
- * @param[in] tp handle from the operation to cancel
- */
-void
-TALER_MERCHANT_reward_pickup2_cancel (
- struct TALER_MERCHANT_RewardPickup2Handle *tp);
-
-
/* ********************* /kyc ************************** */
/**
diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h
index 54d7f888..cb7e6042 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -581,7 +581,7 @@ TALER_TESTING_cmd_merchant_post_orders2 (
* GET /orders request.
* @param http_status expected HTTP response code.
* @param ... NULL-terminated list of labels (const char *) of
- * reserve (commands) we expect to be returned in the list
+ * order (commands) we expect to be returned in the list
* (assuming @a http_code is #MHD_HTTP_OK)
* @return the command.
*/
@@ -1071,403 +1071,6 @@ TALER_TESTING_cmd_merchant_delete_transfer (const char *label,
unsigned int http_status);
-/* ******************* /reserves *************** */
-
-
-/**
- * Define a "POST /reserves" CMD
- *
- * @param label command label.
- * @param merchant_url url to the murchant.
- * @param initial_balance initial amount in the reserve.
- * @param exchange_url url to the exchange
- * @param wire_method wire transfer method to use for this reserve
- * @param http_status expected HTTP response code.
- * @return the command.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_post_reserves (const char *label,
- const char *merchant_url,
- const char *initial_balance,
- const char *exchange_url,
- const char *wire_method,
- unsigned int http_status);
-
-
-/**
- * This commands does not query the backend at all,
- * but just makes up a fake reserve.
- *
- * @param label command label.
- * @return the command.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_post_reserves_fake (const char *label);
-
-
-/**
- * Define a "GET reserve" CMD.
- *
- * @param label command label.
- * @param merchant_url base URL of the merchant serving the request.
- * @param http_status expected HTTP response code.
- * @param reserve_reference reference to a "POST /reserves" that provides the
- * information we are expecting.
- * @return the command.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_get_reserve (const char *label,
- const char *merchant_url,
- unsigned int http_status,
- const char *reserve_reference);
-
-
-/**
- * Define a "GET reserve" CMD.
- *
- * @param label command label.
- * @param merchant_url base URL of the merchant serving the request.
- * @param http_status expected HTTP response code.
- * @param reserve_reference reference to a "POST /reserves" that provides the
- * information we are expecting.
- * @param ... NULL-terminated list of labels (const char *) of
- * reward (commands) we expect to be returned in the list
- * (assuming @a http_code is #MHD_HTTP_OK)
- * @return the command.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_get_reserve_with_rewards (const char *label,
- const char *merchant_url,
- unsigned int http_status,
- const char *
- reserve_reference,
- ...);
-
-
-/**
- * Define a "GET /reserves" CMD
- *
- * @param label command label.
- * @param merchant_url url to the merchant.
- * @param http_status expected HTTP response code.
- * @param ... NULL-terminated list of labels (const char *) of
- * reserve (commands) we expect to be returned in the list
- * (assuming @a http_code is #MHD_HTTP_OK)
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_get_reserves (const char *label,
- const char *merchant_url,
- unsigned int http_status,
- ...);
-
-
-/**
- * Define a "DELETE reserve" CMD.
- *
- * @param label command label.
- * @param merchant_url base URL of the merchant serving the
- * DELETE /reserves/$RESERVE_PUB request.
- * @param reserve_reference command label of a command providing a reserve
- * @param http_status expected HTTP response code.
- * @return the command.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_delete_reserve (const char *label,
- const char *merchant_url,
- const char *reserve_reference,
- unsigned int http_status);
-
-
-/**
- * Define a "PURGE reserve" CMD.
- *
- * @param label command label.
- * @param merchant_url base URL of the merchant serving the
- * DELETE /reserves/$RESERVE_PUB request.
- * @param reserve_reference command label of a command providing a reserve
- * @param http_status expected HTTP response code.
- * @return the command.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_purge_reserve (const char *label,
- const char *merchant_url,
- const char *reserve_reference,
- unsigned int http_status);
-
-
-/**
- * Define a get rewards CMD.
- *
- * @param label the command label
- * @param merchant_url base URL of the merchant which will
- * server the /reward-query request.
- * @param http_status expected HTTP response code for the
- * /reward-query request.
- * @param ... NULL-terminated list of labels (const char *) of
- * reward (commands) we expect to be returned in the list
- * (assuming @a http_code is #MHD_HTTP_OK)
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_get_rewards (const char *label,
- const char *merchant_url,
- unsigned int http_status,
- ...);
-
-
-/**
- * Define a get rewards CMD.
- *
- * @param label the command label
- * @param merchant_url base URL of the merchant which will
- * server the /reward-query request.
- * @param http_status expected HTTP response code for the
- * /reward-query request.
- * @param offset row to start querying the database from.
- * @param limit how many rows to return (with direction).
- * @param ... NULL-terminated list of labels (const char *) of
- * reward (commands) we expect to be returned in the list
- * (assuming @a http_code is #MHD_HTTP_OK)
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_get_rewards2 (const char *label,
- const char *merchant_url,
- uint64_t offset,
- int64_t limit,
- unsigned int http_status,
- ...);
-
-
-/**
- * Define a GET /private/rewards/$REWARD_ID CMD.
- *
- * @param label the command label
- * @param merchant_url base URL of the merchant which will
- * serve the request.
- * @param reward_reference reference to a command that created a reward.
- * @param http_status expected HTTP response code for the request.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_get_reward (const char *label,
- const char *merchant_url,
- const char *reward_reference,
- unsigned int http_status);
-
-
-/**
- * Define a GET /private/rewards/$REWARD_ID CMD.
- *
- * @param label the command label
- * @param merchant_url base URL of the merchant which will
- * serve the request.
- * @param reward_reference reference to a command that created a reward.
- * @param http_status expected HTTP response code for the request.
- * @param ... NULL-terminated list of labels (const char *) of
- * pickup (commands) we expect to be returned in the list
- * (assuming @a http_code is #MHD_HTTP_OK)
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_get_reward_with_pickups (const char *label,
- const char *merchant_url,
- const char *reward_reference,
- unsigned int http_status,
- ...);
-
-/**
- * Define a GET /rewards/$REWARD_ID CMD.
- *
- * @param label the command label
- * @param merchant_url base URL of the merchant which will
- * serve the request.
- * @param reward_reference reference to a command that created a reward.
- * @param http_status expected HTTP response code for the request.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_wallet_get_reward (const char *label,
- const char *merchant_url,
- const char *reward_reference,
- unsigned int http_status);
-
-
-/**
- * Define a GET /rewards/$REWARD_ID CMD.
- *
- * @param label the command label
- * @param merchant_url base URL of the merchant which will
- * serve the request.
- * @param reward_reference reference to a command that created a reward.
- * @param amount_remaining the balance remaining after pickups.
- * @param http_status expected HTTP response code for the request.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_wallet_get_reward2 (const char *label,
- const char *merchant_url,
- const char *reward_reference,
- const char *amount_remaining,
- unsigned int http_status);
-
-
-/**
- * Create a /reward-authorize CMD.
- *
- * @param label this command label
- * @param merchant_url the base URL of the merchant that will
- * serve the /reward-authorize request.
- * @param exchange_url the base URL of the exchange that owns
- * the reserve from which the reward is going to be gotten.
- * @param http_status the HTTP response code which is expected
- * for this operation.
- * @param justification human-readable justification for this
- * reward authorization.
- * @param amount the amount to authorize for rewardping.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_reward_authorize (const char *label,
- const char *merchant_url,
- const char *exchange_url,
- unsigned int http_status,
- const char *justification,
- const char *amount);
-
-
-/**
- * Create a /reward-authorize CMD.
- *
- * @param label this command label
- * @param merchant_url the base URL of the merchant that will
- * serve the /reward-authorize request.
- * @param exchange_url the base URL of the exchange that owns
- * the reserve from which the reward is going to be gotten.
- * @param reserve_reference reference to a command that created
- * a reserve.
- * @param http_status the HTTP response code which is expected
- * for this operation.
- * @param justification human-readable justification for this
- * reward authorization.
- * @param amount the amount to authorize for rewardping.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_reward_authorize_from_reserve (const char *label,
- const char *merchant_url,
- const char *exchange_url,
- const char *reserve_reference,
- unsigned int http_status,
- const char *justification,
- const char *amount);
-
-
-/**
- * Create a /reward-authorize CMD, specifying the Taler error code
- * that is expected to be returned by the backend.
- *
- * @param label this command label
- * @param merchant_url the base URL of the merchant that will
- * serve the /reward-authorize request.
- * @param exchange_url the base URL of the exchange that owns
- * the reserve from which the reward is going to be gotten.
- * @param http_status the HTTP response code which is expected
- * for this operation.
- * @param justification human-readable justification for this
- * reward authorization.
- * @param amount the amount to authorize for rewardping.
- * @param ec expected Taler-defined error code.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_reward_authorize_with_ec (const char *label,
- const char *merchant_url,
- const char *exchange_url,
- unsigned int http_status,
- const char *justification,
- const char *amount,
- enum TALER_ErrorCode ec);
-
-
-/**
- * Create a /reward-authorize CMD, specifying the Taler error code
- * that is expected to be returned by the backend.
- *
- * @param label this command label
- * @param merchant_url the base URL of the merchant that will
- * serve the /reward-authorize request.
- * @param exchange_url the base URL of the exchange that owns
- * the reserve from which the reward is going to be gotten.
- * @param reserve_reference reference to a command that created
- * a reserve.
- * @param http_status the HTTP response code which is expected
- * for this operation.
- * @param justification human-readable justification for this
- * reward authorization.
- * @param amount the amount to authorize for rewardping.
- * @param ec expected Taler-defined error code.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_reward_authorize_from_reserve_with_ec (
- const char *label,
- const char *merchant_url,
- const char *exchange_url,
- const char *reserve_reference,
- unsigned int http_status,
- const char *justification,
- const char *amount,
- enum TALER_ErrorCode ec);
-
-
-/**
- * This commands does not query the backend at all,
- * but just makes up a fake authorization id that will
- * be subsequently used by the "pick up" CMD in order
- * to test against such a case.
- *
- * @param label command label.
- * @return the command.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_reward_authorize_fake (const char *label);
-
-
-/**
- * Define a /reward-pickup CMD, equipped with the expected error
- * code.
- *
- * @param label the command label
- * @param merchant_url base URL of the backend which will serve
- * the /reward-pickup request.
- * @param http_status expected HTTP response code.
- * @param authorize_reference reference to a /reward-autorize CMD
- * that offers a reward id to pick up.
- * @param amounts array of string-defined amounts that specifies
- * which denominations will be accepted for rewardping.
- * @param ec expected Taler error code.
- * @return the command
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_reward_pickup_with_ec (const char *label,
- const char *merchant_url,
- unsigned int http_status,
- const char *authorize_reference,
- const char **amounts,
- enum TALER_ErrorCode ec);
-
-/**
- * Define a /reward-pickup CMD.
- *
- * @param label the command label
- * @param merchant_url base URL of the backend which will serve
- * the /reward-pickup request.
- * @param http_status expected HTTP response code.
- * @param authorize_reference reference to a /reward-autorize CMD
- * that offers a reward id to pick up.
- * @param amounts array of string-defined amounts that specifies
- * which denominations will be accepted for rewardping.
- * @return the command
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_reward_pickup (const char *label,
- const char *merchant_url,
- unsigned int http_status,
- const char *authorize_reference,
- const char **amounts);
-
-
/**
* Run a command to fetch the KYC status of a merchant.
*
@@ -1981,7 +1584,6 @@ TALER_TESTING_cmd_checkserver2 (const char *label,
// FIXME: rename: refund_entry->refund_detail
#define TALER_MERCHANT_TESTING_SIMPLE_TRAITS(op) \
op (claim_nonce, const struct GNUNET_CRYPTO_EddsaPublicKey) \
- op (reward_id, const struct TALER_RewardIdentifierP) \
op (pickup_id, const struct TALER_PickupIdentifierP) \
op (instance_name, const char) \
op (instance_id, const char) \
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 5a6cda80..d5a8376f 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -10,7 +10,7 @@ lib_LTLIBRARIES = \
libtalermerchant.la
libtalermerchant_la_LDFLAGS = \
- -version-info 4:0:0 \
+ -version-info 5:0:0 \
-no-undefined
libtalermerchant_la_SOURCES = \
@@ -21,7 +21,6 @@ libtalermerchant_la_SOURCES = \
merchant_api_delete_order.c \
merchant_api_delete_otp_device.c \
merchant_api_delete_product.c \
- merchant_api_delete_reserve.c \
merchant_api_delete_template.c \
merchant_api_delete_transfer.c \
merchant_api_delete_webhook.c \
@@ -36,9 +35,6 @@ libtalermerchant_la_SOURCES = \
merchant_api_get_otp_devices.c \
merchant_api_get_product.c \
merchant_api_get_products.c \
- merchant_api_get_reserve.c \
- merchant_api_get_reserves.c \
- merchant_api_get_rewards.c \
merchant_api_get_transfers.c \
merchant_api_get_template.c \
merchant_api_get_templates.c \
@@ -46,7 +42,6 @@ libtalermerchant_la_SOURCES = \
merchant_api_get_webhooks.c \
merchant_api_lock_product.c \
merchant_api_merchant_get_order.c \
- merchant_api_merchant_get_reward.c \
merchant_api_patch_account.c \
merchant_api_patch_instance.c \
merchant_api_patch_order_forget.c \
@@ -65,15 +60,10 @@ libtalermerchant_la_SOURCES = \
merchant_api_post_order_refund.c \
merchant_api_post_otp_devices.c \
merchant_api_post_products.c \
- merchant_api_post_reserves.c \
merchant_api_post_transfers.c \
merchant_api_post_templates.c \
merchant_api_post_using_templates.c \
merchant_api_post_webhooks.c \
- merchant_api_reward_authorize.c \
- merchant_api_reward_pickup.c \
- merchant_api_reward_pickup2.c \
- merchant_api_wallet_get_reward.c \
merchant_api_wallet_get_order.c \
merchant_api_wallet_post_order_refund.c
diff --git a/src/lib/merchant_api_delete_reserve.c b/src/lib/merchant_api_delete_reserve.c
deleted file mode 100644
index 8062d040..00000000
--- a/src/lib/merchant_api_delete_reserve.c
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2020 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING.LGPL. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file merchant_api_delete_reserve.c
- * @brief Implementation of the DELETE /reserves/$RESERVE_PUB request of the merchant's HTTP API
- * @author Jonathan Buchanan
- */
-#include "platform.h"
-#include <curl/curl.h>
-#include <jansson.h>
-#include <microhttpd.h> /* just for HTTP status codes */
-#include <gnunet/gnunet_util_lib.h>
-#include <gnunet/gnunet_curl_lib.h>
-#include "taler_merchant_service.h"
-#include "merchant_api_curl_defaults.h"
-#include <taler/taler_json_lib.h>
-#include <taler/taler_signatures.h>
-
-
-/**
- * Handle for a DELETE /reserves/$RESERVE_PUB operation.
- */
-struct TALER_MERCHANT_ReserveDeleteHandle
-{
-
- /**
- * The url for this request.
- */
- char *url;
-
- /**
- * Handle for the request.
- */
- struct GNUNET_CURL_Job *job;
-
- /**
- * Function to call with the result.
- */
- TALER_MERCHANT_ReserveDeleteCallback cb;
-
- /**
- * Closure for @a cb.
- */
- void *cb_cls;
-
- /**
- * Reference to the execution context.
- */
- struct GNUNET_CURL_Context *ctx;
-
-};
-
-
-/**
- * Function called when we're done processing the
- * HTTP DELETE /reserves/$RESERVE_PUB request.
- *
- * @param cls the `struct TALER_MERCHANT_InstanceDeleteHandle`
- * @param response_code HTTP response code, 0 on error
- * @param response response body, NULL if not in JSON
- */
-static void
-handle_delete_reserve_finished (void *cls,
- long response_code,
- const void *response)
-{
- struct TALER_MERCHANT_ReserveDeleteHandle *rdh = cls;
- const json_t *json = response;
- struct TALER_MERCHANT_HttpResponse hr = {
- .http_status = (unsigned int) response_code,
- .reply = json
- };
-
- rdh->job = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got /reserves/$ID response with status code %u\n",
- (unsigned int) response_code);
- switch (response_code)
- {
- case MHD_HTTP_NO_CONTENT:
- break;
- case MHD_HTTP_UNAUTHORIZED:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
- /* Nothing really to verify, merchant says we need to authenticate. */
- break;
- case MHD_HTTP_NOT_FOUND:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
- break;
- default:
- /* unexpected response code */
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d\n",
- (unsigned int) response_code,
- (int) hr.ec);
- break;
- }
- rdh->cb (rdh->cb_cls,
- &hr);
- TALER_MERCHANT_reserve_delete_cancel (rdh);
-}
-
-
-/**
- * Delete the private key of a reserve.
- *
- * @param ctx the context
- * @param backend_url HTTP base URL for the backend
- * @param reserve_pub which reserve should be deleted
- * @param purge purge instead of just deleting
- * @param cb function to call with the backend's return
- * @param cb_cls closure for @a config_cb
- * @return the instances handle; NULL upon error
- */
-static struct TALER_MERCHANT_ReserveDeleteHandle *
-reserve_delete (struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- bool purge,
- TALER_MERCHANT_ReserveDeleteCallback cb,
- void *cb_cls)
-{
- struct TALER_MERCHANT_ReserveDeleteHandle *rdh;
-
- rdh = GNUNET_new (struct TALER_MERCHANT_ReserveDeleteHandle);
- rdh->ctx = ctx;
- rdh->cb = cb;
- rdh->cb_cls = cb_cls;
- {
- char res_str[sizeof (*reserve_pub) * 2];
- char arg_str[sizeof (res_str) + 32];
- char *end;
-
- end = GNUNET_STRINGS_data_to_string (reserve_pub,
- sizeof (*reserve_pub),
- res_str,
- sizeof (res_str));
- *end = '\0';
- GNUNET_snprintf (arg_str,
- sizeof (arg_str),
- "private/reserves/%s",
- res_str);
- if (purge)
- rdh->url = TALER_url_join (backend_url,
- arg_str,
- "purge",
- "yes",
- NULL);
- else
- rdh->url = TALER_url_join (backend_url,
- arg_str,
- NULL);
- }
- if (NULL == rdh->url)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not construct request URL.\n");
- GNUNET_free (rdh);
- return NULL;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Requesting URL '%s'\n",
- rdh->url);
- {
- CURL *eh;
-
- eh = TALER_MERCHANT_curl_easy_get_ (rdh->url);
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_CUSTOMREQUEST,
- MHD_HTTP_METHOD_DELETE));
- rdh->job = GNUNET_CURL_job_add (ctx,
- eh,
- &handle_delete_reserve_finished,
- rdh);
- }
- return rdh;
-}
-
-
-struct TALER_MERCHANT_ReserveDeleteHandle *
-TALER_MERCHANT_reserve_delete (
- struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- TALER_MERCHANT_ReserveDeleteCallback cb,
- void *cb_cls)
-{
- return reserve_delete (ctx,
- backend_url,
- reserve_pub,
- false,
- cb,
- cb_cls);
-}
-
-
-struct TALER_MERCHANT_ReserveDeleteHandle *
-TALER_MERCHANT_reserve_purge (struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- TALER_MERCHANT_ReserveDeleteCallback cb,
- void *cb_cls)
-{
- return reserve_delete (ctx,
- backend_url,
- reserve_pub,
- true,
- cb,
- cb_cls);
-}
-
-
-void
-TALER_MERCHANT_reserve_delete_cancel (
- struct TALER_MERCHANT_ReserveDeleteHandle *rdh)
-{
- if (NULL != rdh->job)
- GNUNET_CURL_job_cancel (rdh->job);
- GNUNET_free (rdh->url);
- GNUNET_free (rdh);
-}
diff --git a/src/lib/merchant_api_get_config.c b/src/lib/merchant_api_get_config.c
index ed693b56..153bca28 100644
--- a/src/lib/merchant_api_get_config.c
+++ b/src/lib/merchant_api_get_config.c
@@ -34,12 +34,12 @@
* Which version of the Taler protocol is implemented
* by this library? Used to determine compatibility.
*/
-#define MERCHANT_PROTOCOL_CURRENT 6
+#define MERCHANT_PROTOCOL_CURRENT 8
/**
* How many configs are we backwards-compatible with?
*/
-#define MERCHANT_PROTOCOL_AGE 1
+#define MERCHANT_PROTOCOL_AGE 3
/**
@@ -117,7 +117,7 @@ handle_config_finished (void *cls,
GNUNET_JSON_spec_mark_optional (
GNUNET_JSON_spec_array_const ("exchanges",
&exchanges),
- NULL),
+ NULL),
GNUNET_JSON_spec_string ("currency",
&cr.details.ok.ci.currency),
TALER_JSON_spec_version ("version",
@@ -158,7 +158,7 @@ handle_config_finished (void *cls,
num_eci = json_object_size (exchanges);
eci = GNUNET_new_array (num_eci,
struct TALER_MERCHANT_ExchangeConfigInfo);
- for (unsigned int i=0;i<num_eci;i++)
+ for (unsigned int i = 0; i<num_eci; i++)
{
struct TALER_MERCHANT_ExchangeConfigInfo *ei = &eci[i];
const json_t *ej = json_array_get (exchanges,
diff --git a/src/lib/merchant_api_get_reserve.c b/src/lib/merchant_api_get_reserve.c
deleted file mode 100644
index 5fdd988e..00000000
--- a/src/lib/merchant_api_get_reserve.c
+++ /dev/null
@@ -1,322 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2023 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING.LGPL. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file merchant_api_get_reserve.c
- * @brief Implementation of the GET /reserve request of the merchant's HTTP API
- * @author Marcello Stanisci
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <curl/curl.h>
-#include <jansson.h>
-#include <microhttpd.h> /* just for HTTP status codes */
-#include <gnunet/gnunet_util_lib.h>
-#include <gnunet/gnunet_curl_lib.h>
-#include "taler_merchant_service.h"
-#include "merchant_api_common.h"
-#include "merchant_api_curl_defaults.h"
-#include <taler/taler_json_lib.h>
-#include <taler/taler_signatures.h>
-
-
-/**
- * @brief A Handle for tracking wire reserve.
- */
-struct TALER_MERCHANT_ReserveGetHandle
-{
-
- /**
- * The url for this request.
- */
- char *url;
-
- /**
- * Handle for the request.
- */
- struct GNUNET_CURL_Job *job;
-
- /**
- * Function to call with the result.
- */
- TALER_MERCHANT_ReserveGetCallback cb;
-
- /**
- * Closure for @a cb.
- */
- void *cb_cls;
-
- /**
- * Reference to the execution context.
- */
- struct GNUNET_CURL_Context *ctx;
-};
-
-
-/**
- * Function called when we're done processing the
- * HTTP GET /reserve request.
- *
- * @param cls the `struct TALER_MERCHANT_ReserveGetHandle`
- * @param response_code HTTP response code, 0 on error
- * @param response response body, NULL if not in JSON
- */
-static void
-handle_reserve_get_finished (void *cls,
- long response_code,
- const void *response)
-{
- struct TALER_MERCHANT_ReserveGetHandle *rgh = cls;
- const json_t *json = response;
- struct TALER_MERCHANT_ReserveGetResponse rgr = {
- .hr.http_status = (unsigned int) response_code,
- .hr.reply = json
- };
-
- rgh->job = NULL;
- switch (response_code)
- {
- case 0:
- rgr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- break;
- case MHD_HTTP_OK:
- {
- struct TALER_MERCHANT_ReserveSummary *rs
- = &rgr.details.ok.rs;
- const json_t *rewards = NULL;
- const json_t *accounts = NULL;
- unsigned int accounts_len = 0;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_timestamp ("creation_time",
- &rs->creation_time),
- GNUNET_JSON_spec_timestamp ("expiration_time",
- &rs->expiration_time),
- GNUNET_JSON_spec_bool ("active",
- &rgr.details.ok.active),
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_array_const ("rewards",
- &rewards),
- NULL),
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_array_const ("accounts",
- &accounts),
- NULL),
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_string (
- "exchange_url",
- &rgr.details.ok.exchange_url),
- NULL),
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_array_const ("accounts",
- &accounts),
- NULL),
- TALER_JSON_spec_amount_any ("merchant_initial_amount",
- &rs->merchant_initial_amount),
- TALER_JSON_spec_amount_any ("exchange_initial_amount",
- &rs->exchange_initial_amount),
- TALER_JSON_spec_amount_any ("pickup_amount",
- &rs->pickup_amount),
- TALER_JSON_spec_amount_any ("committed_amount",
- &rs->committed_amount),
- GNUNET_JSON_spec_end ()
- };
- struct TALER_EXCHANGE_WireAccount *was = NULL;
- struct TALER_MERCHANT_RewardDetails *tds = NULL;
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (json,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- rgr.hr.http_status = 0;
- rgr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- break;
- }
-
- if (NULL != accounts)
- {
- accounts_len = json_array_size (accounts);
- was = GNUNET_new_array (accounts_len,
- struct TALER_EXCHANGE_WireAccount);
- if (GNUNET_OK !=
- TALER_EXCHANGE_parse_accounts (NULL,
- accounts,
- accounts_len,
- was))
- {
- GNUNET_break_op (0);
- rgr.hr.http_status = 0;
- rgr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- }
- else
- {
- rgr.details.ok.accounts = was;
- rgr.details.ok.accounts_len = accounts_len;
- }
- } /* end 'have accounts' */
-
- if (NULL != rewards)
- {
- size_t tds_length = json_array_size (rewards);
- bool ok = true;
- json_t *reward;
- unsigned int i;
-
- tds = GNUNET_new_array (tds_length,
- struct TALER_MERCHANT_RewardDetails);
- json_array_foreach (rewards, i, reward) {
- struct TALER_MERCHANT_RewardDetails *td = &tds[i];
- struct GNUNET_JSON_Specification ispec[] = {
- GNUNET_JSON_spec_fixed_auto ("reward_id",
- &td->reward_id),
- TALER_JSON_spec_amount_any ("total_amount",
- &td->amount),
- GNUNET_JSON_spec_string ("reason",
- &td->reason),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (reward,
- ispec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- ok = false;
- break;
- }
- }
- if (! ok)
- {
- GNUNET_break_op (0);
- rgr.hr.http_status = 0;
- rgr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- }
- else
- {
- rgr.details.ok.rewards = tds;
- rgr.details.ok.rewards_length = tds_length;
- }
- } /* end 'have rewards' */
-
- rgh->cb (rgh->cb_cls,
- &rgr);
- if (NULL != accounts)
- {
- TALER_EXCHANGE_free_accounts (accounts_len,
- was);
- GNUNET_free (was);
- }
- GNUNET_free (tds);
- TALER_MERCHANT_reserve_get_cancel (rgh);
- return;
- }
- case MHD_HTTP_UNAUTHORIZED:
- rgr.hr.ec = TALER_JSON_get_error_code (json);
- rgr.hr.hint = TALER_JSON_get_error_hint (json);
- /* Nothing really to verify, merchant says we need to authenticate. */
- break;
- case MHD_HTTP_INTERNAL_SERVER_ERROR:
- /* Server had an internal issue; we should retry, but this API
- leaves this to the application */
- rgr.hr.ec = TALER_JSON_get_error_code (json);
- rgr.hr.hint = TALER_JSON_get_error_hint (json);
- break;
- default:
- /* unexpected response code */
- GNUNET_break_op (0);
- TALER_MERCHANT_parse_error_details_ (json,
- response_code,
- &rgr.hr);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d\n",
- (unsigned int) response_code,
- (int) rgr.hr.ec);
- break;
- }
- rgh->cb (rgh->cb_cls,
- &rgr);
- TALER_MERCHANT_reserve_get_cancel (rgh);
-}
-
-
-struct TALER_MERCHANT_ReserveGetHandle *
-TALER_MERCHANT_reserve_get (struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- bool fetch_rewards,
- TALER_MERCHANT_ReserveGetCallback cb,
- void *cb_cls)
-{
- struct TALER_MERCHANT_ReserveGetHandle *rgh;
- CURL *eh;
-
- rgh = GNUNET_new (struct TALER_MERCHANT_ReserveGetHandle);
- rgh->ctx = ctx;
- rgh->cb = cb;
- rgh->cb_cls = cb_cls;
- {
- char res_str[sizeof (*reserve_pub) * 2];
- char arg_str[sizeof (res_str) + 32];
- char *end;
-
- end = GNUNET_STRINGS_data_to_string (reserve_pub,
- sizeof (*reserve_pub),
- res_str,
- sizeof (res_str));
- *end = '\0';
- GNUNET_snprintf (arg_str,
- sizeof (arg_str),
- "private/reserves/%s",
- res_str);
- rgh->url = TALER_url_join (backend_url,
- arg_str,
- "rewards",
- fetch_rewards ? "yes" : "no",
- NULL);
- }
- if (NULL == rgh->url)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not construct request URL.\n");
- GNUNET_free (rgh);
- return NULL;
- }
- eh = TALER_MERCHANT_curl_easy_get_ (rgh->url);
- rgh->job = GNUNET_CURL_job_add (ctx,
- eh,
- &handle_reserve_get_finished,
- rgh);
- return rgh;
-}
-
-
-void
-TALER_MERCHANT_reserve_get_cancel (
- struct TALER_MERCHANT_ReserveGetHandle *rgh)
-{
- if (NULL != rgh->job)
- {
- GNUNET_CURL_job_cancel (rgh->job);
- rgh->job = NULL;
- }
- GNUNET_free (rgh->url);
- GNUNET_free (rgh);
-}
-
-
-/* end of merchant_api_get_reserve.c */
diff --git a/src/lib/merchant_api_get_reserves.c b/src/lib/merchant_api_get_reserves.c
deleted file mode 100644
index b825b0d2..00000000
--- a/src/lib/merchant_api_get_reserves.c
+++ /dev/null
@@ -1,271 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2023 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING.LGPL. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file merchant_api_get_reserves.c
- * @brief Implementation of the GET /reserves request of the merchant's HTTP API
- * @author Marcello Stanisci
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <curl/curl.h>
-#include <jansson.h>
-#include <microhttpd.h> /* just for HTTP status codes */
-#include <gnunet/gnunet_util_lib.h>
-#include <gnunet/gnunet_curl_lib.h>
-#include "taler_merchant_service.h"
-#include "merchant_api_common.h"
-#include "merchant_api_curl_defaults.h"
-#include <taler/taler_json_lib.h>
-#include <taler/taler_signatures.h>
-
-
-/**
- * @brief A Handle for tracking wire reserves.
- */
-struct TALER_MERCHANT_ReservesGetHandle
-{
-
- /**
- * The url for this request.
- */
- char *url;
-
- /**
- * Handle for the request.
- */
- struct GNUNET_CURL_Job *job;
-
- /**
- * Function to call with the result.
- */
- TALER_MERCHANT_ReservesGetCallback cb;
-
- /**
- * Closure for @a cb.
- */
- void *cb_cls;
-
- /**
- * Reference to the execution context.
- */
- struct GNUNET_CURL_Context *ctx;
-};
-
-
-/**
- * Function called when we're done processing the
- * HTTP GET /reserves request.
- *
- * @param cls the `struct TALER_MERCHANT_ReservesGetHandle`
- * @param response_code HTTP response code, 0 on error
- * @param response response body, NULL if not in JSON
- */
-static void
-handle_reserves_get_finished (void *cls,
- long response_code,
- const void *response)
-{
- struct TALER_MERCHANT_ReservesGetHandle *rgh = cls;
- const json_t *json = response;
- struct TALER_MERCHANT_ReservesGetResponse rgr = {
- .hr.http_status = (unsigned int) response_code,
- .hr.reply = json
- };
-
- rgh->job = NULL;
- switch (response_code)
- {
- case 0:
- rgr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- break;
- case MHD_HTTP_OK:
- {
- const json_t *reserves;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_array_const ("reserves",
- &reserves),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (json,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- rgr.hr.http_status = 0;
- rgr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- break;
- }
- {
- size_t rds_length;
- struct TALER_MERCHANT_ReserveSummary *rds;
- json_t *reserve;
- unsigned int i;
- bool ok;
-
- rds_length = json_array_size (reserves);
- rds = GNUNET_new_array (rds_length,
- struct TALER_MERCHANT_ReserveSummary);
- ok = true;
- json_array_foreach (reserves, i, reserve) {
- struct TALER_MERCHANT_ReserveSummary *rd = &rds[i];
- struct GNUNET_JSON_Specification ispec[] = {
- GNUNET_JSON_spec_fixed_auto ("reserve_pub",
- &rd->reserve_pub),
- GNUNET_JSON_spec_timestamp ("creation_time",
- &rd->creation_time),
- GNUNET_JSON_spec_timestamp ("expiration_time",
- &rd->expiration_time),
- TALER_JSON_spec_amount_any ("merchant_initial_amount",
- &rd->merchant_initial_amount),
- TALER_JSON_spec_amount_any ("exchange_initial_amount",
- &rd->exchange_initial_amount),
- TALER_JSON_spec_amount_any ("pickup_amount",
- &rd->pickup_amount),
- TALER_JSON_spec_amount_any ("committed_amount",
- &rd->committed_amount),
- GNUNET_JSON_spec_bool ("active",
- &rd->active),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (reserve,
- ispec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- ok = false;
- break;
- }
- }
-
- if (! ok)
- {
- GNUNET_break_op (0);
- GNUNET_free (rds);
- GNUNET_JSON_parse_free (spec);
- rgr.hr.http_status = 0;
- rgr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- break;
- }
- rgr.details.ok.reserves = rds;
- rgr.details.ok.reserves_length = rds_length;
- rgh->cb (rgh->cb_cls,
- &rgr);
- GNUNET_free (rds);
- GNUNET_JSON_parse_free (spec);
- TALER_MERCHANT_reserves_get_cancel (rgh);
- return;
- }
- }
- case MHD_HTTP_UNAUTHORIZED:
- rgr.hr.ec = TALER_JSON_get_error_code (json);
- rgr.hr.hint = TALER_JSON_get_error_hint (json);
- /* Nothing really to verify, merchant says we need to authenticate. */
- break;
- case MHD_HTTP_INTERNAL_SERVER_ERROR:
- /* Server had an internal issue; we should retry, but this API
- leaves this to the application */
- rgr.hr.ec = TALER_JSON_get_error_code (json);
- rgr.hr.hint = TALER_JSON_get_error_hint (json);
- break;
- default:
- /* unexpected response code */
- GNUNET_break_op (0);
- TALER_MERCHANT_parse_error_details_ (json,
- response_code,
- &rgr.hr);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d\n",
- (unsigned int) response_code,
- (int) rgr.hr.ec);
- break;
- }
- rgh->cb (rgh->cb_cls,
- &rgr);
- TALER_MERCHANT_reserves_get_cancel (rgh);
-}
-
-
-struct TALER_MERCHANT_ReservesGetHandle *
-TALER_MERCHANT_reserves_get (
- struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- struct GNUNET_TIME_Timestamp after,
- enum TALER_EXCHANGE_YesNoAll active,
- enum TALER_EXCHANGE_YesNoAll failures,
- TALER_MERCHANT_ReservesGetCallback cb,
- void *cb_cls)
-{
- struct TALER_MERCHANT_ReservesGetHandle *rgh;
- CURL *eh;
- const char *active_s = NULL;
- const char *failures_s = NULL;
- char *after_s;
-
- rgh = GNUNET_new (struct TALER_MERCHANT_ReservesGetHandle);
- rgh->ctx = ctx;
- rgh->cb = cb;
- rgh->cb_cls = cb_cls;
- active_s = TALER_yna_to_string (active);
- failures_s = TALER_yna_to_string (failures);
- after_s = GNUNET_strdup (GNUNET_TIME_timestamp2s (after));
- rgh->url = TALER_url_join (backend_url,
- "private/reserves",
- "active",
- active_s,
- "failures",
- failures_s,
- "after",
- GNUNET_TIME_absolute_is_zero (after.abs_time)
- ? NULL
- : after_s,
- NULL);
- GNUNET_free (after_s);
- if (NULL == rgh->url)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not construct request URL.\n");
- GNUNET_free (rgh);
- return NULL;
- }
- eh = TALER_MERCHANT_curl_easy_get_ (rgh->url);
- rgh->job = GNUNET_CURL_job_add (ctx,
- eh,
- &handle_reserves_get_finished,
- rgh);
- return rgh;
-}
-
-
-void
-TALER_MERCHANT_reserves_get_cancel (
- struct TALER_MERCHANT_ReservesGetHandle *rgh)
-{
- if (NULL != rgh->job)
- {
- GNUNET_CURL_job_cancel (rgh->job);
- rgh->job = NULL;
- }
- GNUNET_free (rgh->url);
- GNUNET_free (rgh);
-}
-
-
-/* end of merchant_api_get_reserves.c */
diff --git a/src/lib/merchant_api_get_rewards.c b/src/lib/merchant_api_get_rewards.c
deleted file mode 100644
index eebc53d8..00000000
--- a/src/lib/merchant_api_get_rewards.c
+++ /dev/null
@@ -1,288 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2020-2023 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING.LGPL. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file merchant_api_get_rewards.c
- * @brief Implementation of the GET /private/rewards request of the merchant's HTTP API
- * @author Jonathan Buchanan
- */
-#include "platform.h"
-#include <curl/curl.h>
-#include <jansson.h>
-#include <microhttpd.h> /* just for HTTP status codes */
-#include <gnunet/gnunet_util_lib.h>
-#include <gnunet/gnunet_curl_lib.h>
-#include "taler_merchant_service.h"
-#include "merchant_api_curl_defaults.h"
-#include <taler/taler_json_lib.h>
-#include <taler/taler_signatures.h>
-
-
-/**
- * Handle for a GET /private/rewards operation.
- */
-struct TALER_MERCHANT_RewardsGetHandle
-{
- /**
- * The url for this request.
- */
- char *url;
-
- /**
- * Handle for the request.
- */
- struct GNUNET_CURL_Job *job;
-
- /**
- * Function to call with the result.
- */
- TALER_MERCHANT_RewardsGetCallback cb;
-
- /**
- * Closure for @a cb.
- */
- void *cb_cls;
-
- /**
- * Reference to the execution context.
- */
- struct GNUNET_CURL_Context *ctx;
-
-};
-
-
-/**
- * Parse reward information from @a ia.
- *
- * @param ia JSON array (or NULL!) reward order data
- * @param[in] tgr response to complete
- * @param tgh operation handle
- * @return #GNUNET_OK on success
- */
-static enum GNUNET_GenericReturnValue
-parse_rewards (const json_t *ia,
- struct TALER_MERCHANT_RewardsGetResponse *tgr,
- struct TALER_MERCHANT_RewardsGetHandle *tgh)
-{
- unsigned int tes_len = json_array_size (ia);
- struct TALER_MERCHANT_RewardEntry tes[GNUNET_NZL (tes_len)];
- size_t index;
- json_t *value;
-
- json_array_foreach (ia, index, value) {
- struct TALER_MERCHANT_RewardEntry *ie = &tes[index];
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_uint64 ("row_id",
- &ie->row_id),
- GNUNET_JSON_spec_fixed_auto ("reward_id",
- &ie->reward_id),
- TALER_JSON_spec_amount_any ("reward_amount",
- &ie->reward_amount),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (value,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- }
- tgr->details.ok.rewards_length = tes_len;
- tgr->details.ok.rewards = tes;
- tgh->cb (tgh->cb_cls,
- tgr);
- tgh->cb = NULL; /* just to be sure */
- return GNUNET_OK;
-}
-
-
-/**
- * Function called when we're done processing the
- * HTTP GET /private/rewards request.
- *
- * @param cls the `struct TALER_MERCHANT_RewardsGetHandle`
- * @param response_code HTTP response code, 0 on error
- * @param response response body, NULL if not in JSON
- */
-static void
-handle_get_rewards_finished (void *cls,
- long response_code,
- const void *response)
-{
- struct TALER_MERCHANT_RewardsGetHandle *tgh = cls;
- const json_t *json = response;
- struct TALER_MERCHANT_RewardsGetResponse tgr = {
- .hr.http_status = (unsigned int) response_code,
- .hr.reply = json
- };
-
- tgh->job = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got /private/rewards response with status code %u\n",
- (unsigned int) response_code);
- switch (response_code)
- {
- case MHD_HTTP_OK:
- {
- const json_t *rewards;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_array_const ("rewards",
- &rewards),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (json,
- spec,
- NULL, NULL))
- {
- tgr.hr.http_status = 0;
- tgr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- break;
- }
- if (GNUNET_OK ==
- parse_rewards (rewards,
- &tgr,
- tgh))
- {
- TALER_MERCHANT_rewards_get_cancel (tgh);
- return;
- }
- tgr.hr.http_status = 0;
- tgr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- break;
- }
- case MHD_HTTP_UNAUTHORIZED:
- tgr.hr.ec = TALER_JSON_get_error_code (json);
- tgr.hr.hint = TALER_JSON_get_error_hint (json);
- /* Nothing really to verify, merchant says we need to authenticate. */
- break;
- default:
- /* unexpected response code */
- tgr.hr.ec = TALER_JSON_get_error_code (json);
- tgr.hr.hint = TALER_JSON_get_error_hint (json);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d\n",
- (unsigned int) response_code,
- (int) tgr.hr.ec);
- break;
- }
- tgh->cb (tgh->cb_cls,
- &tgr);
- TALER_MERCHANT_rewards_get_cancel (tgh);
-}
-
-
-struct TALER_MERCHANT_RewardsGetHandle *
-TALER_MERCHANT_rewards_get (
- struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- TALER_MERCHANT_RewardsGetCallback cb,
- void *cb_cls)
-{
- return TALER_MERCHANT_rewards_get2 (ctx,
- backend_url,
- TALER_EXCHANGE_YNA_NO,
- -20,
- UINT64_MAX,
- cb,
- cb_cls);
-}
-
-
-struct TALER_MERCHANT_RewardsGetHandle *
-TALER_MERCHANT_rewards_get2 (struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- enum TALER_EXCHANGE_YesNoAll expired,
- int64_t limit,
- uint64_t offset,
- TALER_MERCHANT_RewardsGetCallback cb,
- void *cb_cls)
-{
- struct TALER_MERCHANT_RewardsGetHandle *tgh;
- CURL *eh;
-
- GNUNET_assert (NULL != backend_url);
- if (0 == limit)
- {
- GNUNET_break (0);
- return NULL;
- }
- tgh = GNUNET_new (struct TALER_MERCHANT_RewardsGetHandle);
- tgh->ctx = ctx;
- tgh->cb = cb;
- tgh->cb_cls = cb_cls;
-
- /* build tgh->url with the various optional arguments */
- {
- char cbuf[30];
- char lbuf[30];
- bool have_offset;
-
- GNUNET_snprintf (lbuf,
- sizeof (lbuf),
- "%lld",
- (long long) limit);
-
- if (limit > 0)
- have_offset = (0 != offset);
- else
- have_offset = (UINT64_MAX != offset);
- GNUNET_snprintf (cbuf,
- sizeof (cbuf),
- "%llu",
- (unsigned long long) offset);
- tgh->url = TALER_url_join (backend_url,
- "private/rewards",
- "expired",
- (TALER_EXCHANGE_YNA_ALL != expired)
- ? TALER_yna_to_string (expired)
- : NULL,
- "offset", (have_offset) ? cbuf : NULL,
- "limit", (-20 != limit) ? lbuf : NULL,
- NULL);
- }
- if (NULL == tgh->url)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not construct request URL.\n");
- GNUNET_free (tgh);
- return NULL;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Requesting URL '%s'\n",
- tgh->url);
- eh = TALER_MERCHANT_curl_easy_get_ (tgh->url);
- tgh->job = GNUNET_CURL_job_add (ctx,
- eh,
- &handle_get_rewards_finished,
- tgh);
- return tgh;
-}
-
-
-void
-TALER_MERCHANT_rewards_get_cancel (
- struct TALER_MERCHANT_RewardsGetHandle *tgh)
-{
- if (NULL != tgh->job)
- GNUNET_CURL_job_cancel (tgh->job);
- GNUNET_free (tgh->url);
- GNUNET_free (tgh);
-}
diff --git a/src/lib/merchant_api_merchant_get_reward.c b/src/lib/merchant_api_merchant_get_reward.c
deleted file mode 100644
index a26c4243..00000000
--- a/src/lib/merchant_api_merchant_get_reward.c
+++ /dev/null
@@ -1,303 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2020 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING.LGPL. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file merchant_api_merchant_get_reward.c
- * @brief Implementation of the GET /private/rewards/$REWARD_ID request of the merchant's HTTP API
- * @author Jonathan Buchanan
- */
-#include "platform.h"
-#include <curl/curl.h>
-#include <jansson.h>
-#include <microhttpd.h> /* just for HTTP status codes */
-#include <gnunet/gnunet_util_lib.h>
-#include <gnunet/gnunet_curl_lib.h>
-#include "taler_merchant_service.h"
-#include "merchant_api_common.h"
-#include "merchant_api_curl_defaults.h"
-#include <taler/taler_json_lib.h>
-#include <taler/taler_signatures.h>
-
-
-struct TALER_MERCHANT_RewardMerchantGetHandle
-{
- /**
- * The url for this request.
- */
- char *url;
-
- /**
- * Handle for the request.
- */
- struct GNUNET_CURL_Job *job;
-
- /**
- * Function to call with the result.
- */
- TALER_MERCHANT_RewardMerchantGetCallback cb;
-
- /**
- * Closure for @a cb.
- */
- void *cb_cls;
-
- /**
- * Reference to the execution context.
- */
- struct GNUNET_CURL_Context *ctx;
-};
-
-
-static enum GNUNET_GenericReturnValue
-parse_pickups (const json_t *pa,
- struct TALER_MERCHANT_RewardStatusResponse *tsr,
- struct TALER_MERCHANT_RewardMerchantGetHandle *tgh)
-{
- unsigned int pa_len = json_array_size (pa);
- struct TALER_MERCHANT_PickupDetail pickups[pa_len];
- size_t index;
- json_t *value;
-
- json_array_foreach (pa, index, value)
- {
- struct TALER_MERCHANT_PickupDetail *pickup = &pickups[index];
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_fixed_auto ("pickup_id",
- &pickup->pickup_id),
- GNUNET_JSON_spec_uint64 ("num_planchets",
- &pickup->num_planchets),
- TALER_JSON_spec_amount_any ("requested_amount",
- &pickup->requested_amount),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (value,
- spec,
- NULL,
- NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- }
- tsr->details.ok.pickups_length = pa_len;
- tsr->details.ok.pickups = pickups;
- tgh->cb (tgh->cb_cls,
- tsr);
- return GNUNET_OK;
-}
-
-
-/**
- * Function called when we're done processing the
- * GET /private/rewards/$REWARD_ID request.
- *
- * @param cls the `struct TALER_MERCHANT_RewardMerchantGetHandle`
- * @param response_code HTTP response code, 0 on error
- * @param response response body, NULL if not in JSON
- */
-static void
-handle_merchant_reward_get_finished (void *cls,
- long response_code,
- const void *response)
-{
- struct TALER_MERCHANT_RewardMerchantGetHandle *tgh = cls;
- const json_t *json = response;
- struct TALER_MERCHANT_RewardStatusResponse tsr = {
- .hr.http_status = (unsigned int) response_code,
- .hr.reply = json
- };
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got /private/rewards/$REWARD_ID response with status code %u\n",
- (unsigned int) response_code);
- tgh->job = NULL;
- switch (response_code)
- {
- case MHD_HTTP_OK:
- {
- struct GNUNET_JSON_Specification spec[] = {
- TALER_JSON_spec_amount_any ("total_authorized",
- &tsr.details.ok.total_authorized),
- TALER_JSON_spec_amount_any ("total_picked_up",
- &tsr.details.ok.total_picked_up),
- GNUNET_JSON_spec_string ("reason",
- &tsr.details.ok.reason),
- GNUNET_JSON_spec_timestamp ("expiration",
- &tsr.details.ok.expiration),
- GNUNET_JSON_spec_fixed_auto ("reserve_pub",
- &tsr.details.ok.reserve_pub),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (json,
- spec,
- NULL, NULL))
- {
- tsr.hr.http_status = 0;
- tsr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- }
- else
- {
- json_t *pickups = json_object_get (json,
- "pickups");
- if (! json_is_array (pickups))
- {
- tgh->cb (tgh->cb_cls,
- &tsr);
- TALER_MERCHANT_merchant_reward_get_cancel (tgh);
- return;
- }
- if (GNUNET_OK ==
- parse_pickups (pickups,
- &tsr,
- tgh))
- {
- GNUNET_JSON_parse_free (spec);
- TALER_MERCHANT_merchant_reward_get_cancel (tgh);
- return;
- }
- tsr.hr.http_status = 0;
- tsr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- }
- GNUNET_JSON_parse_free (spec);
- break;
- }
- case MHD_HTTP_UNAUTHORIZED:
- tsr.hr.ec = TALER_JSON_get_error_code (json);
- tsr.hr.hint = TALER_JSON_get_error_hint (json);
- /* Nothing really to verify, merchant says we need to authenticate. */
- break;
- case MHD_HTTP_NOT_FOUND:
- /* legal, can happen if instance or reward reserve is unknown */
- tsr.hr.ec = TALER_JSON_get_error_code (json);
- tsr.hr.hint = TALER_JSON_get_error_hint (json);
- break;
- case MHD_HTTP_INTERNAL_SERVER_ERROR:
- /* Server had an internal issue; we should retry, but this API
- leaves this to the application */
- tsr.hr.ec = TALER_JSON_get_error_code (json);
- tsr.hr.hint = TALER_JSON_get_error_hint (json);
- break;
- default:
- /* unexpected response code */
- GNUNET_break_op (0);
- TALER_MERCHANT_parse_error_details_ (json,
- response_code,
- &tsr.hr);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d\n",
- (unsigned int) response_code,
- (int) tsr.hr.ec);
- break;
- }
- tgh->cb (tgh->cb_cls,
- &tsr);
- TALER_MERCHANT_merchant_reward_get_cancel (tgh);
-}
-
-
-struct TALER_MERCHANT_RewardMerchantGetHandle *
-TALER_MERCHANT_merchant_reward_get (struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const struct
- TALER_RewardIdentifierP *reward_id,
- const struct TALER_Amount *min_pick_up,
- struct GNUNET_TIME_Relative lp_timeout,
- bool pickups,
- TALER_MERCHANT_RewardMerchantGetCallback cb,
- void *cb_cls)
-{
- struct TALER_MERCHANT_RewardMerchantGetHandle *tgh;
- CURL *eh;
-
- GNUNET_assert (NULL != backend_url);
- tgh = GNUNET_new (struct TALER_MERCHANT_RewardMerchantGetHandle);
- tgh->ctx = ctx;
- tgh->cb = cb;
- tgh->cb_cls = cb_cls;
-
- {
- char res_str[sizeof (*reward_id) * 2];
- char arg_str[sizeof (res_str) + 48];
- char timeout_str[32];
- char *end;
-
- end = GNUNET_STRINGS_data_to_string (reward_id,
- sizeof (*reward_id),
- res_str,
- sizeof (res_str));
- *end = '\0';
- GNUNET_snprintf (arg_str,
- sizeof (arg_str),
- "private/rewards/%s",
- res_str);
- GNUNET_snprintf (timeout_str,
- sizeof (timeout_str),
- "%llu",
- ((unsigned long long)
- lp_timeout.rel_value_us
- / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us));
- tgh->url = TALER_url_join (backend_url,
- arg_str,
- "pickups",
- pickups
- ? "yes"
- : NULL,
- "min_amount",
- min_pick_up
- ? TALER_amount2s (min_pick_up)
- : NULL,
- "timeout_ms",
- GNUNET_TIME_relative_is_zero (lp_timeout)
- ? NULL
- : timeout_str,
- NULL);
- }
- if (NULL == tgh->url)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not construct request URL.\n");
- GNUNET_free (tgh);
- return NULL;
- }
-
- eh = TALER_MERCHANT_curl_easy_get_ (tgh->url);
- tgh->job = GNUNET_CURL_job_add (ctx,
- eh,
- &handle_merchant_reward_get_finished,
- tgh);
- return tgh;
-}
-
-
-void
-TALER_MERCHANT_merchant_reward_get_cancel (
- struct TALER_MERCHANT_RewardMerchantGetHandle *tgh)
-{
- if (NULL != tgh->job)
- {
- GNUNET_CURL_job_cancel (tgh->job);
- tgh->job = NULL;
- }
- GNUNET_free (tgh->url);
- GNUNET_free (tgh);
-}
-
-
-/* end of merchant_api_merchant_get_reward.c */
diff --git a/src/lib/merchant_api_post_reserves.c b/src/lib/merchant_api_post_reserves.c
deleted file mode 100644
index 8898d61e..00000000
--- a/src/lib/merchant_api_post_reserves.c
+++ /dev/null
@@ -1,261 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2023 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING.LGPL. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file merchant_api_post_reserves.c
- * @brief Implementation of the POST /reserves request of the merchant's HTTP API
- * @author Marcello Stanisci
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <curl/curl.h>
-#include <jansson.h>
-#include <microhttpd.h> /* just for HTTP status codes */
-#include <gnunet/gnunet_util_lib.h>
-#include "taler_merchant_service.h"
-#include "merchant_api_curl_defaults.h"
-#include "merchant_api_common.h"
-#include <taler/taler_curl_lib.h>
-#include <taler/taler_json_lib.h>
-
-
-/**
- * @brief A handle for POSTing reserve data.
- */
-struct TALER_MERCHANT_PostReservesHandle
-{
-
- /**
- * The url for this request.
- */
- char *url;
-
- /**
- * Handle for the request.
- */
- struct GNUNET_CURL_Job *job;
-
- /**
- * Function to call with the result.
- */
- TALER_MERCHANT_PostReservesCallback cb;
-
- /**
- * Closure for @a cb.
- */
- void *cb_cls;
-
- /**
- * Reference to the execution context.
- */
- struct GNUNET_CURL_Context *ctx;
-
- /**
- * Minor context that holds body and headers.
- */
- struct TALER_CURL_PostContext post_ctx;
-
-};
-
-
-/**
- * Function called when we're done processing the
- * HTTP POST /reserves request.
- *
- * @param cls the `struct TALER_MERCHANT_PostReservesHandle`
- * @param response_code HTTP response code, 0 on error
- * @param response response body, NULL if not in JSON
- */
-static void
-handle_post_reserves_finished (void *cls,
- long response_code,
- const void *response)
-{
- struct TALER_MERCHANT_PostReservesHandle *prh = cls;
- const json_t *json = response;
- struct TALER_MERCHANT_PostReservesResponse prr = {
- .hr.http_status = (unsigned int) response_code,
- .hr.reply = json
- };
-
- prh->job = NULL;
- switch (response_code)
- {
- case 0:
- prr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- break;
- case MHD_HTTP_OK:
- {
- const json_t *accounts;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_fixed_auto (
- "reserve_pub",
- &prr.details.ok.reserve_pub),
- GNUNET_JSON_spec_array_const (
- "accounts",
- &accounts),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (json,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- prr.hr.http_status = 0;
- prr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- break;
- }
-
- {
- unsigned int accounts_len = json_array_size (accounts);
- struct TALER_EXCHANGE_WireAccount was[GNUNET_NZL (accounts_len)];
-
- prr.details.ok.accounts = was;
- prr.details.ok.accounts_len = accounts_len;
- if (GNUNET_OK !=
- TALER_EXCHANGE_parse_accounts (NULL,
- accounts,
- accounts_len,
- was))
- {
- GNUNET_break_op (0);
- prr.hr.http_status = 0;
- prr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- }
- prh->cb (prh->cb_cls,
- &prr);
- TALER_EXCHANGE_free_accounts (accounts_len,
- was);
- GNUNET_JSON_parse_free (spec);
- TALER_MERCHANT_reserves_post_cancel (prh);
- return;
- }
- }
- case MHD_HTTP_ACCEPTED:
- break;
- case MHD_HTTP_UNAUTHORIZED:
- prr.hr.ec = TALER_JSON_get_error_code (json);
- prr.hr.hint = TALER_JSON_get_error_hint (json);
- /* Nothing really to verify, merchant says we need to authenticate. */
- break;
- case MHD_HTTP_NOT_FOUND:
- /* Nothing really to verify, this should never
- happen, we should pass the JSON reply to the application */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Did not find any data\n");
- prr.hr.ec = TALER_JSON_get_error_code (json);
- prr.hr.hint = TALER_JSON_get_error_hint (json);
- break;
- case MHD_HTTP_INTERNAL_SERVER_ERROR:
- /* Server had an internal issue; we should retry, but this API
- leaves this to the application */
- prr.hr.ec = TALER_JSON_get_error_code (json);
- prr.hr.hint = TALER_JSON_get_error_hint (json);
- break;
- default:
- /* unexpected response code */
- GNUNET_break_op (0);
- TALER_MERCHANT_parse_error_details_ (json,
- response_code,
- &prr.hr);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d\n",
- (unsigned int) response_code,
- (int) prr.hr.ec);
- break;
- }
- prh->cb (prh->cb_cls,
- &prr);
- TALER_MERCHANT_reserves_post_cancel (prh);
-}
-
-
-struct TALER_MERCHANT_PostReservesHandle *
-TALER_MERCHANT_reserves_post (
- struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const struct TALER_Amount *initial_balance,
- const char *exchange_url,
- const char *wire_method,
- TALER_MERCHANT_PostReservesCallback cb,
- void *cb_cls)
-{
- struct TALER_MERCHANT_PostReservesHandle *prh;
- CURL *eh;
- json_t *req;
-
- prh = GNUNET_new (struct TALER_MERCHANT_PostReservesHandle);
- prh->ctx = ctx;
- prh->cb = cb;
- prh->cb_cls = cb_cls;
- prh->url = TALER_url_join (backend_url,
- "private/reserves",
- NULL);
- if (NULL == prh->url)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not construct request URL.\n");
- GNUNET_free (prh);
- return NULL;
- }
- req = GNUNET_JSON_PACK (
- TALER_JSON_pack_amount ("initial_balance",
- initial_balance),
- GNUNET_JSON_pack_string ("wire_method",
- wire_method),
- GNUNET_JSON_pack_string ("exchange_url",
- exchange_url));
- eh = TALER_MERCHANT_curl_easy_get_ (prh->url);
- if (GNUNET_OK !=
- TALER_curl_easy_post (&prh->post_ctx,
- eh,
- req))
- {
- GNUNET_break (0);
- curl_easy_cleanup (eh);
- json_decref (req);
- GNUNET_free (prh->url);
- GNUNET_free (prh);
- return NULL;
- }
- json_decref (req);
- prh->job = GNUNET_CURL_job_add2 (ctx,
- eh,
- prh->post_ctx.headers,
- &handle_post_reserves_finished,
- prh);
- return prh;
-}
-
-
-void
-TALER_MERCHANT_reserves_post_cancel (
- struct TALER_MERCHANT_PostReservesHandle *prh)
-{
- if (NULL != prh->job)
- {
- GNUNET_CURL_job_cancel (prh->job);
- prh->job = NULL;
- }
- GNUNET_free (prh->url);
- TALER_curl_easy_post_finished (&prh->post_ctx);
- GNUNET_free (prh);
-}
-
-
-/* end of merchant_api_post_reserves.c */
diff --git a/src/lib/merchant_api_reward_authorize.c b/src/lib/merchant_api_reward_authorize.c
deleted file mode 100644
index c81b2eb2..00000000
--- a/src/lib/merchant_api_reward_authorize.c
+++ /dev/null
@@ -1,372 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2023 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING.LGPL. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file merchant_api_reward_authorize.c
- * @brief Implementation of the /reward-authorize request of the merchant's HTTP API
- * @author Marcello Stanisci
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <curl/curl.h>
-#include <jansson.h>
-#include <microhttpd.h> /* just for HTTP status codes */
-#include <gnunet/gnunet_util_lib.h>
-#include <gnunet/gnunet_curl_lib.h>
-#include "taler_merchant_service.h"
-#include "merchant_api_curl_defaults.h"
-#include "merchant_api_common.h"
-#include <taler/taler_json_lib.h>
-#include <taler/taler_signatures.h>
-#include <taler/taler_curl_lib.h>
-
-
-/**
- * @brief A handle for reward authorizations.
- */
-struct TALER_MERCHANT_RewardAuthorizeHandle
-{
-
- /**
- * The url for this request.
- */
- char *url;
-
- /**
- * Handle for the request.
- */
- struct GNUNET_CURL_Job *job;
-
- /**
- * Function to call with the result.
- */
- TALER_MERCHANT_RewardAuthorizeCallback cb;
-
- /**
- * Closure for @a cb.
- */
- void *cb_cls;
-
- /**
- * Reference to the execution context.
- */
- struct GNUNET_CURL_Context *ctx;
-
- /**
- * Minor context that holds body and headers.
- */
- struct TALER_CURL_PostContext post_ctx;
-};
-
-
-/**
- * We got a 200 response back from the exchange (or the merchant).
- * Now we need to parse the response and if it is well-formed,
- * call the callback (and set it to NULL afterwards).
- *
- * @param tao handle of the original authorization operation
- * @param json cryptographic proof returned by the exchange/merchant
- * @return #GNUNET_OK if response is valid
- */
-static enum GNUNET_GenericReturnValue
-check_ok (struct TALER_MERCHANT_RewardAuthorizeHandle *tao,
- const json_t *json)
-{
- const char *reward_status_url;
- struct TALER_MERCHANT_RewardAuthorizeResponse tar = {
- .hr.http_status = MHD_HTTP_OK,
- .hr.reply = json
- };
- struct GNUNET_JSON_Specification spec[] = {
- TALER_JSON_spec_web_url ("reward_status_url",
- &reward_status_url),
- GNUNET_JSON_spec_string ("taler_reward_uri",
- &tar.details.ok.reward_uri),
- GNUNET_JSON_spec_timestamp ("reward_expiration",
- &tar.details.ok.reward_expiration),
- GNUNET_JSON_spec_fixed_auto ("reward_id",
- &tar.details.ok.reward_id),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (json,
- spec,
- NULL, NULL))
- {
- char *log;
-
- GNUNET_break_op (0);
- log = json_dumps (json,
- 0);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "JSON %s\n",
- log);
- free (log);
- return GNUNET_SYSERR;
- }
- tao->cb (tao->cb_cls,
- &tar);
- tao->cb = NULL; /* do not call twice */
- GNUNET_JSON_parse_free (spec);
- return GNUNET_OK;
-}
-
-
-/**
- * Function called when we're done processing the
- * HTTP /reservers/$REWARD_ID/reward-authorize request.
- *
- * @param cls the `struct TALER_MERCHANT_RewardAuthorizeHandle`
- * @param response_code HTTP response code, 0 on error
- * @param response response body, NULL if not in JSON
- */
-static void
-handle_reward_authorize_finished (void *cls,
- long response_code,
- const void *response)
-{
- struct TALER_MERCHANT_RewardAuthorizeHandle *tao = cls;
- const json_t *json = response;
- struct TALER_MERCHANT_RewardAuthorizeResponse tar = {
- .hr.http_status = (unsigned int) response_code,
- .hr.reply = json
- };
-
- tao->job = NULL;
- switch (response_code)
- {
- case MHD_HTTP_OK:
- if (GNUNET_OK ==
- check_ok (tao,
- json))
- {
- TALER_MERCHANT_reward_authorize_cancel (tao);
- return;
- }
- GNUNET_break_op (0);
- tar.hr.http_status = 0;
- tar.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- break;
- case MHD_HTTP_UNAUTHORIZED:
- tar.hr.ec = TALER_JSON_get_error_code (json);
- tar.hr.hint = TALER_JSON_get_error_hint (json);
- /* Nothing really to verify, merchant says we need to authenticate. */
- break;
- case MHD_HTTP_NOT_FOUND:
- /* Well-defined status code, pass on to application! */
- tar.hr.ec = TALER_JSON_get_error_code (json);
- tar.hr.hint = TALER_JSON_get_error_hint (json);
- break;
- case MHD_HTTP_PRECONDITION_FAILED:
- /* Well-defined status code, pass on to application! */
- tar.hr.ec = TALER_JSON_get_error_code (json);
- tar.hr.hint = TALER_JSON_get_error_hint (json);
- break;
- case MHD_HTTP_INTERNAL_SERVER_ERROR:
- /* Server had an internal issue; we should retry, but this API
- leaves this to the application */
- tar.hr.ec = TALER_JSON_get_error_code (json);
- tar.hr.hint = TALER_JSON_get_error_hint (json);
- break;
- case MHD_HTTP_SERVICE_UNAVAILABLE:
- /* Server had an unclear (internal or external) issue; we should retry,
- but this API leaves this to the application */
- TALER_MERCHANT_parse_error_details_ (json,
- response_code,
- &tar.hr);
- break;
- default:
- /* unexpected response code */
- GNUNET_break_op (0);
- TALER_MERCHANT_parse_error_details_ (json,
- response_code,
- &tar.hr);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d\n",
- (unsigned int) response_code,
- (int) tar.hr.ec);
- break;
- }
- if (NULL != tao->cb)
- tao->cb (tao->cb_cls,
- &tar);
- TALER_MERCHANT_reward_authorize_cancel (tao);
-}
-
-
-struct TALER_MERCHANT_RewardAuthorizeHandle *
-TALER_MERCHANT_reward_authorize2 (
- struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const char *next_url,
- const struct TALER_Amount *amount,
- const char *justification,
- TALER_MERCHANT_RewardAuthorizeCallback authorize_cb,
- void *authorize_cb_cls)
-{
- struct TALER_MERCHANT_RewardAuthorizeHandle *tao;
- CURL *eh;
- json_t *te_obj;
-
- tao = GNUNET_new (struct TALER_MERCHANT_RewardAuthorizeHandle);
- tao->ctx = ctx;
- tao->cb = authorize_cb;
- tao->cb_cls = authorize_cb_cls;
-
- {
- char res_str[sizeof (*reserve_pub) * 2];
- char arg_str[sizeof (res_str) + 48];
- char *end;
-
- end = GNUNET_STRINGS_data_to_string (reserve_pub,
- sizeof (*reserve_pub),
- res_str,
- sizeof (res_str));
- *end = '\0';
- GNUNET_snprintf (arg_str,
- sizeof (arg_str),
- "private/reserves/%s/authorize-reward",
- res_str);
- tao->url = TALER_url_join (backend_url,
- arg_str,
- NULL);
- }
- if (NULL == tao->url)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not construct request URL.\n");
- GNUNET_free (tao);
- return NULL;
- }
- te_obj = GNUNET_JSON_PACK (
- TALER_JSON_pack_amount ("amount",
- amount),
- GNUNET_JSON_pack_string ("justification",
- justification),
- GNUNET_JSON_pack_string ("next_url",
- next_url));
- eh = curl_easy_init ();
- GNUNET_assert (NULL != eh);
- if (GNUNET_OK !=
- TALER_curl_easy_post (&tao->post_ctx,
- eh,
- te_obj))
- {
- GNUNET_break (0);
- curl_easy_cleanup (eh);
- json_decref (te_obj);
- GNUNET_free (tao->url);
- GNUNET_free (tao);
- return NULL;
- }
-
- json_decref (te_obj);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Requesting URL '%s'\n",
- tao->url);
- GNUNET_assert (CURLE_OK == curl_easy_setopt (eh,
- CURLOPT_URL,
- tao->url));
-
- tao->job = GNUNET_CURL_job_add2 (ctx,
- eh,
- tao->post_ctx.headers,
- &handle_reward_authorize_finished,
- tao);
- return tao;
-}
-
-
-struct TALER_MERCHANT_RewardAuthorizeHandle *
-TALER_MERCHANT_reward_authorize (struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const char *next_url,
- const struct TALER_Amount *amount,
- const char *justification,
- TALER_MERCHANT_RewardAuthorizeCallback
- authorize_cb,
- void *authorize_cb_cls)
-{
- struct TALER_MERCHANT_RewardAuthorizeHandle *tao;
- CURL *eh;
- json_t *te_obj;
-
- tao = GNUNET_new (struct TALER_MERCHANT_RewardAuthorizeHandle);
- tao->ctx = ctx;
- tao->cb = authorize_cb;
- tao->cb_cls = authorize_cb_cls;
-
- tao->url = TALER_url_join (backend_url,
- "private/rewards",
- NULL);
- if (NULL == tao->url)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not construct request URL.\n");
- GNUNET_free (tao);
- return NULL;
- }
- te_obj = GNUNET_JSON_PACK (
- TALER_JSON_pack_amount ("amount",
- amount),
- GNUNET_JSON_pack_string ("justification",
- justification),
- GNUNET_JSON_pack_string ("next_url",
- next_url));
- eh = TALER_MERCHANT_curl_easy_get_ (tao->url);
- if (GNUNET_OK !=
- TALER_curl_easy_post (&tao->post_ctx,
- eh,
- te_obj))
- {
- GNUNET_break (0);
- curl_easy_cleanup (eh);
- json_decref (te_obj);
- GNUNET_free (tao->url);
- GNUNET_free (tao);
- return NULL;
- }
- json_decref (te_obj);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Requesting URL '%s'\n",
- tao->url);
- tao->job = GNUNET_CURL_job_add2 (ctx,
- eh,
- tao->post_ctx.headers,
- &handle_reward_authorize_finished,
- tao);
- return tao;
-}
-
-
-void
-TALER_MERCHANT_reward_authorize_cancel (
- struct TALER_MERCHANT_RewardAuthorizeHandle *tao)
-{
- if (NULL != tao->job)
- {
- GNUNET_CURL_job_cancel (tao->job);
- tao->job = NULL;
- }
- TALER_curl_easy_post_finished (&tao->post_ctx);
- GNUNET_free (tao->url);
- GNUNET_free (tao);
-}
-
-
-/* end of merchant_api_reward_authorize.c */
diff --git a/src/lib/merchant_api_reward_pickup.c b/src/lib/merchant_api_reward_pickup.c
deleted file mode 100644
index 3111c3b0..00000000
--- a/src/lib/merchant_api_reward_pickup.c
+++ /dev/null
@@ -1,440 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING.LGPL. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file merchant_api_reward_pickup.c
- * @brief Implementation of the /reward-pickup request of the merchant's HTTP API
- * @author Marcello Stanisci
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <curl/curl.h>
-#include <jansson.h>
-#include <microhttpd.h> /* just for HTTP status codes */
-#include <gnunet/gnunet_util_lib.h>
-#include <gnunet/gnunet_curl_lib.h>
-#include "taler_merchant_service.h"
-#include <taler/taler_json_lib.h>
-#include <taler/taler_signatures.h>
-#include <taler/taler_curl_lib.h>
-
-
-/**
- * Data we keep per planchet.
- */
-struct PlanchetData
-{
- /**
- * Secrets of the planchet.
- */
- struct TALER_PlanchetMasterSecretP ps;
-
- /**
- * Denomination key we are withdrawing.
- */
- struct TALER_EXCHANGE_DenomPublicKey pk;
-
- /**
- * Hash of the public key of the coin we are signing.
- */
- struct TALER_CoinPubHashP c_hash;
-
- /**
- * Nonce used for @e csr request, if any.
- */
- union GNUNET_CRYPTO_BlindSessionNonce nonce;
-
- /**
- * Handle for a /csr request we may optionally need
- * to trigger.
- */
- struct TALER_EXCHANGE_CsRWithdrawHandle *csr;
-
- /**
- * Handle for the /reward-pickup operation we are part of.
- */
- struct TALER_MERCHANT_RewardPickupHandle *tp;
-
- /**
- * Offset of this entry in the array.
- */
- unsigned int off;
-};
-
-
-/**
- * Handle for a /reward-pickup operation.
- */
-struct TALER_MERCHANT_RewardPickupHandle
-{
-
- /**
- * Function to call with the result.
- */
- TALER_MERCHANT_RewardPickupCallback cb;
-
- /**
- * Closure for @a cb.
- */
- void *cb_cls;
-
- /**
- * Handle for the actual (internal) withdraw operation.
- */
- struct TALER_MERCHANT_RewardPickup2Handle *tpo2;
-
- /**
- * Array of length @e num_planchets.
- */
- struct PlanchetData *planchets;
-
- /**
- * Array of length @e num_planchets.
- */
- struct TALER_EXCHANGE_PrivateCoinDetails *pcds;
-
- /**
- * Context for making HTTP requests.
- */
- struct GNUNET_CURL_Context *ctx;
-
- /**
- * URL of the merchant backend.
- */
- char *backend_url;
-
- /**
- * ID of the reward we are picking up.
- */
- struct TALER_RewardIdentifierP reward_id;
-
- /**
- * Number of planchets/coins used for this operation.
- */
- unsigned int num_planchets;
-
- /**
- * Number of remaining active /csr-withdraw requests.
- */
- unsigned int csr_active;
-};
-
-
-/**
- * Fail the pickup operation @a tp, returning @a ec.
- * Also cancels @a tp.
- *
- * @param[in] tp operation to fail
- * @param ec reason for the failure
- */
-static void
-fail_pickup (struct TALER_MERCHANT_RewardPickupHandle *tp,
- enum TALER_ErrorCode ec)
-{
- struct TALER_MERCHANT_PickupDetails pd = {
- .hr.ec = ec
- };
-
- tp->cb (tp->cb_cls,
- &pd);
- TALER_MERCHANT_reward_pickup_cancel (tp);
-}
-
-
-/**
- * Callback for a /reward-pickup request. Returns the result of the operation.
- * Note that the client MUST still do the unblinding of the @a blind_sigs.
- *
- * @param cls closure, a `struct TALER_MERCHANT_RewardPickupHandle *`
- * @param tpr response details
- */
-static void
-pickup_done_cb (void *cls,
- const struct TALER_MERCHANT_RewardPickup2Response *tpr)
-{
- struct TALER_MERCHANT_RewardPickupHandle *tp = cls;
- struct TALER_MERCHANT_PickupDetails pd = {
- .hr = tpr->hr
- };
-
- tp->tpo2 = NULL;
- if (MHD_HTTP_OK != tpr->hr.http_status)
- {
- tp->cb (tp->cb_cls,
- &pd);
- TALER_MERCHANT_reward_pickup_cancel (tp);
- return;
- }
- {
- enum GNUNET_GenericReturnValue ok = GNUNET_OK;
-
- for (unsigned int i = 0; i<tpr->details.ok.num_blind_sigs; i++)
- {
- const struct TALER_BlindedDenominationSignature *blind_sig
- = &tpr->details.ok.blind_sigs[i];
- struct TALER_EXCHANGE_PrivateCoinDetails *pcd
- = &tp->pcds[i];
- struct TALER_FreshCoin fc;
-
- if (GNUNET_OK !=
- TALER_planchet_to_coin (&tp->planchets[i].pk.key,
- blind_sig,
- &pcd->bks,
- &pcd->coin_priv,
- NULL,
- &tp->planchets[i].c_hash,
- &pcd->exchange_vals,
- &fc))
- {
- GNUNET_break_op (0);
- ok = GNUNET_SYSERR;
- break;
- }
- pcd->sig = fc.sig;
- }
- if (GNUNET_OK != ok)
- {
- pd.hr.ec = TALER_EC_MERCHANT_REWARD_PICKUP_UNBLIND_FAILURE;
- }
- else
- {
- pd.details.ok.num_sigs = tpr->details.ok.num_blind_sigs;
- pd.details.ok.pcds = tp->pcds;
- }
- tp->cb (tp->cb_cls,
- &pd);
- }
- TALER_MERCHANT_reward_pickup_cancel (tp);
-}
-
-
-/**
- * We have obtained all of the exchange inputs. Continue the pickup.
- *
- * @param[in,out] tp operation to continue
- */
-static void
-pickup_post_csr (struct TALER_MERCHANT_RewardPickupHandle *tp)
-{
- struct TALER_PlanchetDetail details[tp->num_planchets];
-
- for (unsigned int i = 0; i<tp->num_planchets; i++)
- {
- const struct PlanchetData *pd = &tp->planchets[i];
- struct TALER_EXCHANGE_PrivateCoinDetails *pcd = &tp->pcds[i];
-
- TALER_planchet_setup_coin_priv (&pd->ps,
- &pcd->exchange_vals,
- &pcd->coin_priv);
- TALER_planchet_blinding_secret_create (&pd->ps,
- &pcd->exchange_vals,
- &pcd->bks);
- if (GNUNET_OK !=
- TALER_planchet_prepare (&pd->pk.key,
- &pcd->exchange_vals,
- &pcd->bks,
- &pd->nonce,
- &pcd->coin_priv,
- NULL,
- &tp->planchets[i].c_hash,
- &details[i]))
- {
- GNUNET_break (0);
- for (unsigned int j = 0; j<i; j++)
- TALER_planchet_detail_free (&details[j]);
- fail_pickup (tp,
- TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE);
- return;
- }
- }
- tp->tpo2 = TALER_MERCHANT_reward_pickup2 (tp->ctx,
- tp->backend_url,
- &tp->reward_id,
- tp->num_planchets,
- details,
- &pickup_done_cb,
- tp);
- for (unsigned int j = 0; j<tp->num_planchets; j++)
- TALER_planchet_detail_free (&details[j]);
- if (NULL == tp->tpo2)
- {
- GNUNET_break (0);
- fail_pickup (tp,
- TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE);
- return;
- }
-}
-
-
-/**
- * Callbacks of this type are used to serve the result of submitting a
- * CS R request to a exchange.
- *
- * @param cls a `struct TALER_MERCHANT_RewardPickupHandle`
- * @param csrr response details
- */
-static void
-csr_cb (void *cls,
- const struct TALER_EXCHANGE_CsRWithdrawResponse *csrr)
-{
- struct PlanchetData *pd = cls;
- struct TALER_MERCHANT_RewardPickupHandle *tp = pd->tp;
-
- pd->csr = NULL;
- tp->csr_active--;
- switch (csrr->hr.http_status)
- {
- case MHD_HTTP_OK:
- {
- struct TALER_EXCHANGE_PrivateCoinDetails *pcd = &tp->pcds[pd->off];
-
- TALER_denom_ewv_copy (&pcd->exchange_vals,
- &csrr->details.ok.alg_values);
- }
- if (0 != tp->csr_active)
- return;
- pickup_post_csr (tp);
- return;
- default:
- {
- struct TALER_MERCHANT_PickupDetails pd = {
- .hr.hint = "/csr-withdraw failed",
- .hr.exchange_http_status = csrr->hr.http_status
- };
-
- tp->cb (tp->cb_cls,
- &pd);
- TALER_MERCHANT_reward_pickup_cancel (tp);
- return;
- }
- }
-}
-
-
-struct TALER_MERCHANT_RewardPickupHandle *
-TALER_MERCHANT_reward_pickup (
- struct GNUNET_CURL_Context *ctx,
- const char *exchange_url,
- const char *backend_url,
- const struct TALER_RewardIdentifierP *reward_id,
- unsigned int num_planchets,
- const struct TALER_MERCHANT_PlanchetData pds[static num_planchets],
- TALER_MERCHANT_RewardPickupCallback pickup_cb,
- void *pickup_cb_cls)
-{
- struct TALER_MERCHANT_RewardPickupHandle *tp;
-
- if (0 == num_planchets)
- {
- GNUNET_break (0);
- return NULL;
- }
- tp = GNUNET_new (struct TALER_MERCHANT_RewardPickupHandle);
- tp->cb = pickup_cb;
- tp->cb_cls = pickup_cb_cls;
- tp->ctx = ctx;
- tp->backend_url = GNUNET_strdup (backend_url);
- tp->reward_id = *reward_id;
- tp->num_planchets = num_planchets;
- tp->planchets = GNUNET_new_array (num_planchets,
- struct PlanchetData);
- tp->pcds = GNUNET_new_array (num_planchets,
- struct TALER_EXCHANGE_PrivateCoinDetails);
- for (unsigned int i = 0; i<num_planchets; i++)
- {
- const struct TALER_MERCHANT_PlanchetData *mpd = &pds[i];
- const struct TALER_EXCHANGE_DenomPublicKey *pk = mpd->pk;
- struct TALER_EXCHANGE_PrivateCoinDetails *pcd = &tp->pcds[i];
- struct PlanchetData *pd = &tp->planchets[i];
-
- pd->off = i;
- pd->tp = tp;
- tp->planchets[i].ps = mpd->ps;
- tp->planchets[i].pk = *pds[i].pk;
- TALER_denom_pub_copy (&tp->planchets[i].pk.key,
- &pds[i].pk->key);
- switch (pk->key.bsign_pub_key->cipher)
- {
- case GNUNET_CRYPTO_BSA_RSA:
- pcd->exchange_vals = *TALER_denom_ewv_rsa_singleton ();
- break;
- case GNUNET_CRYPTO_BSA_CS:
- {
- TALER_cs_withdraw_nonce_derive (&pd->ps,
- &pd->nonce.cs_nonce);
- pd->csr = TALER_EXCHANGE_csr_withdraw (ctx,
- exchange_url,
- &pd->pk,
- &pd->nonce.cs_nonce,
- &csr_cb,
- pd);
- if (NULL == pd->csr)
- {
- GNUNET_break (0);
- TALER_MERCHANT_reward_pickup_cancel (tp);
- return NULL;
- }
- tp->csr_active++;
- break;
- }
- default:
- GNUNET_break (0);
- TALER_MERCHANT_reward_pickup_cancel (tp);
- return NULL;
- }
- }
- if (0 == tp->csr_active)
- {
- pickup_post_csr (tp);
- return tp;
- }
- return tp;
-}
-
-
-void
-TALER_MERCHANT_reward_pickup_cancel (
- struct TALER_MERCHANT_RewardPickupHandle *tp)
-{
- for (unsigned int i = 0; i<tp->num_planchets; i++)
- {
- struct TALER_EXCHANGE_PrivateCoinDetails *pcd = &tp->pcds[i];
- struct PlanchetData *pd = &tp->planchets[i];
-
- TALER_denom_sig_free (&pcd->sig);
- TALER_denom_ewv_free (&pcd->exchange_vals);
- TALER_denom_pub_free (&tp->planchets[i].pk.key);
- if (NULL != pd->csr)
- {
- TALER_EXCHANGE_csr_withdraw_cancel (pd->csr);
- pd->csr = NULL;
- }
- }
- GNUNET_array_grow (tp->planchets,
- tp->num_planchets,
- 0);
- if (NULL != tp->tpo2)
- {
- TALER_MERCHANT_reward_pickup2_cancel (tp->tpo2);
- tp->tpo2 = NULL;
- }
- GNUNET_free (tp->backend_url);
- GNUNET_free (tp->pcds);
- GNUNET_free (tp);
-}
-
-
-/* end of merchant_api_reward_pickup.c */
diff --git a/src/lib/merchant_api_reward_pickup2.c b/src/lib/merchant_api_reward_pickup2.c
deleted file mode 100644
index 45ebf266..00000000
--- a/src/lib/merchant_api_reward_pickup2.c
+++ /dev/null
@@ -1,356 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2023 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING.LGPL. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file merchant_api_reward_pickup2.c
- * @brief Implementation of the /reward-pickup request of the merchant's HTTP API
- * @author Marcello Stanisci
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <curl/curl.h>
-#include <jansson.h>
-#include <microhttpd.h> /* just for HTTP status codes */
-#include <gnunet/gnunet_util_lib.h>
-#include <gnunet/gnunet_curl_lib.h>
-#include "taler_merchant_service.h"
-#include "merchant_api_curl_defaults.h"
-#include "merchant_api_common.h"
-#include <taler/taler_json_lib.h>
-#include <taler/taler_signatures.h>
-#include <taler/taler_curl_lib.h>
-
-
-/**
- * @brief A handle for tracking transactions.
- */
-struct TALER_MERCHANT_RewardPickup2Handle
-{
-
- /**
- * The url for this request.
- */
- char *url;
-
- /**
- * Minor context that holds body and headers.
- */
- struct TALER_CURL_PostContext post_ctx;
-
- /**
- * Handle for the request.
- */
- struct GNUNET_CURL_Job *job;
-
- /**
- * Function to call with the result.
- */
- TALER_MERCHANT_RewardPickup2Callback cb;
-
- /**
- * Closure for @a cb.
- */
- void *cb_cls;
-
- /**
- * Reference to the execution context.
- */
- struct GNUNET_CURL_Context *ctx;
-
- /**
- * Expected number of planchets.
- */
- unsigned int num_planchets;
-};
-
-
-/**
- * We got a 200 response back from the exchange (or the merchant).
- * Now we need to parse the response and if it is well-formed,
- * call the callback (and set it to NULL afterwards).
- *
- * @param tpo handle of the original authorization operation
- * @param[in] tpr response to complete
- * @param json cryptographic proof returned by the exchange/merchant
- * @return #GNUNET_OK if response is valid
- */
-static enum GNUNET_GenericReturnValue
-check_ok (struct TALER_MERCHANT_RewardPickup2Handle *tpo,
- struct TALER_MERCHANT_RewardPickup2Response *tpr,
- const json_t *json)
-{
- const json_t *ja;
- unsigned int ja_len;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_array_const ("blind_sigs",
- &ja),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (json,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- ja_len = json_array_size (ja);
- if (ja_len != tpo->num_planchets)
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- {
- struct TALER_BlindedDenominationSignature mblind_sigs[GNUNET_NZL (ja_len)];
-
- for (unsigned int i = 0; i<ja_len; i++)
- {
- json_t *pj = json_array_get (ja,
- i);
- struct GNUNET_JSON_Specification ispec[] = {
- TALER_JSON_spec_blinded_denom_sig ("blind_sig",
- &mblind_sigs[i]),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (pj,
- ispec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- for (unsigned int j = 0; j<i; j++)
- TALER_blinded_denom_sig_free (&mblind_sigs[j]);
- return GNUNET_SYSERR;
- }
- }
- tpr->details.ok.num_blind_sigs = ja_len;
- tpr->details.ok.blind_sigs = mblind_sigs;
- tpo->cb (tpo->cb_cls,
- tpr);
- tpo->cb = NULL; /* do not call twice */
- for (unsigned int i = 0; i<ja_len; i++)
- TALER_blinded_denom_sig_free (&mblind_sigs[i]);
- }
- return GNUNET_OK;
-}
-
-
-/**
- * Function called when we're done processing the
- * HTTP /track/transaction request.
- *
- * @param cls the `struct TALER_MERCHANT_RewardPickupHandle`
- * @param response_code HTTP response code, 0 on error
- * @param response response body, NULL if not in JSON
- */
-static void
-handle_reward_pickup_finished (void *cls,
- long response_code,
- const void *response)
-{
- struct TALER_MERCHANT_RewardPickup2Handle *tpo = cls;
- const json_t *json = response;
- struct TALER_MERCHANT_RewardPickup2Response tpr = {
- .hr.http_status = (unsigned int) response_code,
- .hr.reply = json
- };
-
- tpo->job = NULL;
- switch (response_code)
- {
- case MHD_HTTP_OK:
- if (GNUNET_OK !=
- check_ok (tpo,
- &tpr,
- json))
- {
- GNUNET_break_op (0);
- tpr.hr.http_status = 0;
- tpr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- break;
- }
- break;
- case MHD_HTTP_BAD_REQUEST:
- /* Can happen if we pickup an amount that exceeds the reward... */
- tpr.hr.ec = TALER_JSON_get_error_code (json);
- tpr.hr.hint = TALER_JSON_get_error_hint (json);
- GNUNET_break (
- TALER_EC_MERCHANT_REWARD_PICKUP_AMOUNT_EXCEEDS_REWARD_REMAINING ==
- tpr.hr.ec);
- break;
- case MHD_HTTP_CONFLICT:
- /* legal, can happen if we pickup a reward twice... */
- tpr.hr.ec = TALER_JSON_get_error_code (json);
- tpr.hr.hint = TALER_JSON_get_error_hint (json);
- break;
- case MHD_HTTP_NOT_FOUND:
- /* legal, can happen if reward ID is unknown */
- tpr.hr.ec = TALER_JSON_get_error_code (json);
- tpr.hr.hint = TALER_JSON_get_error_hint (json);
- break;
- case MHD_HTTP_INTERNAL_SERVER_ERROR:
- /* Server had an internal issue; we should retry, but this API
- leaves this to the application */
- tpr.hr.ec = TALER_JSON_get_error_code (json);
- tpr.hr.hint = TALER_JSON_get_error_hint (json);
- break;
- default:
- /* unexpected response code */
- GNUNET_break_op (0);
- TALER_MERCHANT_parse_error_details_ (json,
- response_code,
- &tpr.hr);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d\n",
- (unsigned int) response_code,
- (int) tpr.hr.ec);
- break;
- }
- if (NULL != tpo->cb)
- {
- tpo->cb (tpo->cb_cls,
- &tpr);
- tpo->cb = NULL;
- }
- TALER_MERCHANT_reward_pickup2_cancel (tpo);
-}
-
-
-struct TALER_MERCHANT_RewardPickup2Handle *
-TALER_MERCHANT_reward_pickup2 (
- struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const struct TALER_RewardIdentifierP *reward_id,
- unsigned int num_planchets,
- const struct TALER_PlanchetDetail planchets[static num_planchets],
- TALER_MERCHANT_RewardPickup2Callback pickup_cb,
- void *pickup_cb_cls)
-{
- struct TALER_MERCHANT_RewardPickup2Handle *tpo;
- CURL *eh;
- json_t *pa;
- json_t *tp_obj;
-
- if (0 == num_planchets)
- {
- GNUNET_break (0);
- return NULL;
- }
- pa = json_array ();
- GNUNET_assert (NULL != pa);
- for (unsigned int i = 0; i<num_planchets; i++)
- {
- const struct TALER_PlanchetDetail *planchet = &planchets[i];
- json_t *p;
-
- p = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_data_auto ("denom_pub_hash",
- &planchet->denom_pub_hash),
- TALER_JSON_pack_blinded_planchet ("coin_ev",
- &planchet->blinded_planchet));
- if (0 !=
- json_array_append_new (pa,
- p))
- {
- GNUNET_break (0);
- json_decref (pa);
- return NULL;
- }
- }
- tp_obj = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_array_steal ("planchets",
- pa));
- tpo = GNUNET_new (struct TALER_MERCHANT_RewardPickup2Handle);
- tpo->num_planchets = num_planchets;
- tpo->ctx = ctx;
- tpo->cb = pickup_cb;
- tpo->cb_cls = pickup_cb_cls;
-
- {
- char reward_str[sizeof (*reward_id) * 2];
- char arg_str[sizeof (reward_str) + 32];
- char *end;
-
- end = GNUNET_STRINGS_data_to_string (reward_id,
- sizeof (*reward_id),
- reward_str,
- sizeof (reward_str));
- *end = '\0';
- GNUNET_snprintf (arg_str,
- sizeof (arg_str),
- "rewards/%s/pickup",
- reward_str);
- tpo->url = TALER_url_join (backend_url,
- arg_str,
- NULL);
- }
- if (NULL == tpo->url)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not construct request URL.\n");
- json_decref (tp_obj);
- GNUNET_free (tpo);
- return NULL;
- }
- eh = TALER_MERCHANT_curl_easy_get_ (tpo->url);
- if (GNUNET_OK !=
- TALER_curl_easy_post (&tpo->post_ctx,
- eh,
- tp_obj))
- {
- GNUNET_break (0);
- json_decref (tp_obj);
- curl_easy_cleanup (eh);
- GNUNET_free (tpo->url);
- GNUNET_free (tpo);
- return NULL;
- }
- json_decref (tp_obj);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Requesting URL '%s'\n",
- tpo->url);
- tpo->job = GNUNET_CURL_job_add2 (ctx,
- eh,
- tpo->post_ctx.headers,
- &handle_reward_pickup_finished,
- tpo);
- if (NULL == tpo->job)
- {
- TALER_MERCHANT_reward_pickup2_cancel (tpo);
- return NULL;
- }
- return tpo;
-}
-
-
-void
-TALER_MERCHANT_reward_pickup2_cancel (
- struct TALER_MERCHANT_RewardPickup2Handle *tpo)
-{
- if (NULL != tpo->job)
- {
- GNUNET_CURL_job_cancel (tpo->job);
- tpo->job = NULL;
- }
- TALER_curl_easy_post_finished (&tpo->post_ctx);
- GNUNET_free (tpo->url);
- GNUNET_free (tpo);
-}
-
-
-/* end of merchant_api_reward_pickup2.c */
diff --git a/src/lib/merchant_api_wallet_get_reward.c b/src/lib/merchant_api_wallet_get_reward.c
deleted file mode 100644
index 1f6f6176..00000000
--- a/src/lib/merchant_api_wallet_get_reward.c
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2018, 2020 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING.LGPL. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file merchant_api_wallet_get_reward.c
- * @brief Implementation of the GET /rewards/$REWARD_ID request of the merchant's HTTP API
- * @author Florian Dold
- */
-#include "platform.h"
-#include <curl/curl.h>
-#include <jansson.h>
-#include <microhttpd.h> /* just for HTTP status codes */
-#include <gnunet/gnunet_util_lib.h>
-#include <gnunet/gnunet_curl_lib.h>
-#include "taler_merchant_service.h"
-#include "merchant_api_curl_defaults.h"
-#include "merchant_api_common.h"
-#include <taler/taler_json_lib.h>
-#include <taler/taler_signatures.h>
-
-
-/**
- * @brief A handle for tracking /reward-get operations
- */
-struct TALER_MERCHANT_RewardWalletGetHandle
-{
- /**
- * The url for this request.
- */
- char *url;
-
- /**
- * Handle for the request.
- */
- struct GNUNET_CURL_Job *job;
-
- /**
- * Function to call with the result.
- */
- TALER_MERCHANT_RewardWalletGetCallback cb;
-
- /**
- * Closure for @a cb.
- */
- void *cb_cls;
-
- /**
- * Reference to the execution context.
- */
- struct GNUNET_CURL_Context *ctx;
-
-};
-
-
-/**
- * Function called when we're done processing the
- * HTTP /track/transaction request.
- *
- * @param cls the `struct TALER_MERCHANT_RewardGetHandle`
- * @param response_code HTTP response code, 0 on error
- * @param response response body, NULL if not in JSON
- */
-static void
-handle_wallet_reward_get_finished (void *cls,
- long response_code,
- const void *response)
-{
- struct TALER_MERCHANT_RewardWalletGetHandle *tgh = cls;
- const json_t *json = response;
- struct TALER_MERCHANT_RewardWalletGetResponse wgr = {
- .hr.http_status = (unsigned int) response_code,
- .hr.reply = json
- };
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got /reward/$REWARD_ID response with status code %u\n",
- (unsigned int) response_code);
-
- tgh->job = NULL;
- switch (response_code)
- {
- case MHD_HTTP_OK:
- {
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_timestamp ("expiration",
- &wgr.details.ok.expiration),
- TALER_JSON_spec_web_url ("exchange_url",
- &wgr.details.ok.exchange_url),
- /* Does not have to be a Web URL */
- GNUNET_JSON_spec_string ("next_url",
- &wgr.details.ok.next_url),
- TALER_JSON_spec_amount_any ("reward_amount",
- &wgr.details.ok.amount_remaining),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (json,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- wgr.hr.http_status = 0;
- wgr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- break;
- }
- tgh->cb (tgh->cb_cls,
- &wgr);
- TALER_MERCHANT_wallet_reward_get_cancel (tgh);
- return;
- }
- case MHD_HTTP_INTERNAL_SERVER_ERROR:
- /* Server had an internal issue; we should retry, but this API
- leaves this to the application */
- wgr.hr.ec = TALER_JSON_get_error_code (json);
- wgr.hr.hint = TALER_JSON_get_error_hint (json);
- break;
- case MHD_HTTP_NOT_FOUND:
- /* legal, can happen if instance or reward reserve is unknown */
- wgr.hr.ec = TALER_JSON_get_error_code (json);
- wgr.hr.hint = TALER_JSON_get_error_hint (json);
- break;
- default:
- /* unexpected response code */
- GNUNET_break_op (0);
- TALER_MERCHANT_parse_error_details_ (json,
- response_code,
- &wgr.hr);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d\n",
- (unsigned int) response_code,
- (int) wgr.hr.ec);
- break;
- }
- tgh->cb (tgh->cb_cls,
- &wgr);
- TALER_MERCHANT_wallet_reward_get_cancel (tgh);
-}
-
-
-struct TALER_MERCHANT_RewardWalletGetHandle *
-TALER_MERCHANT_wallet_reward_get (struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const struct
- TALER_RewardIdentifierP *reward_id,
- TALER_MERCHANT_RewardWalletGetCallback cb,
- void *cb_cls)
-{
- struct TALER_MERCHANT_RewardWalletGetHandle *tgh;
- CURL *eh;
-
- tgh = GNUNET_new (struct TALER_MERCHANT_RewardWalletGetHandle);
- tgh->ctx = ctx;
- tgh->cb = cb;
- tgh->cb_cls = cb_cls;
- {
- char res_str[sizeof (*reward_id) * 2];
- char arg_str[sizeof (res_str) + 48];
- char *end;
-
- end = GNUNET_STRINGS_data_to_string (reward_id,
- sizeof (*reward_id),
- res_str,
- sizeof (res_str));
- *end = '\0';
- GNUNET_snprintf (arg_str,
- sizeof (arg_str),
- "rewards/%s",
- res_str);
- tgh->url = TALER_url_join (backend_url,
- arg_str,
- NULL);
- }
-
- if (NULL == tgh->url)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not construct request URL.\n");
- GNUNET_free (tgh);
- return NULL;
- }
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Requesting URL '%s'\n",
- tgh->url);
- eh = TALER_MERCHANT_curl_easy_get_ (tgh->url);
- tgh->job = GNUNET_CURL_job_add (ctx,
- eh,
- &handle_wallet_reward_get_finished,
- tgh);
- return tgh;
-}
-
-
-void
-TALER_MERCHANT_wallet_reward_get_cancel (
- struct TALER_MERCHANT_RewardWalletGetHandle *tgh)
-{
- if (NULL != tgh->job)
- {
- GNUNET_CURL_job_cancel (tgh->job);
- tgh->job = NULL;
- }
- GNUNET_free (tgh->url);
- GNUNET_free (tgh);
-}
-
-
-/* end of merchant_api_wallet_get_reward.c */
diff --git a/src/merchant-tools/Makefile.am b/src/merchant-tools/Makefile.am
index 7c28e9ee..21ddb89a 100644
--- a/src/merchant-tools/Makefile.am
+++ b/src/merchant-tools/Makefile.am
@@ -8,7 +8,6 @@ endif
bin_PROGRAMS = \
taler-merchant-dbinit \
- taler-merchant-setup-reserve \
taler-merchant-passwd \
taler-merchant-benchmark
@@ -57,13 +56,3 @@ taler_merchant_passwd_LDADD = \
-ltalerpq \
-lgnunetutil \
$(XLIB)
-
-taler_merchant_setup_reserve_SOURCES = \
- taler-merchant-setup-reserve.c
-taler_merchant_setup_reserve_LDADD = \
- $(LIBGCRYPT_LIBS) \
- $(top_builddir)/src/lib/libtalermerchant.la \
- -ltalerutil \
- -lgnunetcurl \
- -lgnunetutil \
- $(XLIB)
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 8a0afc9b..e462be16 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -13,7 +13,6 @@ check_SCRIPTS = \
test_merchant_instance_creation.sh \
test_merchant_instance_response.sh \
test_merchant_instance_purge.sh \
- test_merchant_reserve_creation.sh \
test_merchant_product_creation.sh \
test_merchant_order_creation.sh \
test_merchant_transfer_tracking.sh \
@@ -25,7 +24,7 @@ lib_LTLIBRARIES = \
libtalermerchanttesting.la
libtalermerchanttesting_la_LDFLAGS = \
- -version-info 2:0:0 \
+ -version-info 3:0:0 \
-no-undefined
libtalermerchanttesting_la_SOURCES = \
@@ -40,9 +39,6 @@ libtalermerchanttesting_la_SOURCES = \
testing_api_cmd_get_otp_devices.c \
testing_api_cmd_get_product.c \
testing_api_cmd_get_products.c \
- testing_api_cmd_get_reserve.c \
- testing_api_cmd_get_reserves.c \
- testing_api_cmd_get_rewards.c \
testing_api_cmd_get_transfers.c \
testing_api_cmd_get_templates.c \
testing_api_cmd_get_template.c \
@@ -55,14 +51,12 @@ libtalermerchanttesting_la_SOURCES = \
testing_api_cmd_delete_product.c \
testing_api_cmd_delete_template.c \
testing_api_cmd_delete_webhook.c \
- testing_api_cmd_delete_reserve.c \
testing_api_cmd_delete_transfer.c \
testing_api_cmd_forget_order.c \
testing_api_cmd_kyc_get.c \
testing_api_cmd_lock_product.c \
testing_api_cmd_instance_auth.c \
testing_api_cmd_merchant_get_order.c \
- testing_api_cmd_merchant_get_reward.c \
testing_api_cmd_patch_instance.c \
testing_api_cmd_patch_otp_device.c \
testing_api_cmd_patch_product.c \
@@ -75,17 +69,13 @@ libtalermerchanttesting_la_SOURCES = \
testing_api_cmd_post_orders.c \
testing_api_cmd_post_otp_devices.c \
testing_api_cmd_post_products.c \
- testing_api_cmd_post_reserves.c \
testing_api_cmd_post_transfers.c \
testing_api_cmd_post_templates.c \
testing_api_cmd_post_using_templates.c \
testing_api_cmd_post_webhooks.c \
testing_api_cmd_refund_order.c \
- testing_api_cmd_reward_authorize.c \
- testing_api_cmd_reward_pickup.c \
testing_api_cmd_tme.c \
testing_api_cmd_wallet_get_order.c \
- testing_api_cmd_wallet_get_reward.c \
testing_api_cmd_wallet_post_orders_refund.c \
testing_api_cmd_webhook.c \
testing_api_cmd_testserver.c \
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index 2a51c29f..5610b987 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -66,10 +66,6 @@ static char *config_file;
*/
#define EXCHANGE_URL "http://localhost:8081/"
-static const char *pickup_amounts_1[] = {"EUR:5", NULL};
-
-static const char *pickup_amounts_2[] = {"EUR:0.01", NULL};
-
/**
* Payto URI of the customer (payer).
*/
@@ -216,11 +212,11 @@ run (void *cls,
"default",
MHD_HTTP_NO_CONTENT),
TALER_TESTING_cmd_merchant_post_account (
- "instance-create-default-account",
- merchant_url,
- PAYTO_I1,
- NULL, NULL,
- MHD_HTTP_OK),
+ "instance-create-default-account",
+ merchant_url,
+ PAYTO_I1,
+ NULL, NULL,
+ MHD_HTTP_OK),
TALER_TESTING_cmd_merchant_kyc_get ("instance-create-kyc-0",
merchant_url,
NULL,
@@ -937,11 +933,11 @@ run (void *cls,
"i1a",
MHD_HTTP_NO_CONTENT),
TALER_TESTING_cmd_merchant_post_account (
- "instance-create-i1a-account",
- merchant_url_i1a,
- PAYTO_I1,
- NULL, NULL,
- MHD_HTTP_OK),
+ "instance-create-i1a-account",
+ merchant_url_i1a,
+ PAYTO_I1,
+ NULL, NULL,
+ MHD_HTTP_OK),
TALER_TESTING_cmd_merchant_get_product ("get-nx-product-i1a-1",
merchant_url_i1a,
"nx-product",
@@ -1029,187 +1025,6 @@ run (void *cls,
TALER_TESTING_cmd_end ()
};
- struct TALER_TESTING_Command reward[] = {
- TALER_TESTING_cmd_merchant_post_reserves ("create-reserve-reward-1",
- merchant_url,
- "EUR:20.04",
- EXCHANGE_URL,
- "x-taler-bank",
- MHD_HTTP_OK),
- TALER_TESTING_cmd_admin_add_incoming_with_ref (
- "create-reserve-reward-1-exch",
- "EUR:20.04",
- &cred.ba,
- payer_payto,
- "create-reserve-reward-1",
- MHD_HTTP_OK),
- /* We need to wait until the merchant re-tries fetching the
- reserve from the exchange. */
- cmd_exec_wirewatch ("wirewatch-3"),
- TALER_TESTING_cmd_sleep ("reward-sleep", 3),
- TALER_TESTING_cmd_reward_authorize ("authorize-reward-1",
- merchant_url,
- EXCHANGE_URL,
- MHD_HTTP_OK,
- "reward 1",
- "EUR:5.01"),
- TALER_TESTING_cmd_reward_authorize_from_reserve ("authorize-reward-2",
- merchant_url,
- EXCHANGE_URL,
- "create-reserve-reward-1-exch",
- MHD_HTTP_OK,
- "reward 2",
- "EUR:5.01"),
- TALER_TESTING_cmd_wallet_get_reward ("get-reward-1",
- merchant_url,
- "authorize-reward-1",
- MHD_HTTP_OK),
- TALER_TESTING_cmd_merchant_get_reward ("merchant-get-reward-1",
- merchant_url,
- "authorize-reward-1",
- MHD_HTTP_OK),
- TALER_TESTING_cmd_get_rewards ("get-rewards-1",
- merchant_url,
- MHD_HTTP_OK,
- "authorize-reward-2",
- "authorize-reward-1",
- NULL),
- TALER_TESTING_cmd_get_rewards2 ("get-rewards-1-asc",
- merchant_url,
- 0,
- 20,
- MHD_HTTP_OK,
- "authorize-reward-1",
- "authorize-reward-2",
- NULL),
- TALER_TESTING_cmd_get_rewards2 ("get-rewards-1-asc-offset",
- merchant_url,
- 1,
- 20,
- MHD_HTTP_OK,
- "authorize-reward-2",
- NULL),
- TALER_TESTING_cmd_merchant_get_reserves ("get-reserves-1",
- merchant_url,
- MHD_HTTP_OK,
- "create-reserve-reward-1-exch",
- NULL),
- TALER_TESTING_cmd_merchant_get_reserve ("get-reserve-1",
- merchant_url,
- MHD_HTTP_OK,
- "create-reserve-reward-1-exch"),
- TALER_TESTING_cmd_merchant_get_reserve_with_rewards ("get-reserve-2",
- merchant_url,
- MHD_HTTP_OK,
- "create-reserve-reward-1-exch",
- "authorize-reward-1",
- "authorize-reward-2",
- NULL),
- TALER_TESTING_cmd_reward_pickup ("pickup-reward-1",
- merchant_url,
- MHD_HTTP_OK,
- "authorize-reward-1",
- pickup_amounts_1),
- TALER_TESTING_cmd_wallet_get_reward2 ("query-reward-2",
- merchant_url,
- "authorize-reward-1",
- "EUR:0.01",
- MHD_HTTP_OK),
- TALER_TESTING_cmd_reward_pickup ("pickup-reward-2",
- merchant_url,
- MHD_HTTP_OK,
- "authorize-reward-2",
- pickup_amounts_1),
-
- TALER_TESTING_cmd_reward_pickup_with_ec ("pickup-reward-3-too-much",
- merchant_url,
- MHD_HTTP_BAD_REQUEST,
- "authorize-reward-1",
- pickup_amounts_1,
- TALER_EC_MERCHANT_REWARD_PICKUP_AMOUNT_EXCEEDS_REWARD_REMAINING),
-
- TALER_TESTING_cmd_reward_pickup ("pickup-reward-4",
- merchant_url,
- MHD_HTTP_OK,
- "authorize-reward-1",
- pickup_amounts_2),
- TALER_TESTING_cmd_merchant_get_reward_with_pickups ("merchant-get-reward-2",
- merchant_url,
- "authorize-reward-1",
- MHD_HTTP_OK,
- "pickup-reward-1",
- "pickup-reward-4",
- NULL),
-
- /* This command tests the authorization of reward
- * against a reserve that does not exist. This is
- * implemented by passing a "reward instance" that
- * specifies a reserve key that was never used to
- * actually create a reserve. */
- TALER_TESTING_cmd_merchant_post_reserves_fake (
- "create-reserve-reward-2-fake"),
- TALER_TESTING_cmd_reward_authorize_from_reserve_with_ec (
- "authorize-reward-null",
- merchant_url,
- EXCHANGE_URL,
- "create-reserve-reward-2-fake",
- MHD_HTTP_NOT_FOUND,
- "reward 3",
- "EUR:5.01",
- TALER_EC_MERCHANT_PRIVATE_POST_REWARD_AUTHORIZE_RESERVE_NOT_FOUND),
-
- /* Test reserve with insufficient funds */
- TALER_TESTING_cmd_merchant_post_reserves ("create-reserve-reward-2",
- merchant_url,
- "EUR:1.04",
- EXCHANGE_URL,
- "x-taler-bank",
- MHD_HTTP_OK),
- TALER_TESTING_cmd_admin_add_incoming_with_ref (
- "create-reserve-reward-2-exch",
- "EUR:1.04",
- &cred.ba,
- payer_payto,
- "create-reserve-reward-2",
- MHD_HTTP_OK),
- cmd_exec_wirewatch ("wirewatch-4"),
- TALER_TESTING_cmd_reward_authorize_from_reserve_with_ec (
- "authorize-reward-insufficient-funds",
- merchant_url,
- EXCHANGE_URL,
- "create-reserve-reward-2",
- MHD_HTTP_PRECONDITION_FAILED,
- "reward 4",
- "EUR:5.01",
- TALER_EC_MERCHANT_PRIVATE_POST_REWARD_AUTHORIZE_INSUFFICIENT_FUNDS),
- TALER_TESTING_cmd_reward_authorize_fake ("fake-reward-authorization"),
- TALER_TESTING_cmd_reward_pickup_with_ec ("pickup-non-existent-id",
- merchant_url,
- MHD_HTTP_NOT_FOUND,
- "fake-reward-authorization",
- pickup_amounts_1,
- TALER_EC_MERCHANT_GENERIC_REWARD_ID_UNKNOWN),
- TALER_TESTING_cmd_merchant_get_reserves ("get-reserves-2",
- merchant_url,
- MHD_HTTP_OK,
- "create-reserve-reward-1",
- "create-reserve-reward-2",
- NULL),
- TALER_TESTING_cmd_merchant_delete_reserve ("delete-reserve-reward-1",
- merchant_url,
- "create-reserve-reward-1",
- MHD_HTTP_NO_CONTENT),
- TALER_TESTING_cmd_merchant_purge_reserve ("delete-reserve-reward-2",
- merchant_url,
- "create-reserve-reward-1",
- MHD_HTTP_NO_CONTENT),
- TALER_TESTING_cmd_merchant_purge_reserve ("delete-reserve-reward-3",
- merchant_url,
- "create-reserve-reward-1",
- MHD_HTTP_NOT_FOUND),
- TALER_TESTING_cmd_end ()
- };
-
struct TALER_TESTING_Command pay_again[] = {
cmd_transfer_to_exchange ("create-reserve-20",
"EUR:20.04"),
@@ -1434,7 +1249,7 @@ run (void *cls,
merchant_url,
"otp-dev",
"my OTP device",
- "otp-key",
+ "FEE4P2J",
TALER_MCA_WITH_PRICE,
0,
MHD_HTTP_NO_CONTENT),
@@ -1454,7 +1269,7 @@ run (void *cls,
merchant_url,
"template-amount",
"a different template with an amount",
- NULL,
+ NULL,
GNUNET_JSON_PACK (
GNUNET_JSON_pack_uint64 ("minimum_age", 0),
GNUNET_JSON_pack_time_rel ("pay_duration",
@@ -1693,11 +1508,11 @@ run (void *cls,
"default",
MHD_HTTP_NO_CONTENT),
TALER_TESTING_cmd_merchant_post_account (
- "instance-create-default-account",
- merchant_url,
- PAYTO_I1,
- NULL, NULL,
- MHD_HTTP_OK),
+ "instance-create-default-account",
+ merchant_url,
+ PAYTO_I1,
+ NULL, NULL,
+ MHD_HTTP_OK),
TALER_TESTING_cmd_merchant_post_instances ("instance-create-i1",
merchant_url,
"i1",
@@ -1937,8 +1752,6 @@ run (void *cls,
pay_abort),
TALER_TESTING_cmd_batch ("refund",
refund),
- TALER_TESTING_cmd_batch ("reward",
- reward),
TALER_TESTING_cmd_batch ("templates",
templates),
TALER_TESTING_cmd_batch ("webhooks",
diff --git a/src/testing/test_merchant_reserve_creation.sh b/src/testing/test_merchant_reserve_creation.sh
deleted file mode 100755
index 207fd821..00000000
--- a/src/testing/test_merchant_reserve_creation.sh
+++ /dev/null
@@ -1,233 +0,0 @@
-#!/bin/bash
-# This file is part of TALER
-# Copyright (C) 2014-2023 Taler Systems SA
-#
-# TALER is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 3, or
-# (at your option) any later version.
-#
-# TALER is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public
-# License along with TALER; see the file COPYING. If not, see
-# <http://www.gnu.org/licenses/>
-#
-
-set -eu
-
-# Replace with 0 for nexus...
-USE_FAKEBANK=1
-if [ 1 = "$USE_FAKEBANK" ]
-then
- ACCOUNT="exchange-account-2"
- WIRE_METHOD="x-taler-bank"
- BANK_FLAGS="-f -d $WIRE_METHOD -u $ACCOUNT"
- BANK_URL="http://localhost:8082/"
-else
- ACCOUNT="exchange-account-1"
- WIRE_METHOD="iban"
- BANK_FLAGS="-ns -d $WIRE_METHOD -u $ACCOUNT"
- BANK_URL="http://localhost:18082/"
-fi
-
-. setup.sh
-# Launch exchange, merchant and bank.
-setup -c "test_template.conf" \
- -em \
- $BANK_FLAGS
-LAST_RESPONSE=$(mktemp -p "${TMPDIR:-/tmp}" test_response.conf-XXXXXX)
-CONF="test_template.conf.edited"
-
-echo -n "Configuring merchant instance ..."
-
-STATUS=$(curl -H "Content-Type: application/json" -X POST \
- -H 'Authorization: Bearer secret-token:super_secret' \
- http://localhost:9966/management/instances \
- -d '{"auth":{"method":"external"},"id":"default","name":"default","user_type":"business","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 50000000},"default_pay_delay":{"d_us": 60000000}}' \
- -w "%{http_code}" -s -o /dev/null)
-
-if [ "$STATUS" != "204" ]
-then
- exit_fail "Expected 204, instance created. Got instead: $STATUS"
-fi
-echo "Ok"
-echo -n "Configuring merchant account ..."
-STATUS=$(curl -H "Content-Type: application/json" -X POST \
- -H 'Authorization: Bearer secret-token:super_secret' \
- http://localhost:9966/instances/default/private/accounts \
- -d '{"payto_uri":"payto://x-taler-bank/localhost:18082/fortythree"}' \
- -w "%{http_code}" -s -o /dev/null)
-
-if [ "$STATUS" != "200" ]
-then
- exit_fail "Expected 200 OK. Got: $STATUS"
-fi
-
-echo "OK"
-
-echo -n "Creating reserve ..."
-
-STATUS=$(curl 'http://localhost:9966/instances/default/private/reserves' \
- -d '{"initial_balance":"TESTKUDOS:2","exchange_url":"http://localhost:8081/","wire_method":"'"$WIRE_METHOD"'"}' \
- -w "%{http_code}" -s -o "$LAST_RESPONSE")
-
-if [ "$STATUS" != "200" ]
-then
- cat "$LAST_RESPONSE"
- exit_fail "Expected 200, reserve created. Got instead: $STATUS"
-fi
-
-echo "OK"
-
-RESERVE_PUB=$(jq -r .reserve_pub < "$LAST_RESPONSE")
-
-STATUS=$(curl 'http://localhost:9966/instances/default/private/reserves/'"$RESERVE_PUB" \
- -w "%{http_code}" -s -o "$LAST_RESPONSE")
-
-FUNDED=$(jq -r '.merchant_initial_amount == .exchange_initial_amount' < "$LAST_RESPONSE")
-
-if [ "$FUNDED" != "false" ]
-then
- cat "$LAST_RESPONSE"
- exit_fail "Should not yet be funded if we just created. Got: $STATUS is founded: $FUNDED"
-fi
-
-
-echo -n "Wire transferring... "
-# Exchange wants TESTKUDOS:2 from account 43, under RESERVE_PUB.
-
-if [ 1 = "$USE_FAKEBANK" ]
-then
- BODY='{"reserve_pub":"'"$RESERVE_PUB"'","debit_account":"payto://x-taler-bank/localhost/fortythree","amount":"TESTKUDOS:2"}'
- curl -X POST \
- -d "$BODY" \
- -s \
- http://localhost:8082/accounts/exchange/taler-wire-gateway/admin/add-incoming \
- > /dev/null
-else
- echo "FIXME: not implemented for current libeufin"
- exit 1
- EXCHANGE_PAYTO=$(get_payto_uri exchange x)
- export LIBEUFIN_SANDBOX_USERNAME=fortythree
- export LIBEUFIN_SANDBOX_PASSWORD=x
- export LIBEUFIN_SANDBOX_URL="http://localhost:18082/"
- libeufin-cli sandbox demobank new-transaction \
- --bank-account "fortythree" \
- --payto-with-subject "$EXCHANGE_PAYTO&message=$RESERVE_PUB" \
- --amount "TESTKUDOS:2"
- unset LIBEUFIN_SANDBOX_USERNAME
- unset LIBEUFIN_SANDBOX_PASSWORD
- unset LIBEUFIN_SANDBOX_URL
- echo "OK"
- echo -n "Give Nexus time to detect the payment (FIXME)... "
- sleep 10 # FIXME-MS: replace with call to Nexus to right now poll the sandbox ...
- # This seems to not work (exchange user unknown). Not sure why.
- #export LIBEUFIN_NEXUS_USERNAME=exchange
- #export LIBEUFIN_NEXUS_PASSWORD=x
- #export LIBEUFIN_NEXUS_URL="http://localhost:8082/"
- #libeufin-cli \
- # accounts \
- # fetch-transactions \
- # exchange \
- # &> libeufin-transfer-fetch.out
- #unset LIBEUFIN_NEXUS_USERNAME
- #unset LIBEUFIN_NEXUS_PASSWORD
- #unset LIBEUFIN_NEXUS_URL
-fi
-echo "OK"
-
-echo "Fetch transaction for exchange"
-# Run wirewatch here, now, and only once
-taler-exchange-wirewatch \
- -c "$CONF" \
- -t \
- -L "INFO" \
- &> taler-exchange-wirewatch.log
-
-STATUS=$(curl 'http://localhost:9966/instances/default/private/reserves/'"$RESERVE_PUB" \
- -w "%{http_code}" -s -o "$LAST_RESPONSE")
-FUNDED=$(jq -r '.merchant_initial_amount == .exchange_initial_amount' < "$LAST_RESPONSE")
-
-if [ "$FUNDED" != "true" ]
-then
- cat "$LAST_RESPONSE"
- exit_fail "should be funded. got: $STATUS is founded: $FUNDED"
-fi
-
-ACCOUNTS=$(jq -r '.accounts|length' < "$LAST_RESPONSE")
-if [ "x$ACCOUNTS" != "x1" ]
-then
- cat "$LAST_RESPONSE"
- exit_fail "Expected 1 account in response. got: $ACCOUNTS"
-fi
-
-echo -n "authorizing reward ..."
-
-STATUS=$(curl 'http://localhost:9966/instances/default/private/reserves/'"$RESERVE_PUB"'/authorize-reward' \
- -d '{"amount":"TESTKUDOS:1","justification":"off course","next_url":"https://taler.net/"}' \
- -w "%{http_code}" -s -o "$LAST_RESPONSE")
-
-if [ "$STATUS" != "200" ]
-then
- exit_fail "should respond failed, we did not fund yet. got: $STATUS"
-fi
-echo "OK"
-
-echo -n "Checking reward ..."
-STATUS=$(curl 'http://localhost:9966/instances/default/private/reserves/'"$RESERVE_PUB"'?rewards=yes' \
- -w "%{http_code}" -s -o "$LAST_RESPONSE")
-
-REWARDS_SIZE=$(jq -r ".rewards | length" < "$LAST_RESPONSE")
-
-if [ "$REWARDS_SIZE" != "1" ]
-then
- cat "$LAST_RESPONSE"
- exit_fail "Expected 1 reward. got: $REWARDS_SIZE"
-fi
-
-REWARD_ID=$(jq -r .rewards[0].reward_id < "$LAST_RESPONSE")
-
-echo "Found"
-
-echo -n "Checking reward status ..."
-
-STATUS=$(curl 'http://localhost:9966/instances/default/private/rewards/'"$REWARD_ID" \
- -w "%{http_code}" -s -o "$LAST_RESPONSE")
-
-if [ "$STATUS" != "200" ]
-then
- cat "$LAST_RESPONSE"
- exit_fail "Expected 200, reward found. got: $STATUS"
-fi
-
-echo -n " ... "
-
-STATUS=$(curl 'http://localhost:9966/instances/default/private/rewards/'"$REWARD_ID"'?pickups=yes' \
- -w "%{http_code}" -s -o "$LAST_RESPONSE")
-
-if [ "$STATUS" != "200" ]
-then
- cat "$LAST_RESPONSE"
- exit_fail "Expected 200, reward found. got: $STATUS"
-fi
-echo "OK"
-
-echo -n "trying to create invalid reserve ..."
-
-STATUS=$(curl 'http://localhost:9966/instances/default/private/reserves' \
- -d '{"initial_balance":"INVALID:2","exchange_url":"http://localhost:8081/","wire_method":"iban"}' \
- -w "%{http_code}" -s -o "$LAST_RESPONSE")
-
-if [ "$STATUS" != "409" ]
-then
- exit_fail "Expected 409, bad currency. got: $STATUS"
-fi
-echo "FAILED (which is expected)"
-
-echo "Test PASSED"
-
-exit 0
diff --git a/src/testing/testing_api_cmd_delete_reserve.c b/src/testing/testing_api_cmd_delete_reserve.c
deleted file mode 100644
index 38742630..00000000
--- a/src/testing/testing_api_cmd_delete_reserve.c
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2020 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 3, or
- (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file testing_api_cmd_delete_reserve.c
- * @brief command to test DELETE /reserves/$RESERVE_PUB
- * @author Jonathan Buchanan
- */
-#include "platform.h"
-#include <taler/taler_exchange_service.h>
-#include <taler/taler_testing_lib.h>
-#include "taler_merchant_service.h"
-#include "taler_merchant_testing_lib.h"
-
-
-/**
- * State of a "DELETE /reserves/$RESERVE_PUB" CMD.
- */
-struct DeleteReserveState
-{
-
- /**
- * Handle for a "DELETE reserve" request.
- */
- struct TALER_MERCHANT_ReserveDeleteHandle *rdh;
-
- /**
- * The interpreter state.
- */
- struct TALER_TESTING_Interpreter *is;
-
- /**
- * Base URL of the merchant serving the request.
- */
- const char *merchant_url;
-
- /**
- * Reference to a command that provides a reserve.
- */
- const char *reserve_reference;
-
- /**
- * Expected HTTP response code.
- */
- unsigned int http_status;
-
- /**
- * Use purge, not delete.
- */
- bool purge;
-
-};
-
-
-/**
- * Callback for a DELETE /reserves/$RESERVE_PUB operation.
- *
- * @param cls closure for this function
- * @param hr response being processed
- */
-static void
-delete_reserve_cb (void *cls,
- const struct TALER_MERCHANT_HttpResponse *hr)
-{
- struct DeleteReserveState *drs = cls;
-
- drs->rdh = NULL;
- if (drs->http_status != hr->http_status)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u (%d) to command %s\n",
- hr->http_status,
- (int) hr->ec,
- TALER_TESTING_interpreter_get_current_label (drs->is));
- TALER_TESTING_interpreter_fail (drs->is);
- return;
- }
- switch (hr->http_status)
- {
- case MHD_HTTP_NO_CONTENT:
- break;
- case MHD_HTTP_NOT_FOUND:
- break;
- case MHD_HTTP_CONFLICT:
- break;
- default:
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Unhandled HTTP status %u for DELETE reserve.\n",
- hr->http_status);
- }
- TALER_TESTING_interpreter_next (drs->is);
-}
-
-
-/**
- * Run the "DELETE reserve" CMD.
- *
- * @param cls closure.
- * @param cmd command being run now.
- * @param is interpreter state.
- */
-static void
-delete_reserve_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct DeleteReserveState *drs = cls;
- const struct TALER_TESTING_Command *reserve_cmd;
- const struct TALER_ReservePublicKeyP *reserve_pub;
-
- reserve_cmd = TALER_TESTING_interpreter_lookup_command (
- is,
- drs->reserve_reference);
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_reserve_pub (reserve_cmd,
- &reserve_pub))
- TALER_TESTING_FAIL (is);
-
- drs->is = is;
- if (drs->purge)
- drs->rdh = TALER_MERCHANT_reserve_purge (
- TALER_TESTING_interpreter_get_context (is),
- drs->merchant_url,
- reserve_pub,
- &delete_reserve_cb,
- drs);
- else
- drs->rdh = TALER_MERCHANT_reserve_delete (
- TALER_TESTING_interpreter_get_context (is),
- drs->merchant_url,
- reserve_pub,
- &delete_reserve_cb,
- drs);
-
- GNUNET_assert (NULL != drs->rdh);
-}
-
-
-/**
- * Free the state of a "DELETE reserve" CMD, and possibly
- * cancel a pending operation thereof.
- *
- * @param cls closure.
- * @param cmd command being run.
- */
-static void
-delete_reserve_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
-{
- struct DeleteReserveState *drs = cls;
-
- if (NULL != drs->rdh)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "DELETE /reserves/$RESERVE_PUB operation did not complete\n");
- TALER_MERCHANT_reserve_delete_cancel (drs->rdh);
- }
- GNUNET_free (drs);
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_delete_reserve (const char *label,
- const char *merchant_url,
- const char *reserve_reference,
- unsigned int http_status)
-{
- struct DeleteReserveState *drs;
-
- drs = GNUNET_new (struct DeleteReserveState);
- drs->merchant_url = merchant_url;
- drs->reserve_reference = reserve_reference;
- drs->http_status = http_status;
- {
- struct TALER_TESTING_Command cmd = {
- .cls = drs,
- .label = label,
- .run = &delete_reserve_run,
- .cleanup = &delete_reserve_cleanup
- };
-
- return cmd;
- }
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_purge_reserve (const char *label,
- const char *merchant_url,
- const char *reserve_reference,
- unsigned int http_status)
-{
- struct DeleteReserveState *drs;
-
- drs = GNUNET_new (struct DeleteReserveState);
- drs->merchant_url = merchant_url;
- drs->reserve_reference = reserve_reference;
- drs->http_status = http_status;
- drs->purge = true;
- {
- struct TALER_TESTING_Command cmd = {
- .cls = drs,
- .label = label,
- .run = &delete_reserve_run,
- .cleanup = &delete_reserve_cleanup
- };
-
- return cmd;
- }
-}
-
-
-/* end of testing_api_cmd_delete_reserve.c */
diff --git a/src/testing/testing_api_cmd_get_reserve.c b/src/testing/testing_api_cmd_get_reserve.c
deleted file mode 100644
index e9589dbb..00000000
--- a/src/testing/testing_api_cmd_get_reserve.c
+++ /dev/null
@@ -1,334 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2020-2023 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 3, or
- (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file testing_api_cmd_get_reserve.c
- * @brief command to test GET /private/reserves/$RESERVE_PUB
- * @author Jonathan Buchanan
- */
-#include "platform.h"
-#include <taler/taler_exchange_service.h>
-#include <taler/taler_testing_lib.h>
-#include "taler_merchant_service.h"
-#include "taler_merchant_testing_lib.h"
-
-
-struct GetReserveState
-{
-
- /**
- * Handle for a "GET reserve" request.
- */
- struct TALER_MERCHANT_ReserveGetHandle *rgh;
-
- /**
- * The interpreter state.
- */
- struct TALER_TESTING_Interpreter *is;
-
- /**
- * Base URL of the merchant serving the request.
- */
- const char *merchant_url;
-
- /**
- * Label for a command that created a reserve.
- */
- const char *reserve_reference;
-
- /**
- * Expected HTTP response code.
- */
- unsigned int http_status;
-
- /**
- * Fetch rewards
- */
- bool fetch_rewards;
-
- /**
- * Length of @e rewards.
- */
- unsigned int rewards_length;
-
- /**
- * The list of references to rewards.
- */
- const char **rewards;
-};
-
-
-static void
-get_reserve_cb (void *cls,
- const struct TALER_MERCHANT_ReserveGetResponse *rgr)
-{
- struct GetReserveState *grs = cls;
- const struct TALER_MERCHANT_HttpResponse *hr = &rgr->hr;
- const struct TALER_TESTING_Command *reserve_cmd;
-
- reserve_cmd = TALER_TESTING_interpreter_lookup_command (
- grs->is,
- grs->reserve_reference);
-
- grs->rgh = NULL;
- if (grs->http_status != hr->http_status)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u (%d) to command %s\n",
- hr->http_status,
- (int) hr->ec,
- TALER_TESTING_interpreter_get_current_label (grs->is));
- TALER_TESTING_interpreter_fail (grs->is);
- return;
- }
- switch (hr->http_status)
- {
- case MHD_HTTP_OK:
- {
- const struct TALER_MERCHANT_ReserveSummary *rs = &rgr->details.ok.rs;
- const struct TALER_Amount *initial_amount;
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_amount (reserve_cmd,
- &initial_amount))
- TALER_TESTING_interpreter_fail (grs->is);
- if ((GNUNET_OK !=
- TALER_amount_cmp_currency (&rs->merchant_initial_amount,
- initial_amount)) ||
- (0 != TALER_amount_cmp (&rs->merchant_initial_amount,
- initial_amount)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Reserve initial amount does not match\n");
- TALER_TESTING_interpreter_fail (grs->is);
- return;
- }
- }
- {
- unsigned int rewards_length = rgr->details.ok.rewards_length;
- const struct TALER_MERCHANT_RewardDetails *rewards =
- rgr->details.ok.rewards;
-
- if (rewards_length != grs->rewards_length)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Number of rewards authorized does not match\n");
- TALER_TESTING_interpreter_fail (grs->is);
- return;
- }
- for (unsigned int i = 0; i < rewards_length; ++i)
- {
- const struct TALER_TESTING_Command *reward_cmd;
-
- reward_cmd = TALER_TESTING_interpreter_lookup_command (grs->is,
- grs->rewards[i]);
- {
- const struct TALER_RewardIdentifierP *reward_id;
-
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_reward_id (reward_cmd,
- &reward_id))
- TALER_TESTING_interpreter_fail (grs->is);
-
- if (0 != GNUNET_memcmp (&rewards[i].reward_id,
- reward_id))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Reserve reward id does not match\n");
- TALER_TESTING_interpreter_fail (grs->is);
- return;
- }
- }
- {
- const struct TALER_Amount *total_amount;
-
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_amount (reward_cmd,
- &total_amount))
- TALER_TESTING_interpreter_fail (grs->is);
-
- if ((GNUNET_OK !=
- TALER_amount_cmp_currency (&rewards[i].amount,
- total_amount)) ||
- (0 != TALER_amount_cmp (&rewards[i].amount,
- total_amount)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Reserve reward amount does not match\n");
- TALER_TESTING_interpreter_fail (grs->is);
- return;
- }
- }
- {
- const char *reason;
-
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_reason (reward_cmd,
- &reason))
- TALER_TESTING_interpreter_fail (grs->is);
-
- if (0 != strcmp (rewards[i].reason,
- reason))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Reserve reward reason does not match\n");
- TALER_TESTING_interpreter_fail (grs->is);
- return;
- }
- }
- }
- }
- break;
- default:
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Unhandled HTTP status.\n");
- }
- TALER_TESTING_interpreter_next (grs->is);
-}
-
-
-/**
- * Run the "GET /private/reserves/$RESERVE_PUB" CMD.
- *
- * @param cls closure.
- * @param cmd command being run now.
- * @param is interpreter state.
- */
-static void
-get_reserve_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct GetReserveState *grs = cls;
- const struct TALER_TESTING_Command *reserve_cmd;
- const struct TALER_ReservePublicKeyP *reserve_pub;
-
- reserve_cmd = TALER_TESTING_interpreter_lookup_command (
- is,
- grs->reserve_reference);
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_reserve_pub (reserve_cmd,
- &reserve_pub))
- TALER_TESTING_FAIL (is);
-
- grs->is = is;
- grs->rgh = TALER_MERCHANT_reserve_get (TALER_TESTING_interpreter_get_context (
- is),
- grs->merchant_url,
- reserve_pub,
- grs->fetch_rewards,
- &get_reserve_cb,
- grs);
-
- GNUNET_assert (NULL != grs->rgh);
-}
-
-
-/**
- * Free the state of a "GET reserve" CMD, and possibly
- * cancel a pending operation thereof.
- *
- * @param cls closure.
- * @param cmd command being run.
- */
-static void
-get_reserve_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
-{
- struct GetReserveState *grs = cls;
-
- if (NULL != grs->rgh)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "GET /private/reserve/$RESERVE_PUB operation did not complete\n");
- TALER_MERCHANT_reserve_get_cancel (grs->rgh);
- }
- GNUNET_array_grow (grs->rewards,
- grs->rewards_length,
- 0);
- GNUNET_free (grs);
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_get_reserve (const char *label,
- const char *merchant_url,
- unsigned int http_status,
- const char *reserve_reference)
-{
- struct GetReserveState *grs;
-
- grs = GNUNET_new (struct GetReserveState);
- grs->merchant_url = merchant_url;
- grs->http_status = http_status;
- grs->reserve_reference = reserve_reference;
- grs->fetch_rewards = false;
- {
- struct TALER_TESTING_Command cmd = {
- .cls = grs,
- .label = label,
- .run = &get_reserve_run,
- .cleanup = &get_reserve_cleanup
- };
-
- return cmd;
- }
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_get_reserve_with_rewards (const char *label,
- const char *merchant_url,
- unsigned int http_status,
- const char *
- reserve_reference,
- ...)
-{
- struct GetReserveState *grs;
-
- grs = GNUNET_new (struct GetReserveState);
- grs->merchant_url = merchant_url;
- grs->http_status = http_status;
- grs->reserve_reference = reserve_reference;
- grs->fetch_rewards = true;
- {
- const char *clabel;
- va_list ap;
-
- va_start (ap, reserve_reference);
- while (NULL != (clabel = va_arg (ap, const char *)))
- {
- GNUNET_array_append (grs->rewards,
- grs->rewards_length,
- clabel);
- }
- va_end (ap);
- }
- {
- struct TALER_TESTING_Command cmd = {
- .cls = grs,
- .label = label,
- .run = &get_reserve_run,
- .cleanup = &get_reserve_cleanup
- };
-
- return cmd;
- }
-}
-
-
-/* end of testing_api_cmd_get_reserve.c */
diff --git a/src/testing/testing_api_cmd_get_reserves.c b/src/testing/testing_api_cmd_get_reserves.c
deleted file mode 100644
index d62a73e3..00000000
--- a/src/testing/testing_api_cmd_get_reserves.c
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2020-2023 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 3, or
- (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file testing_api_cmd_get_reserves.c
- * @brief command to test GET /private/reserves
- * @author Jonathan Buchanan
- */
-#include "platform.h"
-#include <taler/taler_exchange_service.h>
-#include <taler/taler_testing_lib.h>
-#include "taler_merchant_service.h"
-#include "taler_merchant_testing_lib.h"
-
-
-/**
- * State of a "GET reserves" CMD
- */
-struct GetReservesState
-{
-
- /**
- * Handle for a "GET reserves" request.
- */
- struct TALER_MERCHANT_ReservesGetHandle *rgh;
-
- /**
- * The interpreter state.
- */
- struct TALER_TESTING_Interpreter *is;
-
- /**
- * A list of reserves to compare with.
- */
- const char **reserves;
-
- /**
- * Length of @e reserve_refs.
- */
- unsigned int reserves_length;
-
- /**
- * Base URL of the merchant serving the request.
- */
- const char *merchant_url;
-
- /**
- * Expected HTTP response code.
- */
- unsigned int http_status;
-};
-
-
-static void
-get_reserves_cb (void *cls,
- const struct TALER_MERCHANT_ReservesGetResponse *rgr)
-{
- struct GetReservesState *grs = cls;
-
- grs->rgh = NULL;
- if (grs->http_status != rgr->hr.http_status)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u (%d) to command %s\n",
- rgr->hr.http_status,
- (int) rgr->hr.ec,
- TALER_TESTING_interpreter_get_current_label (grs->is));
- TALER_TESTING_interpreter_fail (grs->is);
- return;
- }
- switch (rgr->hr.http_status)
- {
- case MHD_HTTP_OK:
- {
- bool matched[GNUNET_NZL (rgr->details.ok.reserves_length)];
- bool fail = false;
-
- if (rgr->details.ok.reserves_length != grs->reserves_length)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Length of reserves found does not match\n");
- TALER_TESTING_interpreter_fail (grs->is);
- return;
- }
- /* check if the data returned matches that from the POST / PATCH */
- memset (matched,
- 0,
- sizeof (matched));
- for (unsigned int i = 0; i < rgr->details.ok.reserves_length; ++i)
- {
- const struct TALER_MERCHANT_ReserveSummary *reserve
- = &rgr->details.ok.reserves[i];
-
- for (unsigned int j = 0; j < grs->reserves_length; ++j)
- {
- const struct TALER_TESTING_Command *reserve_cmd;
- bool match = true;
-
- reserve_cmd = TALER_TESTING_interpreter_lookup_command (
- grs->is,
- grs->reserves[j]);
- {
- const struct TALER_ReservePublicKeyP *reserve_pub;
-
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_reserve_pub (reserve_cmd,
- &reserve_pub))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not fetch reserve public key\n");
- TALER_TESTING_interpreter_fail (grs->is);
- return;
- }
- if (0 != GNUNET_memcmp (&reserve->reserve_pub,
- reserve_pub))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Reserve public key does not match, got %s\n",
- TALER_B2S (&reserve->reserve_pub));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Reserve public key does not match, expected %s\n",
- TALER_B2S (reserve_pub));
- match = false;
- }
- }
- {
- const struct TALER_Amount *initial;
-
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_amount (reserve_cmd,
- &initial))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not fetch reserve initial balance\n");
- TALER_TESTING_interpreter_fail (grs->is);
- return;
- }
- if ((GNUNET_OK !=
- TALER_amount_cmp_currency (
- &reserve->merchant_initial_amount,
- initial)) ||
- (0 != TALER_amount_cmp (&reserve->merchant_initial_amount,
- initial)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Reserve initial amount does not match, got %s\n",
- TALER_amount2s (
- &reserve->merchant_initial_amount));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Reserve initial amount does not match, wanted %s\n",
- TALER_amount2s (initial));
- match = false;
- }
- }
- if (match)
- matched[i] = true;
- }
- }
- for (unsigned int i = 0; i < rgr->details.ok.reserves_length; ++i)
- if (! matched[i])
- fail = true;
- if (fail)
- {
- TALER_TESTING_interpreter_fail (grs->is);
- return;
- }
- break;
- }
- default:
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Unhandled HTTP status %u.\n",
- rgr->hr.http_status);
- break;
- }
- TALER_TESTING_interpreter_next (grs->is);
-}
-
-
-/**
- * Run the "GET /private/reserves" CMD.
- *
- * @param cls closure.
- * @param cmd command being run now.
- * @param is interpreter state.
- */
-static void
-get_reserves_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct GetReservesState *grs = cls;
-
- grs->is = is;
- grs->rgh = TALER_MERCHANT_reserves_get (
- TALER_TESTING_interpreter_get_context (is),
- grs->merchant_url,
- GNUNET_TIME_UNIT_ZERO_TS,
- TALER_EXCHANGE_YNA_ALL,
- TALER_EXCHANGE_YNA_ALL,
- &get_reserves_cb,
- grs);
-
- GNUNET_assert (NULL != grs->rgh);
-}
-
-
-/**
- * Free the state of a "GET reserves" CMD, and possibly
- * cancel a pending operation thereof.
- *
- * @param cls closure.
- * @param cmd command being run.
- */
-static void
-get_reserves_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
-{
- struct GetReservesState *grs = cls;
-
- if (NULL != grs->rgh)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "GET /private/reserves operation did not complete\n");
- TALER_MERCHANT_reserves_get_cancel (grs->rgh);
- }
- GNUNET_array_grow (grs->reserves,
- grs->reserves_length,
- 0);
- GNUNET_free (grs);
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_get_reserves (const char *label,
- const char *merchant_url,
- unsigned int http_status,
- ...)
-{
- struct GetReservesState *grs;
-
- grs = GNUNET_new (struct GetReservesState);
- grs->merchant_url = merchant_url;
- grs->http_status = http_status;
- {
- const char *clabel;
- va_list ap;
-
- va_start (ap, http_status);
- while (NULL != (clabel = va_arg (ap, const char *)))
- {
- GNUNET_array_append (grs->reserves,
- grs->reserves_length,
- clabel);
- }
- va_end (ap);
- }
- {
- struct TALER_TESTING_Command cmd = {
- .cls = grs,
- .label = label,
- .run = &get_reserves_run,
- .cleanup = &get_reserves_cleanup
- };
-
- return cmd;
- }
-}
-
-
-/* end of testing_api_cmd_get_reserves.c */
diff --git a/src/testing/testing_api_cmd_get_rewards.c b/src/testing/testing_api_cmd_get_rewards.c
deleted file mode 100644
index 4bc72f79..00000000
--- a/src/testing/testing_api_cmd_get_rewards.c
+++ /dev/null
@@ -1,311 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2020-2023 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 3, or
- (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file testing_api_cmd_get_rewards.c
- * @brief command to test GET /private/rewards
- * @author Jonathan Buchanan
- */
-#include "platform.h"
-#include <taler/taler_exchange_service.h>
-#include <taler/taler_testing_lib.h>
-#include "taler_merchant_service.h"
-#include "taler_merchant_testing_lib.h"
-
-
-/**
- * State of a "GET rewards" CMD.
- */
-struct GetRewardsState
-{
-
- /**
- * Handle for a "GET rewards" request.
- */
- struct TALER_MERCHANT_RewardsGetHandle *tgh;
-
- /**
- * The interpreter state.
- */
- struct TALER_TESTING_Interpreter *is;
-
- /**
- * Base URL of the merchant serving the request.
- */
- const char *merchant_url;
-
- /**
- * Row to start querying the database from.
- */
- uint64_t offset;
-
- /**
- * How many rows to return (with direction).
- */
- int64_t limit;
-
- /**
- * Expected HTTP response code.
- */
- unsigned int http_status;
-
- /**
- * Length of @e rewards.
- */
- unsigned int rewards_length;
-
- /**
- * References to rewards that we expect to be found.
- */
- const char **rewards;
-
-};
-
-/**
- * Callback for a GET /private/rewards operation.
- *
- * @param cls closure for this function
- * @param tgr response details
- */
-static void
-get_rewards_cb (void *cls,
- const struct TALER_MERCHANT_RewardsGetResponse *tgr)
-{
- struct GetRewardsState *gts = cls;
-
- gts->tgh = NULL;
- if (gts->http_status != tgr->hr.http_status)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u (%d) to command %s\n",
- tgr->hr.http_status,
- (int) tgr->hr.ec,
- TALER_TESTING_interpreter_get_current_label (gts->is));
- TALER_TESTING_interpreter_fail (gts->is);
- return;
- }
- switch (tgr->hr.http_status)
- {
- case MHD_HTTP_OK:
- if (tgr->details.ok.rewards_length != gts->rewards_length)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Rewards length does not match\n");
- TALER_TESTING_interpreter_fail (gts->is);
- return;
- }
- for (unsigned int i = 0; i < tgr->details.ok.rewards_length; ++i)
- {
- const struct TALER_MERCHANT_RewardEntry *reward
- = &tgr->details.ok.rewards[i];
- const struct TALER_TESTING_Command *reward_cmd;
-
- reward_cmd = TALER_TESTING_interpreter_lookup_command (
- gts->is,
- gts->rewards[i]);
- {
- const struct TALER_RewardIdentifierP *reward_id;
-
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_reward_id (reward_cmd,
- &reward_id))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not fetch reward id\n");
- TALER_TESTING_interpreter_fail (gts->is);
- return;
- }
- if (0 != GNUNET_memcmp (reward_id,
- &reward->reward_id))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Reward id does not match\n");
- TALER_TESTING_interpreter_fail (gts->is);
- return;
- }
- }
- {
- const struct TALER_Amount *reward_amount;
-
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_amount (reward_cmd,
- &reward_amount))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not fetch reward amount\n");
- TALER_TESTING_interpreter_fail (gts->is);
- return;
- }
- if ( (GNUNET_OK !=
- TALER_amount_cmp_currency (reward_amount,
- &reward->reward_amount)) ||
- (0 !=
- TALER_amount_cmp (reward_amount,
- &reward->reward_amount)) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Reward amount does not match\n");
- TALER_TESTING_interpreter_fail (gts->is);
- return;
- }
- }
- }
- break;
- default:
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Unhandled HTTP status.\n");
- }
- TALER_TESTING_interpreter_next (gts->is);
-}
-
-
-/**
- * Run the "GET /private/rewards" CMD.
- *
- * @param cls closure.
- * @param cmd command being run now.
- * @param is interpreter state.
- */
-static void
-get_rewards_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct GetRewardsState *gts = cls;
-
- gts->is = is;
- gts->tgh = TALER_MERCHANT_rewards_get2 (
- TALER_TESTING_interpreter_get_context (is),
- gts->merchant_url,
- TALER_EXCHANGE_YNA_NO,
- gts->limit,
- gts->offset,
- &get_rewards_cb,
- gts);
-
- GNUNET_assert (NULL != gts->tgh);
-}
-
-
-/**
- * Free the state of a "GET rewards" CMD, and possibly
- * cancel a pending operation thereof.
- *
- * @param cls closure.
- * @param cmd command being run.
- */
-static void
-get_rewards_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
-{
- struct GetRewardsState *gts = cls;
-
- if (NULL != gts->tgh)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "GET /private/rewards operation did not complete\n");
- TALER_MERCHANT_rewards_get_cancel (gts->tgh);
- }
- GNUNET_array_grow (gts->rewards,
- gts->rewards_length,
- 0);
- GNUNET_free (gts);
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_get_rewards (const char *label,
- const char *merchant_url,
- unsigned int http_status,
- ...)
-{
- struct GetRewardsState *gts;
-
- gts = GNUNET_new (struct GetRewardsState);
- gts->merchant_url = merchant_url;
- gts->offset = INT64_MAX;
- gts->limit = -20;
- gts->http_status = http_status;
- {
- const char *clabel;
- va_list ap;
-
- va_start (ap, http_status);
- while (NULL != (clabel = va_arg (ap, const char *)))
- {
- GNUNET_array_append (gts->rewards,
- gts->rewards_length,
- clabel);
- }
- va_end (ap);
- }
- {
- struct TALER_TESTING_Command cmd = {
- .cls = gts,
- .label = label,
- .run = &get_rewards_run,
- .cleanup = &get_rewards_cleanup
- };
-
- return cmd;
- }
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_get_rewards2 (const char *label,
- const char *merchant_url,
- uint64_t offset,
- int64_t limit,
- unsigned int http_status,
- ...)
-{
- struct GetRewardsState *gts;
-
- gts = GNUNET_new (struct GetRewardsState);
- gts->merchant_url = merchant_url;
- gts->offset = offset;
- gts->limit = limit;
- gts->http_status = http_status;
- {
- const char *clabel;
- va_list ap;
-
- va_start (ap, http_status);
- while (NULL != (clabel = va_arg (ap, const char *)))
- {
- GNUNET_array_append (gts->rewards,
- gts->rewards_length,
- clabel);
- }
- va_end (ap);
- }
- {
- struct TALER_TESTING_Command cmd = {
- .cls = gts,
- .label = label,
- .run = &get_rewards_run,
- .cleanup = &get_rewards_cleanup
- };
-
- return cmd;
- }
-}
-
-
-/* end of testing_api_cmd_get_rewards.c */
diff --git a/src/testing/testing_api_cmd_merchant_get_reward.c b/src/testing/testing_api_cmd_merchant_get_reward.c
deleted file mode 100644
index 1c8b5c00..00000000
--- a/src/testing/testing_api_cmd_merchant_get_reward.c
+++ /dev/null
@@ -1,373 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2020 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 3, or
- (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file testing_api_cmd_merchant_get_reward.c
- * @brief command to test GET /private/rewards/$REWARD_ID.
- * @author Jonathan Buchanan
- */
-#include "platform.h"
-#include <taler/taler_exchange_service.h>
-#include <taler/taler_testing_lib.h>
-#include "taler_merchant_service.h"
-#include "taler_merchant_testing_lib.h"
-
-/**
- * State for a GET /private/rewards/$REWARD_ID CMD.
- */
-struct MerchantRewardGetState
-{
-
- /**
- * The merchant base URL.
- */
- const char *merchant_url;
-
- /**
- * Expected HTTP response code for this CMD.
- */
- unsigned int http_status;
-
- /**
- * Whether to fetch and compare pickups.
- */
- bool fetch_pickups;
-
- /**
- * The length of @e pickups.
- */
- unsigned int pickups_length;
-
- /**
- * The NULL-terminated list of pickup commands associated with the reward.
- */
- const char **pickups;
-
- /**
- * The handle to the current GET /rewards/$REWARD_ID request.
- */
- struct TALER_MERCHANT_RewardMerchantGetHandle *tgh;
-
- /**
- * The interpreter state.
- */
- struct TALER_TESTING_Interpreter *is;
-
- /**
- * Reference to a command that created a reward.
- */
- const char *reward_reference;
-};
-
-
-/**
- * Callback for a GET /private/rewards/$REWARD_ID operation.
- *
- * @param cls closure for this function
- * @param tsr response
- */
-static void
-merchant_get_reward_cb (void *cls,
- const struct TALER_MERCHANT_RewardStatusResponse *tsr)
-{
- struct MerchantRewardGetState *gts = cls;
- const struct TALER_TESTING_Command *authorize_cmd;
- struct TALER_Amount expected_total_picked_up;
-
- authorize_cmd = TALER_TESTING_interpreter_lookup_command (gts->is,
- gts->
- reward_reference);
-
- gts->tgh = NULL;
- if (gts->http_status != tsr->hr.http_status)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u (%d) to command %s\n",
- tsr->hr.http_status,
- (int) tsr->hr.ec,
- TALER_TESTING_interpreter_get_current_label (gts->is));
- TALER_TESTING_interpreter_fail (gts->is);
- return;
- }
- switch (tsr->hr.http_status)
- {
- case MHD_HTTP_OK:
- {
- const struct TALER_Amount *initial_amount;
-
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (
- tsr->details.ok.total_picked_up.currency,
- &expected_total_picked_up));
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_amount (authorize_cmd,
- &initial_amount))
- TALER_TESTING_FAIL (gts->is);
- if ((GNUNET_OK !=
- TALER_amount_cmp_currency (&tsr->details.ok.total_authorized,
- initial_amount)) ||
- (0 != TALER_amount_cmp (&tsr->details.ok.total_authorized,
- initial_amount)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Reward authorized amount does not match\n");
- TALER_TESTING_interpreter_fail (gts->is);
- return;
- }
- }
- {
- const char *justification;
-
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_reason (authorize_cmd,
- &justification))
- TALER_TESTING_FAIL (gts->is);
- if (0 != strcmp (tsr->details.ok.reason,
- justification))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Reward authorized reason does not match\n");
- TALER_TESTING_interpreter_fail (gts->is);
- return;
- }
- }
- {
- const struct GNUNET_TIME_Timestamp *reward_expiration;
-
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_timestamp (authorize_cmd,
- 0,
- &reward_expiration))
- TALER_TESTING_FAIL (gts->is);
- if (GNUNET_TIME_timestamp_cmp (*reward_expiration,
- !=,
- tsr->details.ok.expiration))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Reward authorized expiration does not match\n");
- TALER_TESTING_interpreter_fail (gts->is);
- return;
- }
- }
- if (tsr->details.ok.pickups_length != gts->pickups_length)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Length of pickups array does not match\n");
- TALER_TESTING_interpreter_fail (gts->is);
- return;
- }
- {
- for (unsigned int i = 0; i < gts->pickups_length; ++i)
- {
- const struct TALER_TESTING_Command *pickup_cmd;
-
- pickup_cmd = TALER_TESTING_interpreter_lookup_command (gts->is,
- gts->pickups[i]);
- {
- const uint32_t *num_planchets;
-
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_num_planchets (pickup_cmd,
- &num_planchets))
- TALER_TESTING_FAIL (gts->is);
-
- if (*num_planchets != tsr->details.ok.pickups[i].num_planchets)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Pickup planchet count does not match\n");
- TALER_TESTING_interpreter_fail (gts->is);
- return;
- }
- }
- {
- const struct TALER_Amount *total;
-
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_amount (pickup_cmd,
- &total))
- TALER_TESTING_FAIL (gts->is);
-
- if ( (GNUNET_OK !=
- TALER_amount_cmp_currency (total,
- &tsr->details.ok.pickups[i].
- requested_amount)) ||
- (0 != TALER_amount_cmp (total,
- &tsr->details.ok.pickups[i].
- requested_amount)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Pickup planchet sum does not match\n");
- TALER_TESTING_interpreter_fail (gts->is);
- return;
- }
- GNUNET_assert (0 < TALER_amount_add (&expected_total_picked_up,
- &expected_total_picked_up,
- total));
- }
- }
- if ( (GNUNET_OK !=
- TALER_amount_cmp_currency (&expected_total_picked_up,
- &tsr->details.ok.total_picked_up)) ||
- (0 !=
- TALER_amount_cmp (&expected_total_picked_up,
- &tsr->details.ok.total_picked_up)) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Reward picked up amount does not match\n");
- TALER_TESTING_interpreter_fail (gts->is);
- return;
- }
- }
- break;
- default:
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Unhandled HTTP status.\n");
- }
- TALER_TESTING_interpreter_next (gts->is);
-}
-
-
-/**
- * Run the "GET reward" CMD.
- *
- * @param cls closure.
- * @param cmd command being run now.
- * @param is interpreter state.
- */
-static void
-merchant_get_reward_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct MerchantRewardGetState *tgs = cls;
- const struct TALER_TESTING_Command *reward_cmd;
- const struct TALER_RewardIdentifierP *reward_id;
-
- reward_cmd = TALER_TESTING_interpreter_lookup_command (is,
- tgs->reward_reference);
-
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_reward_id (reward_cmd,
- &reward_id))
- TALER_TESTING_FAIL (is);
-
- tgs->is = is;
- tgs->tgh = TALER_MERCHANT_merchant_reward_get (
- TALER_TESTING_interpreter_get_context (is),
- tgs->merchant_url,
- reward_id,
- NULL,
- GNUNET_TIME_UNIT_ZERO,
- tgs->fetch_pickups,
- &merchant_get_reward_cb,
- tgs);
- GNUNET_assert (NULL != tgs->tgh);
-}
-
-
-/**
-* Free the state of a "GET reward" CMD, and possibly
-* cancel a pending operation thereof.
-*
-* @param cls closure.
-* @param cmd command being run.
-*/
-static void
-merchant_get_reward_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
-{
- struct MerchantRewardGetState *tgs = cls;
-
- if (NULL != tgs->tgh)
- {
- TALER_LOG_WARNING ("Get reward operation did not complete\n");
- TALER_MERCHANT_merchant_reward_get_cancel (tgs->tgh);
- }
- GNUNET_array_grow (tgs->pickups,
- tgs->pickups_length,
- 0);
- GNUNET_free (tgs);
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_get_reward (const char *label,
- const char *merchant_url,
- const char *reward_reference,
- unsigned int http_status)
-{
- struct MerchantRewardGetState *tgs;
-
- tgs = GNUNET_new (struct MerchantRewardGetState);
- tgs->merchant_url = merchant_url;
- tgs->reward_reference = reward_reference;
- tgs->http_status = http_status;
- {
- struct TALER_TESTING_Command cmd = {
- .cls = tgs,
- .label = label,
- .run = &merchant_get_reward_run,
- .cleanup = &merchant_get_reward_cleanup
- };
-
- return cmd;
- }
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_get_reward_with_pickups (const char *label,
- const char *merchant_url,
- const char *reward_reference,
- unsigned int http_status,
- ...)
-{
- struct MerchantRewardGetState *tgs;
-
- tgs = GNUNET_new (struct MerchantRewardGetState);
- tgs->merchant_url = merchant_url;
- tgs->reward_reference = reward_reference;
- tgs->fetch_pickups = true;
- tgs->http_status = http_status;
- {
- const char *clabel;
- va_list ap;
-
- va_start (ap, http_status);
- while (NULL != (clabel = va_arg (ap, const char *)))
- {
- GNUNET_array_append (tgs->pickups,
- tgs->pickups_length,
- clabel);
- }
- va_end (ap);
- }
- {
- struct TALER_TESTING_Command cmd = {
- .cls = tgs,
- .label = label,
- .run = &merchant_get_reward_run,
- .cleanup = &merchant_get_reward_cleanup
- };
-
- return cmd;
- }
-}
-
-
-/* end of testing_api_cmd_merchant_get_reward.c */
diff --git a/src/testing/testing_api_cmd_post_reserves.c b/src/testing/testing_api_cmd_post_reserves.c
deleted file mode 100644
index c8fe914d..00000000
--- a/src/testing/testing_api_cmd_post_reserves.c
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2020 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 3, or
- (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file testing_api_cmd_post_reserves.c
- * @brief command to test POST /reserves
- * @author Jonathan Buchanan
- */
-#include "platform.h"
-#include <taler/taler_exchange_service.h>
-#include <taler/taler_testing_lib.h>
-#include "taler_merchant_service.h"
-#include "taler_merchant_testing_lib.h"
-
-/**
- * State of a "POST /reserves" CMD.
- */
-struct PostReservesState
-{
- /**
- * Handle for a "POST /reserves" request.
- */
- struct TALER_MERCHANT_PostReservesHandle *prh;
-
- /**
- * The interpreter state.
- */
- struct TALER_TESTING_Interpreter *is;
-
- /**
- * Base URL of the merchant
- */
- const char *merchant_url;
-
- /**
- * Base URL of the exchange.
- */
- const char *exchange_url;
-
- /**
- * Wire method for the reserve.
- */
- const char *wire_method;
-
- /**
- * The initial balance of the reserve.
- */
- struct TALER_Amount initial_balance;
-
- /**
- * Expected HTTP response code.
- */
- unsigned int http_status;
-
- /**
- * Public key assigned to the reserve
- */
- struct TALER_ReservePublicKeyP reserve_pub;
-};
-
-
-/**
- * Callbacks of this type are used to work the result of submitting a
- * POST /reserves request to a merchant
- *
- * @param cls closure
- * @param prr response details
- */
-static void
-post_reserves_cb (void *cls,
- const struct TALER_MERCHANT_PostReservesResponse *prr)
-{
- struct PostReservesState *prs = cls;
-
- prs->prh = NULL;
- if (prs->http_status != prr->hr.http_status)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u (%d) to command %s\n",
- prr->hr.http_status,
- (int) prr->hr.ec,
- TALER_TESTING_interpreter_get_current_label (prs->is));
- TALER_TESTING_interpreter_fail (prs->is);
- return;
- }
- switch (prr->hr.http_status)
- {
- case MHD_HTTP_OK:
- prs->reserve_pub = prr->details.ok.reserve_pub;
- break;
- case MHD_HTTP_ACCEPTED:
- break;
- case MHD_HTTP_UNAUTHORIZED:
- break;
- case MHD_HTTP_NOT_FOUND:
- break;
- default:
- GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Unhandled HTTP status %u for POST /reserves.\n",
- prr->hr.http_status);
- break;
- }
- TALER_TESTING_interpreter_next (prs->is);
-}
-
-
-/**
- * Offers information from the POST /reserves CMD state to other
- * commands.
- *
- * @param cls closure
- * @param[out] ret result (could be anything)
- * @param trait name of the trait
- * @param index index number of the object to extract.
- * @return #GNUNET_OK on success
- */
-static enum GNUNET_GenericReturnValue
-post_reserves_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- struct PostReservesState *prs = cls;
- struct TALER_TESTING_Trait traits[] = {
- TALER_TESTING_make_trait_reserve_pub (&prs->reserve_pub),
- TALER_TESTING_make_trait_amount (&prs->initial_balance),
- TALER_TESTING_trait_end (),
- };
-
- return TALER_TESTING_get_trait (traits,
- ret,
- trait,
- index);
-}
-
-
-/**
- * Run the "POST /reserves" CMD.
- *
- * @param cls closure.
- * @param cmd command being run now.
- * @param is interpreter state.
- */
-static void
-post_reserves_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct PostReservesState *prs = cls;
-
- prs->is = is;
- prs->prh = TALER_MERCHANT_reserves_post (
- TALER_TESTING_interpreter_get_context (is),
- prs->merchant_url,
- &prs->initial_balance,
- prs->exchange_url,
- prs->wire_method,
- &post_reserves_cb,
- prs);
- GNUNET_assert (NULL != prs->prh);
-}
-
-
-/**
- * Run the fake "POST /reserves" CMD.
- *
- * @param cls closure.
- * @param cmd command being run now.
- * @param is interpreter state.
- */
-static void
-post_reserves_fake_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct PostReservesState *prs = cls;
- struct TALER_ReservePrivateKeyP reserve_priv;
-
- prs->is = is;
- GNUNET_CRYPTO_eddsa_key_create (&reserve_priv.eddsa_priv);
- GNUNET_CRYPTO_eddsa_key_get_public (&reserve_priv.eddsa_priv,
- &prs->reserve_pub.eddsa_pub);
-
- GNUNET_assert (GNUNET_OK == TALER_string_to_amount ("EUR:100.00",
- &prs->initial_balance));
- TALER_TESTING_interpreter_next (prs->is);
-}
-
-
-/**
- * Free the state of a "POST /reserves" CMD, and possibly
- * cancel a pending operation thereof.
- *
- * @param cls closure.
- * @param cmd command being run.
- */
-static void
-post_reserves_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
-{
- struct PostReservesState *prs = cls;
-
- if (NULL != prs->prh)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "POST /reserves operation did not complete\n");
- TALER_MERCHANT_reserves_post_cancel (prs->prh);
- }
- GNUNET_free (prs);
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_post_reserves (const char *label,
- const char *merchant_url,
- const char *initial_balance,
- const char *exchange_url,
- const char *wire_method,
- unsigned int http_status)
-{
- struct PostReservesState *prs;
-
- prs = GNUNET_new (struct PostReservesState);
- prs->merchant_url = merchant_url;
- prs->exchange_url = exchange_url;
- prs->wire_method = wire_method;
- prs->http_status = http_status;
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (initial_balance,
- &prs->initial_balance));
- {
- struct TALER_TESTING_Command cmd = {
- .cls = prs,
- .label = label,
- .run = &post_reserves_run,
- .cleanup = &post_reserves_cleanup,
- .traits = &post_reserves_traits
- };
-
- return cmd;
- }
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_post_reserves_fake (const char *label)
-{
- struct PostReservesState *prs;
-
- prs = GNUNET_new (struct PostReservesState);
- {
- struct TALER_TESTING_Command cmd = {
- .cls = prs,
- .label = label,
- .run = &post_reserves_fake_run,
- .cleanup = &post_reserves_cleanup,
- .traits = &post_reserves_traits
- };
-
- return cmd;
- }
-}
diff --git a/src/testing/testing_api_cmd_reward_authorize.c b/src/testing/testing_api_cmd_reward_authorize.c
deleted file mode 100644
index 1e8579ab..00000000
--- a/src/testing/testing_api_cmd_reward_authorize.c
+++ /dev/null
@@ -1,485 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2023 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 3, or
- (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-
-/**
- * @file testing_api_cmd_reward_authorize.c
- * @brief command to test the rewardping.
- * @author Marcello Stanisci
- */
-
-#include "platform.h"
-#include <taler/taler_exchange_service.h>
-#include <taler/taler_testing_lib.h>
-#include "taler_merchant_service.h"
-#include "taler_merchant_testing_lib.h"
-
-
-/**
- * State for a /reward-authorize CMD.
- */
-struct RewardAuthorizeState
-{
-
- /**
- * Merchant base URL.
- */
- const char *merchant_url;
-
- /**
- * Expected HTTP response code.
- */
- unsigned int http_status;
-
- /**
- * Reference to the reserve to authorize the reward
- * from (if NULL, the merchant decides).
- */
- const char *reserve_reference;
-
- /**
- * Human-readable justification for the
- * reward authorization carried on by this CMD.
- */
- const char *justification;
-
- /**
- * Amount that should be authorized for rewardping.
- */
- struct TALER_Amount amount;
-
- /**
- * Expected Taler error code for this CMD.
- */
- enum TALER_ErrorCode expected_ec;
-
- /**
- * Reward taler:// URI.
- */
- char *reward_uri;
-
- /**
- * The reward id; set when the CMD succeeds.
- */
- struct TALER_RewardIdentifierP reward_id;
-
- /**
- * Expiration date for this reward.
- */
- struct GNUNET_TIME_Timestamp reward_expiration;
-
- /**
- * Handle to the on-going /reward-authorize request.
- */
- struct TALER_MERCHANT_RewardAuthorizeHandle *tao;
-
- /**
- * The interpreter state.
- */
- struct TALER_TESTING_Interpreter *is;
-
- /**
- * Task used for retries.
- */
- struct GNUNET_SCHEDULER_Task *retry_task;
-
- /**
- * How long do we wait between retries?
- */
- struct GNUNET_TIME_Relative backoff;
-
- /**
- * How many retries are left?
- */
- unsigned int retries_left;
-
-};
-
-
-/**
- * Run the main logic of talking to the merchant.
- *
- * @param cls a `struct RewardAuthorizeState`.
- */
-static void
-do_retry (void *cls);
-
-
-/**
- * Callback for a /reward-authorize request. Set into the state
- * what was returned from the backend (@a reward_id and @a
- * reward_expiration).
- *
- * @param cls closure
- * @param tar response we got
- */
-static void
-reward_authorize_cb (void *cls,
- const struct TALER_MERCHANT_RewardAuthorizeResponse *tar)
-{
- struct RewardAuthorizeState *tas = cls;
-
- tas->tao = NULL;
- if (tas->http_status != tar->hr.http_status)
- {
- if ( (MHD_HTTP_NOT_FOUND == tar->hr.http_status) &&
- (0 < tas->retries_left) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Reserve authorization failed. Reserve may not yet be ready, retrying %u more times.\n",
- tas->retries_left);
- tas->retries_left--;
- tas->backoff = GNUNET_TIME_randomized_backoff (tas->backoff,
- GNUNET_TIME_UNIT_SECONDS);
- tas->retry_task = GNUNET_SCHEDULER_add_delayed (tas->backoff,
- &do_retry,
- tas);
- return;
- }
-
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u (%d) to command %s\n",
- tar->hr.http_status,
- tar->hr.ec,
- TALER_TESTING_interpreter_get_current_label (tas->is));
- TALER_TESTING_interpreter_fail (tas->is);
- return;
- }
-
- if (tas->expected_ec != tar->hr.ec)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected error code %d (%u) to command %s\n",
- (int) tar->hr.ec,
- tar->hr.http_status,
- TALER_TESTING_interpreter_get_current_label (tas->is));
- TALER_TESTING_interpreter_fail (tas->is);
- return;
- }
- if ( (MHD_HTTP_OK == tar->hr.http_status) &&
- (TALER_EC_NONE == tar->hr.ec) )
- {
- tas->reward_uri = GNUNET_strdup (tar->details.ok.reward_uri);
- tas->reward_id = tar->details.ok.reward_id;
- tas->reward_expiration = tar->details.ok.reward_expiration;
- }
- TALER_TESTING_interpreter_next (tas->is);
-}
-
-
-/**
- * Offers information from the /reward-authorize CMD state to other
- * commands.
- *
- * @param cls closure
- * @param[out] ret result (could be anything)
- * @param trait name of the trait
- * @param index index number of the object to extract.
- * @return #GNUNET_OK on success
- */
-static enum GNUNET_GenericReturnValue
-reward_authorize_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- struct RewardAuthorizeState *tas = cls;
- struct TALER_TESTING_Trait traits[] = {
- TALER_TESTING_make_trait_reward_id (&tas->reward_id),
- TALER_TESTING_make_trait_amount (&tas->amount),
- TALER_TESTING_make_trait_reason (tas->justification),
- TALER_TESTING_make_trait_timestamp (0,
- &tas->reward_expiration),
- TALER_TESTING_trait_end (),
- };
-
- return TALER_TESTING_get_trait (traits,
- ret,
- trait,
- index);
-}
-
-
-/**
- * Runs the /reward-authorize CMD
- *
- * @param cls closure
- * @param cmd the CMD representing _this_ command
- * @param is interpreter state
- */
-static void
-reward_authorize_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct RewardAuthorizeState *tas = cls;
-
- tas->retries_left = 16;
- tas->is = is;
- tas->retry_task = GNUNET_SCHEDULER_add_now (&do_retry,
- tas);
-}
-
-
-static void
-do_retry (void *cls)
-{
- struct RewardAuthorizeState *tas = cls;
-
- tas->retry_task = NULL;
- if (NULL == tas->reserve_reference)
- {
- tas->tao = TALER_MERCHANT_reward_authorize (
- TALER_TESTING_interpreter_get_context (tas->is),
- tas->merchant_url,
- "http://merchant.com/pickup",
- &tas->amount,
- tas->justification,
- &reward_authorize_cb,
- tas);
- }
- else
- {
- const struct TALER_TESTING_Command *reserve_cmd;
- const struct TALER_ReservePublicKeyP *reserve_pub;
-
- reserve_cmd = TALER_TESTING_interpreter_lookup_command (
- tas->is,
- tas->reserve_reference);
- GNUNET_assert (GNUNET_OK ==
- TALER_TESTING_get_trait_reserve_pub (reserve_cmd,
- &reserve_pub));
- tas->tao = TALER_MERCHANT_reward_authorize2 (
- TALER_TESTING_interpreter_get_context (tas->is),
- tas->merchant_url,
- reserve_pub,
- "http://merchant.com/pickup",
- &tas->amount,
- tas->justification,
- &reward_authorize_cb,
- tas);
- }
- GNUNET_assert (NULL != tas->tao);
-}
-
-
-/**
- * Run the /reward-authorize CMD, the "fake" version of it.
- *
- * @param cls closure
- * @param cmd the CMD representing _this_ command
- * @param is interpreter state *
- */
-static void
-reward_authorize_fake_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct RewardAuthorizeState *tas = cls;
-
- /* Make up a reward id. */
- GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
- &tas->reward_id,
- sizeof (struct TALER_RewardIdentifierP));
- TALER_TESTING_interpreter_next (is);
-}
-
-
-/**
- * Free the state from a /reward-authorize CMD, and possibly
- * cancel any pending operation.
- *
- * @param cls closure
- * @param cmd the /reward-authorize CMD that is about to be freed.
- */
-static void
-reward_authorize_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
-{
- struct RewardAuthorizeState *tas = cls;
-
- if (NULL != tas->tao)
- {
- TALER_LOG_WARNING ("Reward-autorize operation"
- " did not complete\n");
- TALER_MERCHANT_reward_authorize_cancel (tas->tao);
- }
- if (NULL != tas->retry_task)
- {
- GNUNET_SCHEDULER_cancel (tas->retry_task);
- tas->retry_task = NULL;
- }
- GNUNET_free (tas->reward_uri);
- GNUNET_free (tas);
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_reward_authorize_with_ec (const char *label,
- const char *merchant_url,
- const char *exchange_url,
- unsigned int http_status,
- const char *justification,
- const char *amount,
- enum TALER_ErrorCode ec)
-{
- struct RewardAuthorizeState *tas;
-
- tas = GNUNET_new (struct RewardAuthorizeState);
- tas->merchant_url = merchant_url;
- tas->justification = justification;
- tas->http_status = http_status;
- tas->expected_ec = ec;
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (amount,
- &tas->amount));
- {
- struct TALER_TESTING_Command cmd = {
- .label = label,
- .cls = tas,
- .run = &reward_authorize_run,
- .cleanup = &reward_authorize_cleanup,
- .traits = &reward_authorize_traits
- };
-
- return cmd;
- }
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_reward_authorize_from_reserve_with_ec (
- const char *label,
- const char *merchant_url,
- const char *exchange_url,
- const char *reserve_reference,
- unsigned int http_status,
- const char *justification,
- const char *amount,
- enum TALER_ErrorCode ec)
-{
- struct RewardAuthorizeState *tas;
-
- tas = GNUNET_new (struct RewardAuthorizeState);
- tas->merchant_url = merchant_url;
- tas->justification = justification;
- tas->http_status = http_status;
- tas->expected_ec = ec;
- tas->reserve_reference = reserve_reference;
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (amount,
- &tas->amount));
- {
- struct TALER_TESTING_Command cmd = {
- .label = label,
- .cls = tas,
- .run = &reward_authorize_run,
- .cleanup = &reward_authorize_cleanup,
- .traits = &reward_authorize_traits
- };
-
- return cmd;
- }
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_reward_authorize (const char *label,
- const char *merchant_url,
- const char *exchange_url,
- unsigned int http_status,
- const char *justification,
- const char *amount)
-{
- struct RewardAuthorizeState *tas;
-
- tas = GNUNET_new (struct RewardAuthorizeState);
- tas->merchant_url = merchant_url;
- tas->justification = justification;
- tas->http_status = http_status;
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (amount,
- &tas->amount));
- {
- struct TALER_TESTING_Command cmd = {
- .label = label,
- .cls = tas,
- .run = &reward_authorize_run,
- .cleanup = &reward_authorize_cleanup,
- .traits = &reward_authorize_traits
- };
-
- return cmd;
- }
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_reward_authorize_from_reserve (const char *label,
- const char *merchant_url,
- const char *exchange_url,
- const char *reserve_reference,
- unsigned int http_status,
- const char *justification,
- const char *amount)
-{
- struct RewardAuthorizeState *tas;
-
- tas = GNUNET_new (struct RewardAuthorizeState);
- tas->merchant_url = merchant_url;
- tas->reserve_reference = reserve_reference;
- tas->justification = justification;
- tas->http_status = http_status;
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (amount,
- &tas->amount));
- {
- struct TALER_TESTING_Command cmd = {
- .label = label,
- .cls = tas,
- .run = &reward_authorize_run,
- .cleanup = &reward_authorize_cleanup,
- .traits = &reward_authorize_traits
- };
-
- return cmd;
- }
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_reward_authorize_fake (const char *label)
-{
- struct RewardAuthorizeState *tas;
-
- tas = GNUNET_new (struct RewardAuthorizeState);
- {
- struct TALER_TESTING_Command cmd = {
- .label = label,
- .cls = tas,
- .run = &reward_authorize_fake_run,
- .cleanup = &reward_authorize_cleanup,
- .traits = &reward_authorize_traits
- };
-
- return cmd;
- }
-}
-
-
-/* end of testing_api_cmd_reward_authorize.c */
diff --git a/src/testing/testing_api_cmd_reward_pickup.c b/src/testing/testing_api_cmd_reward_pickup.c
deleted file mode 100644
index 0b53b717..00000000
--- a/src/testing/testing_api_cmd_reward_pickup.c
+++ /dev/null
@@ -1,415 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 3, or
- (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-
-/**
- * @file testing_api_cmd_reward_pickup.c
- * @brief command to test picking up a reward.
- * @author Marcello Stanisci
- */
-#include "platform.h"
-#include <taler/taler_exchange_service.h>
-#include <taler/taler_testing_lib.h>
-#include "taler_merchant_service.h"
-#include "taler_merchant_testing_lib.h"
-
-/**
- * State for a /reward-pickup CMD.
- */
-struct RewardPickupState
-{
- /**
- * Merchant base URL.
- */
- const char *merchant_url;
-
- /**
- * Exchange base URL.
- */
- const char *exchange_url;
-
- /**
- * Expected HTTP response code.
- */
- unsigned int http_status;
-
- /**
- * Reference to a /reward/authorize CMD. This will be used to
- * get the reward id to make the request with.
- */
- const char *authorize_reference;
-
- /**
- * If set to non NULL, it references another pickup CMD
- * that will provide all the data which is needed to issue
- * the request (like planchet secrets, denomination keys..).
- */
- const char *replay_reference;
-
- /**
- * Handle to a on-going /reward/pickup request.
- */
- struct TALER_MERCHANT_RewardPickupHandle *tpo;
-
- /**
- * The interpreter state.
- */
- struct TALER_TESTING_Interpreter *is;
-
- /**
- * An array of string-defined amounts that indicates
- * which denominations are going to be used to receive
- * rewards.
- */
- const char **amounts;
-
- /**
- * The object version of the above @a amounts.
- */
- struct TALER_Amount *amounts_obj;
-
- /**
- * The sum of the the amounts above.
- */
- struct TALER_Amount total_amount;
-
- /**
- * The array of denomination keys, in the same order of @a
- * amounts.
- */
- const struct TALER_EXCHANGE_DenomPublicKey **dks;
-
- /**
- * The array of planchet secrets, in the same order of @a
- * amounts.
- */
- struct TALER_PlanchetMasterSecretP *psa;
-
- /**
- * Set (by the interpreter) to an array of @a num_coins
- * details on coins created from the (successful) reward operation.
- */
- struct TALER_EXCHANGE_PrivateCoinDetails *pcds;
-
- /**
- * How many coins are involved in the rewardping operation.
- */
- uint32_t num_coins;
-
- /**
- * Expected Taler error code (NOTE: this is NOT the HTTP
- * response code).
- */
- enum TALER_ErrorCode expected_ec;
-};
-
-
-/**
- * Callback for a /reward-pickup request, it mainly checks if
- * values returned from the backend are as expected, and if so
- * (and if the status was 200 OK) proceede with the withdrawal.
- *
- * @param cls closure
- * @param pd details about the result of the operation
- */
-static void
-pickup_cb (void *cls,
- const struct TALER_MERCHANT_PickupDetails *pd)
-{
- struct RewardPickupState *tps = cls;
-
- tps->tpo = NULL;
- if (pd->hr.http_status != tps->http_status)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u (%d) to command %s\n",
- pd->hr.http_status,
- (int) pd->hr.ec,
- TALER_TESTING_interpreter_get_current_label (tps->is));
- TALER_TESTING_FAIL (tps->is);
- }
-
- if (pd->hr.ec != tps->expected_ec)
- TALER_TESTING_FAIL (tps->is);
-
- /* Safe to go ahead: http status was expected. */
- if ( (MHD_HTTP_OK != pd->hr.http_status) ||
- (TALER_EC_NONE != pd->hr.ec) )
- {
- TALER_TESTING_interpreter_next (tps->is);
- return;
- }
- if (pd->details.ok.num_sigs != tps->num_coins)
- TALER_TESTING_FAIL (tps->is);
- tps->pcds = GNUNET_new_array (tps->num_coins,
- struct TALER_EXCHANGE_PrivateCoinDetails);
- for (unsigned int i = 0; i<tps->num_coins; i++)
- {
- struct TALER_EXCHANGE_PrivateCoinDetails *pcd =
- &pd->details.ok.pcds[i];
-
- tps->pcds[i] = *pcd;
- TALER_denom_sig_copy (&tps->pcds[i].sig,
- &pcd->sig);
- }
- TALER_TESTING_interpreter_next (tps->is);
-}
-
-
-/**
- * Run a /reward-pickup CMD.
- *
- * @param cls closure
- * @param cmd the current /reward-pickup CMD.
- * @param is interpreter state.
- */
-static void
-reward_pickup_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct RewardPickupState *tps = cls;
- unsigned int num_planchets;
- const struct TALER_TESTING_Command *replay_cmd;
- const struct TALER_TESTING_Command *authorize_cmd;
- const struct TALER_RewardIdentifierP *reward_id;
-
- tps->is = is;
- tps->exchange_url = TALER_TESTING_get_exchange_url (is);
- if (NULL == tps->replay_reference)
- {
- replay_cmd = NULL;
-
- /* Count planchets. */
- for (num_planchets = 0;
- NULL != tps->amounts[num_planchets];
- num_planchets++)
- ;
- }
- else
- {
- const uint32_t *np;
-
- if (NULL == /* looking for "parent" reward-pickup command */
- (replay_cmd
- = TALER_TESTING_interpreter_lookup_command (is,
- tps->replay_reference)) )
- TALER_TESTING_FAIL (is);
-
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_num_planchets (replay_cmd,
- &np))
- TALER_TESTING_FAIL (is);
- num_planchets = *np;
- }
-
- if (NULL ==
- (authorize_cmd
- = TALER_TESTING_interpreter_lookup_command (is,
- tps->authorize_reference)) )
- TALER_TESTING_FAIL (is);
-
- tps->num_coins = num_planchets;
- {
- struct TALER_MERCHANT_PlanchetData planchets[num_planchets];
-
- tps->psa = GNUNET_new_array (num_planchets,
- struct TALER_PlanchetMasterSecretP);
- tps->dks = GNUNET_new_array (num_planchets,
- const struct TALER_EXCHANGE_DenomPublicKey *);
- tps->amounts_obj = GNUNET_new_array (num_planchets,
- struct TALER_Amount);
- for (unsigned int i = 0; i<num_planchets; i++)
- {
- if (NULL == replay_cmd)
- {
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (tps->amounts[i],
- &tps->amounts_obj[i]));
- if (0 == i)
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (tps->amounts_obj[i].currency,
- &tps->total_amount));
-
- GNUNET_assert (0 <
- TALER_amount_add (&tps->total_amount,
- &tps->total_amount,
- &tps->amounts_obj[i]));
- tps->dks[i] = TALER_TESTING_find_pk (
- TALER_TESTING_get_keys (is),
- &tps->amounts_obj[i],
- false);
- if (NULL == tps->dks[i])
- TALER_TESTING_FAIL (is);
- TALER_planchet_master_setup_random (&tps->psa[i]);
- }
- else
- {
- const struct TALER_PlanchetMasterSecretP *ps;
-
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_denom_pub (replay_cmd,
- i,
- &tps->dks[i]))
- TALER_TESTING_FAIL (is);
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_planchet_secrets (replay_cmd,
- i,
- &ps))
- TALER_TESTING_FAIL (is);
- tps->psa[i] = *ps;
- }
- planchets[i].pk = tps->dks[i];
- planchets[i].ps = tps->psa[i];
- }
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_reward_id (authorize_cmd,
- &reward_id))
- TALER_TESTING_FAIL (is);
- tps->tpo = TALER_MERCHANT_reward_pickup (
- TALER_TESTING_interpreter_get_context (is),
- TALER_TESTING_get_exchange_url (is),
- tps->merchant_url,
- reward_id,
- num_planchets,
- planchets,
- &pickup_cb,
- tps);
- GNUNET_assert (NULL != tps->tpo);
- }
-}
-
-
-/**
- * Free a /reward-pickup CMD state, and possibly cancel a
- * pending /reward-pickup request.
- *
- * @param cls closure.
- * @param cmd current CMD to be freed.
- */
-static void
-reward_pickup_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
-{
- struct RewardPickupState *tps = cls;
-
- GNUNET_free (tps->amounts_obj);
- GNUNET_free (tps->dks);
- GNUNET_free (tps->psa);
- if (NULL != tps->pcds)
- {
- for (unsigned int i = 0; i<tps->num_coins; i++)
- TALER_denom_sig_free (&tps->pcds[i].sig);
- GNUNET_free (tps->pcds);
- }
- if (NULL != tps->tpo)
- {
- TALER_LOG_WARNING ("Reward-pickup operation did not complete\n");
- TALER_MERCHANT_reward_pickup_cancel (tps->tpo);
- }
- GNUNET_free (tps);
-}
-
-
-static enum GNUNET_GenericReturnValue
-reward_pickup_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- struct RewardPickupState *tps = cls;
-
- if (index >= tps->num_coins)
- return GNUNET_SYSERR;
- {
- struct TALER_TESTING_Trait traits[] = {
- TALER_TESTING_make_trait_planchet_secrets (index,
- &tps->psa[index]),
- TALER_TESTING_make_trait_coin_priv (index,
- &tps->pcds[index].coin_priv),
- TALER_TESTING_make_trait_denom_pub (index,
- tps->dks[index]),
- TALER_TESTING_make_trait_denom_sig (index,
- &tps->pcds[index].sig),
- TALER_TESTING_make_trait_amounts (index,
- &tps->amounts_obj[index]),
- TALER_TESTING_make_trait_amount (&tps->total_amount),
- TALER_TESTING_make_trait_num_planchets (&tps->num_coins),
- TALER_TESTING_make_trait_exchange_url (tps->exchange_url),
- TALER_TESTING_trait_end ()
- };
-
- return TALER_TESTING_get_trait (traits,
- ret,
- trait,
- index);
- }
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_reward_pickup (const char *label,
- const char *merchant_url,
- unsigned int http_status,
- const char *authorize_reference,
- const char **amounts)
-{
- struct RewardPickupState *tps;
-
- tps = GNUNET_new (struct RewardPickupState);
- tps->merchant_url = merchant_url;
- tps->authorize_reference = authorize_reference;
- tps->amounts = amounts;
- tps->http_status = http_status;
- {
- struct TALER_TESTING_Command cmd = {
- .cls = tps,
- .label = label,
- .run = &reward_pickup_run,
- .cleanup = &reward_pickup_cleanup,
- .traits = &reward_pickup_traits
- };
-
- return cmd;
- }
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_reward_pickup_with_ec (const char *label,
- const char *merchant_url,
- unsigned int http_status,
- const char *authorize_reference,
- const char **amounts,
- enum TALER_ErrorCode ec)
-{
- struct TALER_TESTING_Command cmd;
- struct RewardPickupState *tps;
-
- cmd = TALER_TESTING_cmd_reward_pickup (label,
- merchant_url,
- http_status,
- authorize_reference,
- amounts);
- tps = cmd.cls;
- tps->expected_ec = ec;
- return cmd;
-}
-
-
-/* end of testing_api_cmd_reward_pickup.c */
diff --git a/src/testing/testing_api_cmd_wallet_get_reward.c b/src/testing/testing_api_cmd_wallet_get_reward.c
deleted file mode 100644
index 661b31f2..00000000
--- a/src/testing/testing_api_cmd_wallet_get_reward.c
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2020 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 3, or
- (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file testing_api_cmd_wallet_get_reward.c
- * @brief command to test the rewardping.
- * @author Marcello Stanisci
- */
-#include "platform.h"
-#include <taler/taler_exchange_service.h>
-#include <taler/taler_testing_lib.h>
-#include "taler_merchant_service.h"
-#include "taler_merchant_testing_lib.h"
-
-
-/**
- * State for a GET /rewards/$REWARD_ID CMD.
- */
-struct WalletRewardGetState
-{
-
- /**
- * The merchant base URL.
- */
- const char *merchant_url;
-
- /**
- * Expected HTTP response code for this CMD.
- */
- unsigned int http_status;
-
- /**
- * Whether to compare amounts or not.
- */
- bool cmp_amounts;
-
- /**
- * The expected amount remaining.
- */
- struct TALER_Amount amount_remaining;
-
- /**
- * The handle to the current GET /rewards/$REWARD_ID request.
- */
- struct TALER_MERCHANT_RewardWalletGetHandle *tgh;
-
- /**
- * The interpreter state.
- */
- struct TALER_TESTING_Interpreter *is;
-
- /**
- * Reference to a command that created a reward.
- */
- const char *reward_reference;
-};
-
-
-/**
- * Callback to process a GET /rewards/$REWARD_ID request, it mainly
- * checks that what the backend returned matches the command's
- * expectations.
- *
- * @param cls closure
- * @param wgr response
- */
-static void
-wallet_reward_get_cb (void *cls,
- const struct TALER_MERCHANT_RewardWalletGetResponse *wgr)
-{
- struct WalletRewardGetState *gts = cls;
- const struct TALER_TESTING_Command *reward_cmd;
-
- reward_cmd = TALER_TESTING_interpreter_lookup_command (
- gts->is,
- gts->reward_reference);
-
- gts->tgh = NULL;
- if (gts->http_status != wgr->hr.http_status)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u (%d) to command %s\n",
- wgr->hr.http_status,
- (int) wgr->hr.ec,
- TALER_TESTING_interpreter_get_current_label (gts->is));
- TALER_TESTING_interpreter_fail (gts->is);
- return;
- }
- switch (wgr->hr.http_status)
- {
- case MHD_HTTP_OK:
- if (gts->cmp_amounts)
- {
- if ((GNUNET_OK !=
- TALER_amount_cmp_currency (&gts->amount_remaining,
- &wgr->details.ok.amount_remaining))
- ||
- (0 != TALER_amount_cmp (&gts->amount_remaining,
- &wgr->details.ok.amount_remaining)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Amount remaining on reward does not match\n");
- TALER_TESTING_interpreter_fail (gts->is);
- return;
- }
- }
- {
- const struct GNUNET_TIME_Timestamp *expiration;
-
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_timestamp (reward_cmd,
- 0,
- &expiration))
- TALER_TESTING_interpreter_fail (gts->is);
- if (GNUNET_TIME_timestamp_cmp (*expiration,
- !=,
- wgr->details.ok.expiration))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Reward expiration does not match\n");
- TALER_TESTING_interpreter_fail (gts->is);
- return;
- }
- }
- break;
- default:
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Unhandled HTTP status.\n");
- }
- TALER_TESTING_interpreter_next (gts->is);
-}
-
-
-/**
- * Run the "GET reward" CMD.
- *
- * @param cls closure.
- * @param cmd command being run now.
- * @param is interpreter state.
- */
-static void
-wallet_get_reward_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct WalletRewardGetState *tgs = cls;
- const struct TALER_TESTING_Command *reward_cmd;
- const struct TALER_RewardIdentifierP *reward_id;
-
- reward_cmd = TALER_TESTING_interpreter_lookup_command (is,
- tgs->reward_reference);
-
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_reward_id (reward_cmd,
- &reward_id))
- TALER_TESTING_FAIL (is);
-
- tgs->is = is;
- tgs->tgh = TALER_MERCHANT_wallet_reward_get (
- TALER_TESTING_interpreter_get_context (is),
- tgs->merchant_url,
- reward_id,
- &wallet_reward_get_cb,
- tgs);
-}
-
-
-/**
- * Free the state of a "GET reward" CMD, and possibly
- * cancel a pending operation thereof.
- *
- * @param cls closure.
- * @param cmd command being run.
- */
-static void
-wallet_get_reward_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
-{
- struct WalletRewardGetState *tgs = cls;
-
- if (NULL != tgs->tgh)
- {
- TALER_LOG_WARNING ("Get reward operation did not complete\n");
- TALER_MERCHANT_wallet_reward_get_cancel (tgs->tgh);
- }
- GNUNET_free (tgs);
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_wallet_get_reward (const char *label,
- const char *merchant_url,
- const char *reward_reference,
- unsigned int http_status)
-{
- struct WalletRewardGetState *tgs;
-
- tgs = GNUNET_new (struct WalletRewardGetState);
- tgs->merchant_url = merchant_url;
- tgs->reward_reference = reward_reference;
- tgs->http_status = http_status;
- {
- struct TALER_TESTING_Command cmd = {
- .cls = tgs,
- .label = label,
- .run = &wallet_get_reward_run,
- .cleanup = &wallet_get_reward_cleanup
- };
-
- return cmd;
- }
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_wallet_get_reward2 (const char *label,
- const char *merchant_url,
- const char *reward_reference,
- const char *amount_remaining,
- unsigned int http_status)
-{
- struct WalletRewardGetState *tgs;
-
- tgs = GNUNET_new (struct WalletRewardGetState);
- tgs->merchant_url = merchant_url;
- tgs->reward_reference = reward_reference;
- tgs->cmp_amounts = true;
- GNUNET_assert (GNUNET_OK == TALER_string_to_amount (amount_remaining,
- &tgs->amount_remaining));
- tgs->http_status = http_status;
- {
- struct TALER_TESTING_Command cmd = {
- .cls = tgs,
- .label = label,
- .run = &wallet_get_reward_run,
- .cleanup = &wallet_get_reward_cleanup
- };
-
- return cmd;
- }
-}
-
-
-/* end of testing_api_cmd_wallet_get_reward.c */