gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-merchant] branch master updated (bee5098 -> 450ff23)


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] branch master updated (bee5098 -> 450ff23)
Date: Mon, 22 Jan 2018 17:51:07 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a change to branch master
in repository merchant.

    from bee5098  fix #5259 (assertion slightly wrong)
     new cf4e7ee  implement check payment API client
     new 450ff23  make arguments const

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/backend/taler-merchant-httpd.c   |  4 +-
 src/backend/taler-merchant-httpd.h   |  4 +-
 src/include/taler_merchant_service.h | 72 ++++++++++++++++++++++++++++++
 src/lib/Makefile.am                  |  3 +-
 src/lib/merchant_api_common.c        | 86 ++++++++++++++++++++++++++++++++++++
 src/lib/merchant_api_common.h        | 13 ++++++
 6 files changed, 177 insertions(+), 5 deletions(-)

diff --git a/src/backend/taler-merchant-httpd.c 
b/src/backend/taler-merchant-httpd.c
index 5fbb54f..d5be71b 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -1471,7 +1471,7 @@ main (int argc,
  */
 char *
 TMH_make_absolute_backend_url (struct MHD_Connection *connection,
-                               char *path,
+                               const char *path,
                                ...)
 {
   static CURL *curl = NULL;
@@ -1556,7 +1556,7 @@ TMH_make_absolute_backend_url (struct MHD_Connection 
*connection,
  * @returns #GNUNET_OK on success, #GNUNET_SYSERR on invalid format
  */
 int
-TMH_convert_amount (json_t *json, char *field_name)
+TMH_convert_amount (json_t *json, const char *field_name)
 {
   if (! json_is_string (json_object_get (json, field_name)))
     return GNUNET_OK;
diff --git a/src/backend/taler-merchant-httpd.h 
b/src/backend/taler-merchant-httpd.h
index 18b1b54..078c038 100644
--- a/src/backend/taler-merchant-httpd.h
+++ b/src/backend/taler-merchant-httpd.h
@@ -368,7 +368,7 @@ TMH_lookup_instance_json (struct json_t *json);
  * @returns the URL, must be freed with #GNUNET_free
  */
 char *
-TMH_make_absolute_backend_url (struct MHD_Connection *connection, char *path, 
...);
+TMH_make_absolute_backend_url (struct MHD_Connection *connection, const char 
*path, ...);
 
 
 /**
@@ -381,6 +381,6 @@ TMH_make_absolute_backend_url (struct MHD_Connection 
*connection, char *path, ..
  * @returns #GNUNET_OK on success, #GNUNET_SYSERR on invalid format
  */
 int
-TMH_convert_amount (json_t *json, char *field_name);
+TMH_convert_amount (json_t *json, const char *field_name);
 
 #endif
diff --git a/src/include/taler_merchant_service.h 
b/src/include/taler_merchant_service.h
index adcf006..3462288 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -918,4 +918,76 @@ void
 TALER_MERCHANT_tip_pickup_cancel (struct TALER_MERCHANT_TipPickupOperation 
*tp);
 
 
+/* ********************** /check-payment ************************* */
+
+
+/**
+ * Handle for a /tip-pickup operation.
+ */
+struct TALER_MERCHANT_CheckPaymentOperation;
+
+
+/**
+ * Callback to process a GET /check-payment request
+ *
+ * @param cls closure
+ * @param http_status HTTP status code for this request
+ * @param obj raw response body
+ * @param paid #GNUNET_YES if the payment is settled, #GNUNET_NO if not
+ *        settled, $GNUNET_SYSERR on error
+ *        (note that refunded payments are returned as paid!)
+ * @param refunded #GNUNET_YES if there is at least on refund on this payment,
+ *        #GNUNET_NO if refunded, #GNUNET_SYSERR or error
+ * @param refunded_amount amount that was refunded, NULL if there
+ *        was no refund
+ * @param payment_redirect_url URL to redirect the browser to in order to
+ *        execute or re-play the payment (NULL if not applicable)
+ */
+typedef void
+(*TALER_MERCHANT_CheckPaymentCallback) (void *cls,
+                                       unsigned int http_status,
+                                       const json_t *obj,
+                                        int paid,
+                                        int refunded,
+                                        struct TALER_Amount *refund_amount,
+                                        const char *payment_redirect_url);
+
+
+/**
+ * Issue a /check-payment request to the backend.  Checks the status
+ * of a payment.
+ *
+ * @param ctx execution context
+ * @param backend_url base URL of the merchant backend
+ * @param instance instance used for the transaction
+ * @param order_id order id to identify the payment
+ * @parem resource_url resource URL to identify duplicate payments (can be 
NULL)
+ * @parem session_id sesion id for the payment (or NULL if the payment is not 
bound to a session) 
+ * @parem session_id sesion signature for the payment (or NULL if the payment
+ *        is not bound to a session or the session is not signed yet) 
+ * @param check_payment_cb callback which will work the response gotten from 
the backend
+ * @param check_payment_cb_cls closure to pass to @a check_payment_cb
+ * @return handle for this operation, NULL upon errors
+ */
+struct TALER_MERCHANT_CheckPaymentOperation *
+TALER_MERCHANT_check_payment (struct GNUNET_CURL_Context *ctx,
+                              const char *backend_url,
+                              const char *instance,
+                              const char *order_id,
+                              const char *resource_url,
+                              const char *session_id,
+                              const char *session_sig,
+                              TALER_MERCHANT_CheckPaymentCallback 
check_payment_cb,
+                              void *check_payment_cls);
+
+
+/**
+ * Cancel a GET /check-payment request.
+ *
+ * @param cph handle to the request to be canceled
+ */
+void
+TALER_MERCHANT_check_payment_cancel (struct 
TALER_MERCHANT_CheckPaymentOperation *cph);
+
+
 #endif  /* _TALER_MERCHANT_SERVICE_H */
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 4c6d5f8..d407ee0 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -22,7 +22,8 @@ libtalermerchant_la_SOURCES = \
   merchant_api_track_transaction.c \
   merchant_api_track_transfer.c \
   merchant_api_history.c \
-  merchant_api_refund.c
+  merchant_api_refund.c \
+  merchant_api_check_payment.c
 
 libtalermerchant_la_LIBADD = \
   -ltalerexchange \
diff --git a/src/lib/merchant_api_common.c b/src/lib/merchant_api_common.c
index 05e2637..12bc81d 100644
--- a/src/lib/merchant_api_common.c
+++ b/src/lib/merchant_api_common.c
@@ -20,6 +20,7 @@
  * @author Christian Grothoff
  */
 #include "platform.h"
+#include <curl/curl.h>
 #include <gnunet/gnunet_util_lib.h>
 
 
@@ -47,4 +48,89 @@ MAH_path_to_url_ (const char *base_url,
   return url;
 }
 
+
+/**
+ * Concatenate two strings and grow the first buffer (of size n)
+ * if necessary.
+ */
+#define STR_CAT_GROW(s, p, n) do { \
+    for (; strlen (s) + strlen (p) >= n; (n) = (n) * 2); \
+    (s) = GNUNET_realloc ((s), (n)); \
+    GNUNET_assert (NULL != (s)); \
+    strncat (s, p, n); \
+  } while (0)
+
+
+/**
+ * Make an absolute URL with query parameters.
+ *
+ * @param base_url absolute base URL to use
+ * @param path path of the url
+ * @param ... NULL-terminated key-value pairs (char *) for query parameters
+ * @returns the URL, must be freed with #GNUNET_free
+ */
+char *
+MAH_make_url (const char *base_url,
+              const char *path,
+              ...)
+{
+  static CURL *curl = NULL;
+  if (NULL == curl)
+  {
+    curl = curl_easy_init();
+    GNUNET_assert (NULL != curl);
+  }
+
+  size_t n = 256;
+  char *res = GNUNET_malloc (n);
+
+  GNUNET_assert (NULL != res);
+
+  STR_CAT_GROW (res, base_url, n);
+
+  if ( ('/' == path[0]) &&
+       (0 < strlen (base_url)) &&
+       ('/' == base_url[strlen (base_url) - 1]) )
+  {
+   /* avoid generating URL with "//" from concat */
+    path++;
+  }
+  else if ( ('/' != path[0]) && 
+            ('/' != base_url[strlen (base_url) - 1]))
+  {
+    /* put '/' between path and base URL if necessary */
+    STR_CAT_GROW (res, "/", n);
+  }
+
+  STR_CAT_GROW (res, path, n);
+
+  va_list args;
+  va_start (args, path);
+
+  unsigned int iparam = 0;
+
+  while (1) {
+    char *key = va_arg (args, char *);
+    if (NULL == key)
+      break;
+    char *value = va_arg (args, char *);
+    if (NULL == value)
+      continue;
+    if (0 == iparam)
+      STR_CAT_GROW (res, "?", n);
+    else
+      STR_CAT_GROW (res, "&", n);
+    iparam++;
+    char *urlencoded_value = curl_easy_escape (curl, value, strlen (value));
+    STR_CAT_GROW (res, key, n);
+    STR_CAT_GROW (res, "=", n);
+    STR_CAT_GROW (res, urlencoded_value, n);
+    curl_free (urlencoded_value);
+  }
+
+  va_end (args);
+
+  return res;
+}
+
 /* end of merchant_api_common.c */
diff --git a/src/lib/merchant_api_common.h b/src/lib/merchant_api_common.h
index 683f1db..09696e3 100644
--- a/src/lib/merchant_api_common.h
+++ b/src/lib/merchant_api_common.h
@@ -33,4 +33,17 @@ char *
 MAH_path_to_url_ (const char *base_url,
                  const char *path);
 
+/**
+ * Make an absolute URL with query parameters.
+ *
+ * @param base_url absolute base URL to use
+ * @param path path of the url
+ * @param ... NULL-terminated key-value pairs (char *) for query parameters
+ * @returns the URL, must be freed with #GNUNET_free
+ */
+char *
+MAH_make_url (const char *base_url,
+              const char *path,
+              ...);
+
 #endif

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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