[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-merchant] 02/02: implement OC_TIP_AUTHORIZE
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-merchant] 02/02: implement OC_TIP_AUTHORIZE |
Date: |
Mon, 30 Oct 2017 15:37:15 +0100 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository merchant.
commit 22b8ebf3c035be0f741fd25dea9bbef7bb5b785c
Author: Christian Grothoff <address@hidden>
AuthorDate: Mon Oct 30 15:37:09 2017 +0100
implement OC_TIP_AUTHORIZE
---
src/lib/test_merchant_api.c | 85 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 84 insertions(+), 1 deletion(-)
diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c
index 19eb4b6..0ab41e6 100644
--- a/src/lib/test_merchant_api.c
+++ b/src/lib/test_merchant_api.c
@@ -21,7 +21,6 @@
*
* TODO:
* - implement getting reserve_priv from configuration in /admin/add/incoming
- * - implement tip_authorize
* - implement tip_pickup
* - implement spending with coins from tips
* - add test logic for tips to main test interpreter
@@ -774,6 +773,11 @@ struct Command
struct GNUNET_HashCode tip_id;
/**
+ * When does the authorization expire?
+ */
+ struct GNUNET_TIME_Absolute tip_expiration;
+
+ /**
* EC expected for the operation.
*/
enum TALER_ErrorCode expected_ec;
@@ -1765,6 +1769,64 @@ tip_enable_cb (void *cls,
/**
+ * Callback for a /tip-authorize request. Returns the result of
+ * the operation.
+ *
+ * @param cls closure
+ * @param http_status HTTP status returned by the merchant backend
+ * @param ec taler-specific error code
+ */
+static void
+tip_authorize_cb (void *cls,
+ unsigned int http_status,
+ enum TALER_ErrorCode ec,
+ const struct GNUNET_HashCode *tip_id,
+ struct GNUNET_TIME_Absolute tip_expiration,
+ const char *exchange_uri)
+{
+ struct InterpreterState *is = cls;
+ struct Command *cmd = &is->commands[is->ip];
+
+ cmd->details.tip_authorize.tao = NULL;
+ if (cmd->expected_response_code != http_status)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u to command %s\n",
+ http_status,
+ cmd->label);
+ fail (is);
+ return;
+ }
+ if (cmd->details.tip_authorize.expected_ec != ec)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected error code %u to command %s\n",
+ ec,
+ cmd->label);
+ fail (is);
+ return;
+ }
+ if ( (MHD_HTTP_OK == http_status) &&
+ (TALER_EC_NONE == ec) )
+ {
+ if (0 != strcmp (exchange_uri,
+ EXCHANGE_URI))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected exchange URI %s to command %s\n",
+ exchange_uri,
+ cmd->label);
+ fail (is);
+ return;
+ }
+ cmd->details.tip_authorize.tip_id = *tip_id;
+ cmd->details.tip_authorize.tip_expiration = tip_expiration;
+ }
+ next_command (is);
+}
+
+
+/**
* Find denomination key matching the given amount.
*
* @param keys array of keys to search
@@ -2592,6 +2654,27 @@ interpreter_run (void *cls)
}
break;
}
+ case OC_TIP_AUTHORIZE:
+ {
+ GNUNET_assert (NULL != cmd->details.tip_authorize.amount);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (cmd->details.tip_authorize.amount,
+ &amount));
+ if (NULL == (cmd->details.tip_authorize.tao
+ = TALER_MERCHANT_tip_authorize
+ (ctx,
+ MERCHANT_URI,
+ &amount,
+ cmd->details.tip_authorize.instance,
+ cmd->details.tip_authorize.justification,
+ &tip_authorize_cb,
+ is)))
+ {
+ GNUNET_break (0);
+ fail (is);
+ }
+ break;
+ }
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unknown instruction %d at %u (%s)\n",
--
To stop receiving notification emails like this one, please contact
address@hidden