[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-merchant] 159/277: add POST /tips logic
From: |
gnunet |
Subject: |
[taler-merchant] 159/277: add POST /tips logic |
Date: |
Sun, 05 Jul 2020 20:51:12 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository merchant.
commit 48ea83ffb0b7f8f57649e66352c8962efaaeb0b7
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun May 31 15:07:48 2020 +0200
add POST /tips logic
---
src/lib/merchant_api_tip_authorize.c | 87 ++++++++++++++++++++++++++++++++++++
1 file changed, 87 insertions(+)
diff --git a/src/lib/merchant_api_tip_authorize.c
b/src/lib/merchant_api_tip_authorize.c
index 2a17238..4604fc0 100644
--- a/src/lib/merchant_api_tip_authorize.c
+++ b/src/lib/merchant_api_tip_authorize.c
@@ -308,6 +308,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.
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-merchant] 108/277: sketch for GET /transfers cmd, (continued)
- [taler-merchant] 108/277: sketch for GET /transfers cmd, gnunet, 2020/07/05
- [taler-merchant] 134/277: finished writing db tests for products, gnunet, 2020/07/05
- [taler-merchant] 137/277: implement POST /tips/ID/pickup, gnunet, 2020/07/05
- [taler-merchant] 141/277: Merge branch 'protocolV1' of git+ssh://git.taler.net/merchant into protocolV1, gnunet, 2020/07/05
- [taler-merchant] 143/277: more SQL for tips, gnunet, 2020/07/05
- [taler-merchant] 148/277: fixed inventory locking, test code for transfer lookups, gnunet, 2020/07/05
- [taler-merchant] 155/277: fix ftbfs, gnunet, 2020/07/05
- [taler-merchant] 154/277: return creation_time instead of leaving it uninitizlied, mark problematic missing lines, gnunet, 2020/07/05
- [taler-merchant] 158/277: work on tip APIs, gnunet, 2020/07/05
- [taler-merchant] 156/277: implement lookup tip details, gnunet, 2020/07/05
- [taler-merchant] 159/277: add POST /tips logic,
gnunet <=
- [taler-merchant] 164/277: fixed db test building and added test for wire fee storage, gnunet, 2020/07/05
- [taler-merchant] 163/277: implement filter, gnunet, 2020/07/05
- [taler-merchant] 165/277: add logic for activation of reserves to merchant backend DB, gnunet, 2020/07/05
- [taler-merchant] 147/277: added more tests for contract terms, deposits, and transfers, gnunet, 2020/07/05
- [taler-merchant] 160/277: address DB fixes for missing EC values, gnunet, 2020/07/05
- [taler-merchant] 157/277: fix DB use, gnunet, 2020/07/05
- [taler-merchant] 166/277: SQL fixing, gnunet, 2020/07/05
- [taler-merchant] 152/277: wrote db tests for tips/lookups, gnunet, 2020/07/05
- [taler-merchant] 145/277: refactored the existing product and order tests, gnunet, 2020/07/05
- [taler-merchant] 171/277: tests/fixes for tips and pickups in backenddb, gnunet, 2020/07/05