diff options
Diffstat (limited to 'src/lib/merchant_api_tip_authorize.c')
-rw-r--r-- | src/lib/merchant_api_tip_authorize.c | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/lib/merchant_api_tip_authorize.c b/src/lib/merchant_api_tip_authorize.c index 2a172387..4604fc0c 100644 --- a/src/lib/merchant_api_tip_authorize.c +++ b/src/lib/merchant_api_tip_authorize.c @@ -309,6 +309,93 @@ TALER_MERCHANT_tip_authorize2 ( /** + * Issue a POST /tips request to the backend. Informs the backend that a tip + * should be created. In contrast to #TALER_MERCHANT_tip_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 tip + * @param amount amount to be handed out as a tip + * @param justification which justification should be stored (human-readable reason for the tip) + * @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_TipAuthorizeHandle * +TALER_MERCHANT_tip_authorize (struct GNUNET_CURL_Context *ctx, + const char *backend_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 *tao; + CURL *eh; + json_t *te_obj; + + 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, + "/tips", + NULL); + if (NULL == tao->url) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not construct request URL.\n"); + GNUNET_free (tao); + return NULL; + } + te_obj = json_pack ("{" + " s:o," /* amount */ + " s:s," /* justification */ + " s:s," /* next_url */ + "}", + "amount", TALER_JSON_from_amount (amount), + "justification", justification, + "next_url", next_url); + if (NULL == te_obj) + { + GNUNET_break (0); + GNUNET_free (tao->url); + GNUNET_free (tao); + return NULL; + } + + eh = curl_easy_init (); + if (GNUNET_OK != TALER_curl_easy_post (&tao->post_ctx, + eh, + te_obj)) + { + GNUNET_break (0); + 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_tip_authorize_finished, + tao); + return tao; +} + + +/** * Cancel a /track/transaction request. This function cannot be used * on a request handle if a response is already served for it. * |