gnunet-svn
[Top][All Lists]
Advanced

[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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]