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: 80% GET /refund log


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] branch master updated: 80% GET /refund logic
Date: Mon, 19 Jun 2017 15:09:59 +0200

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

marcello pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 46dccc5  80% GET /refund logic
46dccc5 is described below

commit 46dccc5558e828a2c8e4b03ed418832843ebd3a5
Author: Marcello Stanisci <address@hidden>
AuthorDate: Mon Jun 19 15:09:48 2017 +0200

    80% GET /refund logic
---
 src/include/taler_merchant_service.h | 113 +++++++++++++++++++++++------------
 src/lib/merchant_api_refund.c        | 107 ++++++++++++++++++++++++++++++---
 2 files changed, 173 insertions(+), 47 deletions(-)

diff --git a/src/include/taler_merchant_service.h 
b/src/include/taler_merchant_service.h
index 84fc04b..8a2343a 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -32,16 +32,15 @@
 
 struct TALER_MERCHANT_RefundIncreaseOperation;
 
+struct TALER_MERCHANT_RefundLookupOperation;
+
 /**
- * Callbacks of this type get passed the result of a GET /refund
- * request to the backend.
+ * Callback to process a POST /refund request
  *
  * @param cls closure
- * @param http_status the HTTP status of the connection to the backend
+ * @param http_status HTTP status code for this request
  * @param ec taler-specific error code
- * @param obj the resposne in JSON format. NOTE, this object is an array,
- * so it makes little sense to extract values from it and serve them to the
- * callback.
+ * @param obj the response body
  */
 typedef void
 (*TALER_MERCHANT_RefundIncreaseCallback) (void *cls,
@@ -49,6 +48,76 @@ typedef void
                                           enum TALER_ErrorCode ec,
                                           const json_t *obj);
 
+/**
+ * Callback to process a GET /refund request
+ *
+ * @param cls closure
+ * @param http_status HTTP status code for this request
+ * @param ec taler-specific error code
+ * @param obj the response body
+ */
+typedef void
+(*TALER_MERCHANT_RefundLookupCallback) (void *cls,
+                                                 unsigned int http_status,
+                                                 enum TALER_ErrorCode ec,
+                                                 const json_t *obj);
+
+/**
+ * Does a GET /refund.
+ *
+ * @param ctx execution context
+ * @param backend_uri base URL of the merchant backend
+ * @param order_id order id used to perform the lookup
+ * @param cb callback which will work the response gotten from the backend
+ * @param cb_cls closure to pass to the callback
+ * @return handle for this operation, NULL upon errors
+ */
+struct TALER_MERCHANT_RefundLookupOperation *
+TALER_MERCHANT_refund_lookup (struct GNUNET_CURL_Context *ctx,
+                              const char *backend_uri,
+                              const char *order_id,
+                              const char *instance,
+                              TALER_MERCHANT_RefundLookupCallback cb,
+                              void *cb_cls);
+
+/**
+ * Increase the refund associated to a order
+ *
+ * @param ctx the CURL context used to connect to the backend
+ * @param backend_uri backend's base URL, including final "/"
+ * @param order_id id of the order whose refund is to be increased
+ * @param refund amount to which increase the refund
+ * @param reason human-readable reason justifying the refund
+ * @param instance id of the merchant instance issuing the request
+ * @param cb callback processing the response from /refund
+ * @param cb_cls closure for cb
+ */
+struct TALER_MERCHANT_RefundIncreaseOperation *
+TALER_MERCHANT_refund_increase (struct GNUNET_CURL_Context *ctx,
+                                const char *backend_uri,
+                                const char *order_id,
+                                const struct TALER_Amount *refund,
+                                const char *reason,
+                                const char *instance,
+                                TALER_MERCHANT_RefundIncreaseCallback cb,
+                                void *cb_cls);
+
+/**
+ * Cancel a POST /refund request.
+ *
+ * @param rio the refund increasing operation to cancel
+ */
+void
+TALER_MERCHANT_refund_increase_cancel (struct 
TALER_MERCHANT_RefundIncreaseOperation *rio);
+
+/**
+ * Cancel a GET /refund request.
+ *
+ * @param rlo the refund increasing operation to cancel
+ */
+void
+TALER_MERCHANT_refund_lookup_cancel (struct 
TALER_MERCHANT_RefundLookupOperation *rlo);
+
 /* *********************  /proposal *********************** */
 
 
