diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-05-31 15:06:00 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-05-31 15:06:00 +0200 |
commit | a043dd973bad7c46f1bb222ccacc935b76141d37 (patch) | |
tree | 051533ab4f1e64b155e0a499aa5f680d89f70e65 /src/lib | |
parent | 059797b86a96e95ca4d61ccbcec690620957aaf9 (diff) |
work on tip APIs
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/merchant_api_tip_authorize.c | 73 | ||||
-rw-r--r-- | src/lib/merchant_api_tip_pickup.c | 16 | ||||
-rw-r--r-- | src/lib/merchant_api_tip_pickup2.c | 18 | ||||
-rw-r--r-- | src/lib/merchant_api_tip_query.c | 79 |
4 files changed, 101 insertions, 85 deletions
diff --git a/src/lib/merchant_api_tip_authorize.c b/src/lib/merchant_api_tip_authorize.c index 37ad3904..2a172387 100644 --- a/src/lib/merchant_api_tip_authorize.c +++ b/src/lib/merchant_api_tip_authorize.c @@ -35,7 +35,7 @@ /** * @brief A handle for tip authorizations. */ -struct TALER_MERCHANT_TipAuthorizeOperation +struct TALER_MERCHANT_TipAuthorizeHandle { /** @@ -80,13 +80,15 @@ struct TALER_MERCHANT_TipAuthorizeOperation * @return #GNUNET_OK if response is valid */ static int -check_ok (struct TALER_MERCHANT_TipAuthorizeOperation *tao, +check_ok (struct TALER_MERCHANT_TipAuthorizeHandle *tao, const json_t *json) { - const char *taler_tip_uri; + const char *taler_tip_url; struct GNUNET_HashCode tip_id; + struct GNUNET_TIME_Absolute expiration_time; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_string ("taler_tip_uri", &taler_tip_uri), + GNUNET_JSON_spec_string ("tip_redirect_url", &taler_tip_url), + GNUNET_JSON_spec_absolute_time ("tip_expiration", &expiration_time), GNUNET_JSON_spec_fixed_auto ("tip_id", &tip_id), GNUNET_JSON_spec_end () }; @@ -114,7 +116,8 @@ check_ok (struct TALER_MERCHANT_TipAuthorizeOperation *tao, tao->cb (tao->cb_cls, &hr, &tip_id, - taler_tip_uri); + taler_tip_url, + expiration_time); tao->cb = NULL; /* do not call twice */ GNUNET_JSON_parse_free (spec); return GNUNET_OK; @@ -123,9 +126,9 @@ check_ok (struct TALER_MERCHANT_TipAuthorizeOperation *tao, /** * Function called when we're done processing the - * HTTP /track/transaction request. + * HTTP /reservers/$TIP_ID/tip-authorize request. * - * @param cls the `struct TALER_MERCHANT_TipAuthorizeOperation` + * @param cls the `struct TALER_MERCHANT_TipAuthorizeHandle` * @param response_code HTTP response code, 0 on error * @param json response body, NULL if not in JSON */ @@ -134,7 +137,7 @@ handle_tip_authorize_finished (void *cls, long response_code, const void *response) { - struct TALER_MERCHANT_TipAuthorizeOperation *tao = cls; + struct TALER_MERCHANT_TipAuthorizeHandle *tao = cls; const json_t *json = response; struct TALER_MERCHANT_HttpResponse hr = { .http_status = (unsigned int) response_code, @@ -195,7 +198,8 @@ handle_tip_authorize_finished (void *cls, tao->cb (tao->cb_cls, &hr, NULL, - NULL); + NULL, + GNUNET_TIME_UNIT_ZERO_ABS); TALER_MERCHANT_tip_authorize_cancel (tao); } @@ -206,7 +210,7 @@ handle_tip_authorize_finished (void *cls, * * @param ctx execution context * @param backend_url base URL of the merchant backend - * @param pickup_url frontend URL for where the tip can be picked up + * @param reserve_pub public key of the reserve * @param next_url where the browser should proceed after picking up the tip * @param amount amount to be handed out as a tip * @param justification which justification should be stored (human-readable reason for the tip) @@ -214,27 +218,44 @@ handle_tip_authorize_finished (void *cls, * @param authorize_cb_cls closure to pass to @a authorize_cb * @return handle for this operation, NULL upon errors */ -struct TALER_MERCHANT_TipAuthorizeOperation * -TALER_MERCHANT_tip_authorize (struct GNUNET_CURL_Context *ctx, - const char *backend_url, - const char *pickup_url, - const char *next_url, - const struct TALER_Amount *amount, - const char *justification, - TALER_MERCHANT_TipAuthorizeCallback authorize_cb, - void *authorize_cb_cls) +struct TALER_MERCHANT_TipAuthorizeHandle * +TALER_MERCHANT_tip_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_TipAuthorizeCallback authorize_cb, + void *authorize_cb_cls) { - struct TALER_MERCHANT_TipAuthorizeOperation *tao; + struct TALER_MERCHANT_TipAuthorizeHandle *tao; CURL *eh; json_t *te_obj; - tao = GNUNET_new (struct TALER_MERCHANT_TipAuthorizeOperation); + tao = GNUNET_new (struct TALER_MERCHANT_TipAuthorizeHandle); tao->ctx = ctx; tao->cb = authorize_cb; tao->cb_cls = authorize_cb_cls; - tao->url = TALER_url_join (backend_url, - "tip-authorize", - NULL); + + { + char res_str[sizeof (struct GNUNET_HashCode) * 2]; + char arg_str[sizeof (struct TALER_CoinSpendPublicKeyP) * 2 + 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), + "/reserves/%s/tip-authorize", + res_str); + tao->url = TALER_url_join (backend_url, + arg_str, + NULL); + } if (NULL == tao->url) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -245,12 +266,10 @@ TALER_MERCHANT_tip_authorize (struct GNUNET_CURL_Context *ctx, te_obj = json_pack ("{" " s:o," /* amount */ " s:s," /* justification */ - " s:s," /* pickup_url */ " s:s," /* next_url */ "}", "amount", TALER_JSON_from_amount (amount), "justification", justification, - "pickup_url", pickup_url, "next_url", next_url); if (NULL == te_obj) { @@ -297,7 +316,7 @@ TALER_MERCHANT_tip_authorize (struct GNUNET_CURL_Context *ctx, */ void TALER_MERCHANT_tip_authorize_cancel ( - struct TALER_MERCHANT_TipAuthorizeOperation *tao) + struct TALER_MERCHANT_TipAuthorizeHandle *tao) { if (NULL != tao->job) { diff --git a/src/lib/merchant_api_tip_pickup.c b/src/lib/merchant_api_tip_pickup.c index 6e48f169..08f59359 100644 --- a/src/lib/merchant_api_tip_pickup.c +++ b/src/lib/merchant_api_tip_pickup.c @@ -57,7 +57,7 @@ struct PlanchetData /** * Handle for a /tip-pickup operation. */ -struct TALER_MERCHANT_TipPickupOperation +struct TALER_MERCHANT_TipPickupHandle { /** @@ -73,7 +73,7 @@ struct TALER_MERCHANT_TipPickupOperation /** * Handle for the actual (internal) withdraw operation. */ - struct TALER_MERCHANT_TipPickup2Operation *tpo2; + struct TALER_MERCHANT_TipPickup2Handle *tpo2; /** * Number of planchets/coins used for this operation. @@ -92,7 +92,7 @@ struct TALER_MERCHANT_TipPickupOperation * Callback for a /tip-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_TipPickupOperation *` + * @param cls closure, a `struct TALER_MERCHANT_TipPickupHandle *` * @param hr HTTP response details * @param num_blind_sigs length of the @a reserve_sigs array, 0 on error * @param blind_sigs array of blind signatures over the planchets, NULL on error @@ -103,7 +103,7 @@ pickup_done_cb (void *cls, unsigned int num_blind_sigs, const struct TALER_MERCHANT_BlindSignature *blind_sigs) { - struct TALER_MERCHANT_TipPickupOperation *tp = cls; + struct TALER_MERCHANT_TipPickupHandle *tp = cls; tp->tpo2 = NULL; if (NULL == blind_sigs) @@ -180,7 +180,7 @@ pickup_done_cb (void *cls, * @param pickup_cb_cls closure to pass to @a pickup_cb * @return handle for this operation, NULL upon errors */ -struct TALER_MERCHANT_TipPickupOperation * +struct TALER_MERCHANT_TipPickupHandle * TALER_MERCHANT_tip_pickup (struct GNUNET_CURL_Context *ctx, const char *backend_url, const struct GNUNET_HashCode *tip_id, @@ -189,7 +189,7 @@ TALER_MERCHANT_tip_pickup (struct GNUNET_CURL_Context *ctx, TALER_MERCHANT_TipPickupCallback pickup_cb, void *pickup_cb_cls) { - struct TALER_MERCHANT_TipPickupOperation *tp; + struct TALER_MERCHANT_TipPickupHandle *tp; struct TALER_PlanchetDetail details[GNUNET_NZL (num_planchets)]; if (0 == num_planchets) @@ -197,7 +197,7 @@ TALER_MERCHANT_tip_pickup (struct GNUNET_CURL_Context *ctx, GNUNET_break (0); return NULL; } - tp = GNUNET_new (struct TALER_MERCHANT_TipPickupOperation); + tp = GNUNET_new (struct TALER_MERCHANT_TipPickupHandle); GNUNET_array_grow (tp->planchets, tp->num_planchets, num_planchets); @@ -249,7 +249,7 @@ TALER_MERCHANT_tip_pickup (struct GNUNET_CURL_Context *ctx, * @param tp handle from the operation to cancel */ void -TALER_MERCHANT_tip_pickup_cancel (struct TALER_MERCHANT_TipPickupOperation *tp) +TALER_MERCHANT_tip_pickup_cancel (struct TALER_MERCHANT_TipPickupHandle *tp) { for (unsigned int i = 0; i<tp->num_planchets; i++) GNUNET_CRYPTO_rsa_public_key_dup (tp->planchets[i].pk.key.rsa_public_key); diff --git a/src/lib/merchant_api_tip_pickup2.c b/src/lib/merchant_api_tip_pickup2.c index 751d1267..a06de612 100644 --- a/src/lib/merchant_api_tip_pickup2.c +++ b/src/lib/merchant_api_tip_pickup2.c @@ -35,7 +35,7 @@ /** * @brief A handle for tracking transactions. */ -struct TALER_MERCHANT_TipPickup2Operation +struct TALER_MERCHANT_TipPickup2Handle { /** @@ -85,7 +85,7 @@ struct TALER_MERCHANT_TipPickup2Operation * @return #GNUNET_OK if response is valid */ static int -check_ok (struct TALER_MERCHANT_TipPickup2Operation *tpo, +check_ok (struct TALER_MERCHANT_TipPickup2Handle *tpo, const json_t *json) { json_t *ja; @@ -154,7 +154,7 @@ check_ok (struct TALER_MERCHANT_TipPickup2Operation *tpo, * Function called when we're done processing the * HTTP /track/transaction request. * - * @param cls the `struct TALER_MERCHANT_TipPickupOperation` + * @param cls the `struct TALER_MERCHANT_TipPickupHandle` * @param response_code HTTP response code, 0 on error * @param json response body, NULL if not in JSON */ @@ -163,7 +163,7 @@ handle_tip_pickup_finished (void *cls, long response_code, const void *response) { - struct TALER_MERCHANT_TipPickup2Operation *tpo = cls; + struct TALER_MERCHANT_TipPickup2Handle *tpo = cls; const json_t *json = response; struct TALER_MERCHANT_HttpResponse hr = { .http_status = (unsigned int) response_code, @@ -235,16 +235,16 @@ handle_tip_pickup_finished (void *cls, * @param pickup_cb_cls closure to pass to @a pickup_cb * @return handle for this operation, NULL upon errors */ -struct TALER_MERCHANT_TipPickup2Operation * +struct TALER_MERCHANT_TipPickup2Handle * TALER_MERCHANT_tip_pickup2 (struct GNUNET_CURL_Context *ctx, const char *backend_url, const struct GNUNET_HashCode *tip_id, unsigned int num_planchets, - struct TALER_PlanchetDetail *planchets, + const struct TALER_PlanchetDetail planchets[], TALER_MERCHANT_TipPickup2Callback pickup_cb, void *pickup_cb_cls) { - struct TALER_MERCHANT_TipPickup2Operation *tpo; + struct TALER_MERCHANT_TipPickup2Handle *tpo; CURL *eh; json_t *pa; json_t *tp_obj; @@ -294,7 +294,7 @@ TALER_MERCHANT_tip_pickup2 (struct GNUNET_CURL_Context *ctx, GNUNET_break (0); return NULL; } - tpo = GNUNET_new (struct TALER_MERCHANT_TipPickup2Operation); + tpo = GNUNET_new (struct TALER_MERCHANT_TipPickup2Handle); tpo->num_planchets = num_planchets; tpo->ctx = ctx; tpo->cb = pickup_cb; @@ -347,7 +347,7 @@ TALER_MERCHANT_tip_pickup2 (struct GNUNET_CURL_Context *ctx, */ void TALER_MERCHANT_tip_pickup2_cancel ( - struct TALER_MERCHANT_TipPickup2Operation *tpo) + struct TALER_MERCHANT_TipPickup2Handle *tpo) { if (NULL != tpo->job) { diff --git a/src/lib/merchant_api_tip_query.c b/src/lib/merchant_api_tip_query.c index 250d26d0..b25fac85 100644 --- a/src/lib/merchant_api_tip_query.c +++ b/src/lib/merchant_api_tip_query.c @@ -15,7 +15,7 @@ <http://www.gnu.org/licenses/> */ /** - * @file lib/merchant_api_tip_query.c + * @file lib/merchant_api_tip_query.c => FIXME: rename! * @brief Implementation of the /tip-query request of the merchant's HTTP API * @author Florian Dold */ @@ -31,9 +31,9 @@ /** - * @brief A handle for tracking /tip-query operations + * @brief A handle for tracking /tip-get operations */ -struct TALER_MERCHANT_TipQueryOperation +struct TALER_MERCHANT_TipGetHandle { /** * The url for this request. @@ -48,7 +48,7 @@ struct TALER_MERCHANT_TipQueryOperation /** * Function to call with the result. */ - TALER_MERCHANT_TipQueryCallback cb; + TALER_MERCHANT_TipGetCallback cb; /** * Closure for @a cb. @@ -67,16 +67,16 @@ struct TALER_MERCHANT_TipQueryOperation * Function called when we're done processing the * HTTP /track/transaction request. * - * @param cls the `struct TALER_MERCHANT_TipQueryOperation` + * @param cls the `struct TALER_MERCHANT_TipGetHandle` * @param response_code HTTP response code, 0 on error * @param json response body, NULL if not in JSON */ static void -handle_tip_query_finished (void *cls, - long response_code, - const void *response) +handle_tip_get_finished (void *cls, + long response_code, + const void *response) { - struct TALER_MERCHANT_TipQueryOperation *tqo = cls; + struct TALER_MERCHANT_TipGetHandle *tqo = cls; const json_t *json = response; struct TALER_MERCHANT_HttpResponse hr = { .http_status = (unsigned int) response_code, @@ -84,7 +84,7 @@ handle_tip_query_finished (void *cls, }; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Got /tip-query response with status code %u\n", + "Got /tip-get response with status code %u\n", (unsigned int) response_code); tqo->job = NULL; @@ -93,17 +93,14 @@ handle_tip_query_finished (void *cls, case MHD_HTTP_OK: { struct GNUNET_TIME_Absolute reserve_expiration; - struct TALER_Amount amount_authorized; - struct TALER_Amount amount_available; - struct TALER_Amount amount_picked_up; + const char *exchange_url; + struct TALER_Amount amount_remaining; struct TALER_ReservePublicKeyP reserve_pub; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_fixed_auto ("reserve_pub", &reserve_pub), - GNUNET_JSON_spec_absolute_time ("reserve_expiration", - &reserve_expiration), - TALER_JSON_spec_amount ("amount_authorized", &amount_authorized), - TALER_JSON_spec_amount ("amount_available", &amount_available), - TALER_JSON_spec_amount ("amount_picked_up", &amount_picked_up), + GNUNET_JSON_spec_string ("exchange_url", + &exchange_url), + TALER_JSON_spec_amount ("amount_remaining", &amount_remaining), GNUNET_JSON_spec_end () }; @@ -120,11 +117,9 @@ handle_tip_query_finished (void *cls, tqo->cb (tqo->cb_cls, &hr, reserve_expiration, - &reserve_pub, - &amount_authorized, - &amount_available, - &amount_picked_up); - TALER_MERCHANT_tip_query_cancel (tqo); + exchange_url, + &amount_remaining); + TALER_MERCHANT_tip_get_cancel (tqo); return; } case MHD_HTTP_INTERNAL_SERVER_ERROR: @@ -154,36 +149,38 @@ handle_tip_query_finished (void *cls, &hr, GNUNET_TIME_UNIT_ZERO_ABS, NULL, - NULL, - NULL, NULL); - TALER_MERCHANT_tip_query_cancel (tqo); + TALER_MERCHANT_tip_get_cancel (tqo); } /** - * Issue a /tip-query request to the backend. Informs the backend + * Issue a /tip-get request to the backend. Informs the backend * that a customer wants to pick up a tip. * * @param ctx execution context * @param backend_url base URL of the merchant backend + * @param tip_id which tip 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_TipQueryOperation * -TALER_MERCHANT_tip_query (struct GNUNET_CURL_Context *ctx, - const char *backend_url, - TALER_MERCHANT_TipQueryCallback query_cb, - void *query_cb_cls) +struct TALER_MERCHANT_TipGetHandle * +TALER_MERCHANT_tip_get (struct GNUNET_CURL_Context *ctx, + const char *backend_url, + const struct GNUNET_HashCode *tip_id, + TALER_MERCHANT_TipGetCallback cb, + void *cb_cls) { - struct TALER_MERCHANT_TipQueryOperation *tqo; + struct TALER_MERCHANT_TipGetHandle *tqo; CURL *eh; - tqo = GNUNET_new (struct TALER_MERCHANT_TipQueryOperation); + tqo = GNUNET_new (struct TALER_MERCHANT_TipGetHandle); tqo->ctx = ctx; - tqo->cb = query_cb; - tqo->cb_cls = query_cb_cls; + tqo->cb = cb; + tqo->cb_cls = cb_cls; tqo->url = TALER_url_join (backend_url, - "tip-query", + "tip-get", NULL); if (NULL == tqo->url) { @@ -206,20 +203,20 @@ TALER_MERCHANT_tip_query (struct GNUNET_CURL_Context *ctx, tqo->job = GNUNET_CURL_job_add (ctx, eh, GNUNET_YES, - &handle_tip_query_finished, + &handle_tip_get_finished, tqo); return tqo; } /** - * Cancel a /tip-query request. This function cannot be used + * Cancel a /tip-get request. This function cannot be used * on a request handle if a response is already served for it. * * @param tqo handle to the operation being cancelled */ void -TALER_MERCHANT_tip_query_cancel (struct TALER_MERCHANT_TipQueryOperation *tqo) +TALER_MERCHANT_tip_get_cancel (struct TALER_MERCHANT_TipGetHandle *tqo) { if (NULL != tqo->job) { @@ -231,4 +228,4 @@ TALER_MERCHANT_tip_query_cancel (struct TALER_MERCHANT_TipQueryOperation *tqo) } -/* end of merchant_api_tip_query.c */ +/* end of merchant_api_tip_get.c */ |