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: /refund lib, issuin


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] branch master updated: /refund lib, issuing the POST and defining cb skeleton
Date: Mon, 19 Jun 2017 11:30:53 +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 a6b996f  /refund lib, issuing the POST and defining cb skeleton
a6b996f is described below

commit a6b996f6a2ee55dff2c33bb9b8ef209b532c8bf3
Author: Marcello Stanisci <address@hidden>
AuthorDate: Mon Jun 19 11:30:45 2017 +0200

    /refund lib, issuing the POST and defining cb skeleton
---
 src/backend/taler-merchant-httpd_refund.c |  2 +-
 src/include/taler_merchant_service.h      | 24 +++++++++++
 src/lib/merchant_api_proposal.c           |  5 +--
 src/lib/merchant_api_refund.c             | 71 ++++++++++++++++++++++++++++++-
 4 files changed, 97 insertions(+), 5 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_refund.c 
b/src/backend/taler-merchant-httpd_refund.c
index cbbf328..f690c5e 100644
--- a/src/backend/taler-merchant-httpd_refund.c
+++ b/src/backend/taler-merchant-httpd_refund.c
@@ -121,7 +121,7 @@ MH_handler_refund_increase (struct TMH_RequestHandler *rh,
     TALER_JSON_spec_amount ("refund", &refund),
     GNUNET_JSON_spec_string ("order_id", &order_id),
     GNUNET_JSON_spec_string ("reason", &reason),
-    GNUNET_JSON_spec_string ("reason", &merchant),
+    GNUNET_JSON_spec_string ("instance", &merchant),
     GNUNET_JSON_spec_end ()
   }; 
 
diff --git a/src/include/taler_merchant_service.h 
b/src/include/taler_merchant_service.h
index e813851..15287c5 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -621,4 +621,28 @@ 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);
+
 #endif  /* _TALER_MERCHANT_SERVICE_H */
diff --git a/src/lib/merchant_api_proposal.c b/src/lib/merchant_api_proposal.c
index f8f1ab7..d262fff 100644
--- a/src/lib/merchant_api_proposal.c
+++ b/src/lib/merchant_api_proposal.c
@@ -103,11 +103,11 @@ struct TALER_MERCHANT_ProposalLookupOperation
 
 /**
  * Function called when we're done processing the
- * HTTP PUT /proposal request.
+ * HTTP POST /proposal request.
  *
  * @param cls the `struct TALER_MERCHANT_ProposalOperation`
  * @param response_code HTTP response code, 0 on error
- * @param json response body, NULL if not in JSON
+ * @param json response body, NULL if not JSON
  */
 static void
 handle_proposal_finished (void *cls,
@@ -239,7 +239,6 @@ TALER_MERCHANT_order_put (struct GNUNET_CURL_Context *ctx,
                  curl_easy_setopt (eh,
                                    CURLOPT_URL,
                                    po->url));
-  /* FIXME: as for the specs, POST becomes PUT */
   GNUNET_assert (CURLE_OK ==
                  curl_easy_setopt (eh,
                                    CURLOPT_POSTFIELDS,
diff --git a/src/lib/merchant_api_refund.c b/src/lib/merchant_api_refund.c
index ecb233c..126dda6 100644
--- a/src/lib/merchant_api_refund.c
+++ b/src/lib/merchant_api_refund.c
@@ -39,6 +39,11 @@ struct TALER_MERCHANT_RefundIncreaseOperation
   char *url;
 
   /**
+   * The request body
+   */
+  char *json_enc;
+
+  /**
    * The CURL context to connect to the backend
    */
   struct GNUNET_CURL_Context *ctx;
@@ -52,15 +57,41 @@ struct TALER_MERCHANT_RefundIncreaseOperation
    * Clasure to pass to the callback
    */
   void *cb_cls;
+
+  /**
+   * Handle for the request
+   */
+  struct GNUNET_CURL_Job *job;
+
 };
 
 
 /**
+ * Callback to process POST /refund response
+ *
+ * @param cls the `struct TALER_MERCHANT_RefundIncreaseOperation`
+ * @param response_code HTTP response code, 0 on error
+ * @param json response body, NULL if not JSON
+ */
+static void
+handle_refund_increase_finished (void *cls,
+                                 long response_code,
+                                 const json_t *json)
+{
+
+}
+
+/**
  * 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,
@@ -68,6 +99,7 @@ TALER_MERCHANT_refund_increase (struct GNUNET_CURL_Context 
*ctx,
                                 const char *order_id,
                                 const struct TALER_Amount *refund,
                                 const char *reason,
+                                const char *instance,
                                 TALER_MERCHANT_RefundIncreaseCallback cb,
                                 void *cb_cls)
 {
@@ -80,12 +112,49 @@ TALER_MERCHANT_refund_increase (struct GNUNET_CURL_Context 
*ctx,
   rio->cb = cb;
   rio->cb_cls = cb_cls;
   GNUNET_asprintf (&rio->url,
-                   "%s/%s",
+                   "%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,
+                                   rio->url));
+  GNUNET_assert (CURLE_OK ==
+                 curl_easy_setopt (eh,
+                                   CURLOPT_POSTFIELDS,
+                                   rio->json_enc));
+  GNUNET_assert (CURLE_OK ==
+                 curl_easy_setopt (eh,
+                                   CURLOPT_POSTFIELDSIZE,
+                                   strlen (rio->json_enc)));
+  rio->job = GNUNET_CURL_job_add (ctx,
+                                  eh,
+                                  GNUNET_YES,
+                                  &handle_refund_increase_finished,
+                                  rio);
+
 
   return NULL;
 }

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



reply via email to

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