@@ -621,36 +690,4 @@ TALER_MERCHANT_history (struct GNUNET_CURL_Context *ctx,
 void
 TALER_MERCHANT_history_cancel (struct TALER_MERCHANT_HistoryOperation *ho);
 
-/************************ /refund ****************************/
-
-/**
- * Increase the refund associated to a order
- *
- * @param ctx the CURL context used to connect to the backend
- * @param backend_uri backend's base URL, including final "/"
- * @param order_id id of the order whose refund is to be increased
- * @param refund amount to which increase the refund
- * @param reason human-readable reason justifying the refund
- * @param instance id of the merchant instance issuing the request
- * @param cb callback processing the response from /refund
- * @param cb_cls closure for cb
- */
-struct TALER_MERCHANT_RefundIncreaseOperation *
-TALER_MERCHANT_refund_increase (struct GNUNET_CURL_Context *ctx,
-                                const char *backend_uri,
-                                const char *order_id,
-                                const struct TALER_Amount *refund,
-                                const char *reason,
-                                const char *instance,
-                                TALER_MERCHANT_RefundIncreaseCallback cb,
-                                void *cb_cls);
-
-/**
- * Cancel a POST /refund request.
- *
- * @param rio the refund increasing operation to cancel
- */
-void
-TALER_MERCHANT_refund_increase_cancel (struct 
TALER_MERCHANT_RefundIncreaseOperation *rio);
-
 #endif  /* _TALER_MERCHANT_SERVICE_H */
diff --git a/src/lib/merchant_api_refund.c b/src/lib/merchant_api_refund.c
index 4f2a8c1..9a4329b 100644
--- a/src/lib/merchant_api_refund.c
+++ b/src/lib/merchant_api_refund.c
@@ -31,6 +31,36 @@
 #include <taler/taler_json_lib.h>
 #include <taler/taler_signatures.h>
 
+
+struct TALER_MERCHANT_RefundLookupOperation
+{
+  /**
+   * URL of the request, includes parameters
+   */
+  char *url;
+
+  /**
+   * Handle of the request
+   */
+  struct GNUNET_CURL_Job *job;
+
+  /**
+   * Function to call with the response
+   */
+  TALER_MERCHANT_RefundLookupCallback cb;
+
+  /**
+   * Closure for cb
+   */
+  void *cb_cls;
+
+  /**
+   * Reference to the execution context
+   */
+  struct GNUNET_CURL_Context *ctx;
+
+};
+
 struct TALER_MERCHANT_RefundIncreaseOperation
 {
   /**
@@ -78,7 +108,7 @@ handle_refund_increase_finished (void *cls,
                                  long response_code,
                                  const json_t *json)
 {
-
+  /* TBD */
 }
 
 /**
@@ -133,28 +163,21 @@ TALER_MERCHANT_refund_increase (struct 
GNUNET_CURL_Context *ctx,
                    "%s%s",
                    backend_uri,
                    "/refund");
-  /**
-   * FIXME: pack the data to POST.
-   */
   req = json_pack ("{s:o, s:s, s:s}",
                    "refund", TALER_JSON_from_amount (refund),
                    "order_id", order_id,
                    "reason", reason,
                    "instance", instance);
-
   eh = curl_easy_init ();
-
   rio->json_enc = json_dumps (req,
                               JSON_COMPACT);
   json_decref (req);
-
   if (NULL == rio->json_enc)
   {
     GNUNET_break (0);
     GNUNET_free (rio);
     return NULL;
   }
-  
   GNUNET_assert (CURLE_OK ==
                  curl_easy_setopt (eh,
                                    CURLOPT_URL,
@@ -172,7 +195,73 @@ TALER_MERCHANT_refund_increase (struct GNUNET_CURL_Context 
*ctx,
                                   GNUNET_YES,
                                   &handle_refund_increase_finished,
                                   rio);
+  return NULL;
+}
 
+/**
+ * Process GET /refund response
+ */
+void
+handle_refund_lookup_finished (void *cls,
+                               long response_code,
+                               const json_t *json)
+{
+  /**
+   *  TBD
+   */
 
-  return NULL;
+}
+
+/**
+ * Does a GET /refund.
+ *
+ * @param ctx execution context
+ * @param backend_uri base URL of the merchant backend
+ * @param order_id order id used to perform the lookup
+ * @param cb callback which will work the response gotten from the backend
+ * @param cb_cls closure to pass to the callback
+ * @return handle for this operation, NULL upon errors
+ */
+struct TALER_MERCHANT_RefundLookupOperation *
+TALER_MERCHANT_refund_lookup (struct GNUNET_CURL_Context *ctx,
+                              const char *backend_uri,
+                              const char *order_id,
+                              const char *instance,
+                              TALER_MERCHANT_RefundLookupCallback cb,
+                              void *cb_cls)
+{
+  struct TALER_MERCHANT_RefundLookupOperation *rlo;
+  CURL *eh;
+
+  rlo = GNUNET_new (struct TALER_MERCHANT_RefundLookupOperation);
+  rlo->ctx = ctx;
+  rlo->cb = cb;
+  rlo->cb_cls = cb_cls;
+
+  GNUNET_asprintf (&rlo->url,
+                   "%s/refund?instance=%s&order_id=%s",
+                   backend_uri,
+                   instance,
+                   order_id);
+  eh = curl_easy_init ();
+  if (CURLE_OK != curl_easy_setopt (eh,
+                                    CURLOPT_URL,
+                                    rlo->url))
+  {
+    GNUNET_break (0);
+    return NULL;
+  }
+
+  if (NULL == (rlo->job = GNUNET_CURL_job_add (ctx,
+                                               eh,
+                                               GNUNET_NO,
+                                               handle_refund_lookup_finished,
+                                               rlo)))
+  {
+    GNUNET_break (0);
+    return NULL;
+  
+  }
+
+  return rlo;
 }

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



reply via email to

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