summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/taler-merchant-httpd_contract.c4
-rw-r--r--src/backend/taler-merchant-httpd_pay.c58
-rw-r--r--src/backend/taler-mint-httpd_responses.c17
3 files changed, 73 insertions, 6 deletions
diff --git a/src/backend/taler-merchant-httpd_contract.c b/src/backend/taler-merchant-httpd_contract.c
index 834cfce8..c157b859 100644
--- a/src/backend/taler-merchant-httpd_contract.c
+++ b/src/backend/taler-merchant-httpd_contract.c
@@ -107,7 +107,7 @@ MH_handler_contract (struct TMH_RequestHandler *rh,
json_array_append_new (trusted_mints, mint);
}
}
- auditors = json_array ();
+ j_auditors = json_array ();
for (cnt = 0; cnt < nauditors; cnt++)
{
auditor = json_pack ("{s:s}",
@@ -129,7 +129,7 @@ MH_handler_contract (struct TMH_RequestHandler *rh,
/**
* Hard error, no action can be taken by a wallet
*/
- if (!json_array_size (auditors))
+ if (!json_array_size (j_auditors))
return MHD_NO;
json_object_set_new (root, "mints", trusted_mints);
diff --git a/src/backend/taler-merchant-httpd_pay.c b/src/backend/taler-merchant-httpd_pay.c
index 59aa211c..02c2ef04 100644
--- a/src/backend/taler-merchant-httpd_pay.c
+++ b/src/backend/taler-merchant-httpd_pay.c
@@ -42,6 +42,38 @@ extern PGconn *db_conn;
extern long long salt;
/**
+ * Fetch the deposit fee related to the given coin aggregate.
+ * @param connection the connection to send an error response to
+ * @param coin_aggregate a coin "aggregate" is the JSON set of
+ * values contained in a single cell of the 'coins' array sent
+ * in a payment
+ * @param deposit_fee where to store the resulting deposi fee
+ * @param mint_index the index which points the chosen mint within
+ * the global 'mints' array
+ * @return GNUNET_OK if successful, GNUNET_NO if the data supplied
+ * is invalid, GNUNET_SYSERR upon internal errors
+ */
+int
+deposit_fee_from_coin_json (struct MHD_Connection *connection,
+ json_t *coin_aggregate,
+ struct TALER_Amount *deposit_fee,
+ unsigned int mint_index)
+{
+ int res;
+ struct TALER_DenominationPublicKey denom;
+ struct TMH_PARSE_FieldSpecification spec[] = {
+ TMH_PARSE_member_denomination_public_key ("denom_pub", &denom);
+ };
+
+ res = TMH_PARSE_json_data (connection,
+ coin_aggregate,
+ spec);
+ if (GNUNET_OK != res)
+ return res;
+ /* Iterate over the mint keys to get the wanted data */
+}
+
+/**
* Accomplish this payment.
* @param rh context of the handler
* @param connection the MHD connection to handle
@@ -62,12 +94,17 @@ MH_handler_pay (struct TMH_RequestHandler *rh,
json_t *root;
json_t *coins;
-
+ json_t *chosen_mint;
+ json_t *coin_aggregate;
+ unsigned int ncoins;
int res;
+ struct TMH_PARSE_FieldSpecification spec[] = {
+ TMH_PARSE_member_array ("coins", &coins);
+ TMH_PARSE_member_object ("mint", &chosen_mint);
+ };
struct TALER_Amount max_deposit_fee;
//struct TALER_Amount acc_deposit_fee;
//struct TALER_Amount coin_deposit_fee;
-
res = TMH_PARSE_post_json (connection,
connection_cls,
upload_data,
@@ -83,9 +120,17 @@ MH_handler_pay (struct TMH_RequestHandler *rh,
/* 0 What if the coin gives zero-length coins array? */
- /* 1 Check if the total deposit fee is \leq the limit */
+
+ res = TMH_PARSE_json_data (connection,
+ coin_aggregate,
+ spec);
- /* 2 Check if the chosen mint is among the merchant's preferred.
+ if (GNUNET_YES != res)
+ return (GNUNET_NO == res) ? MHD_YES : MHD_NO;
+ if (0 == ncoins)
+ return TMH_RESPONSE_reply_external_error (connection,
+ "empty coin array");
+ /* 1 Check if the chosen mint is among the merchant's preferred.
An error in this case could be due to:
@@ -100,6 +145,11 @@ MH_handler_pay (struct TMH_RequestHandler *rh,
*/
+ /* 2 Check if the total deposit fee is \leq the limit */
+ ncoins = json_array_size (coins);
+ if (NULL == (coin_aggregate = json_array_get (coins, 0)))
+ return MHD_NO;
+
/* 3 For each coin in DB
a. Generate a deposit permission
diff --git a/src/backend/taler-mint-httpd_responses.c b/src/backend/taler-mint-httpd_responses.c
index 70cf7e52..00a4d25f 100644
--- a/src/backend/taler-mint-httpd_responses.c
+++ b/src/backend/taler-mint-httpd_responses.c
@@ -186,4 +186,21 @@ TMH_RESPONSE_add_global_headers (struct MHD_Response *response)
"close");
}
+/**
+ * Send a response indicating an external error.
+ *
+ * @param connection the MHD connection to use
+ * @param hint hint about the error's nature
+ * @return a MHD result code
+ */
+int
+TMH_RESPONSE_reply_external_error (struct MHD_Connection *connection,
+ const char *hint)
+{
+ return TMH_RESPONSE_reply_json_pack (connection,
+ MHD_HTTP_BAD_REQUEST,
+ "{s:s, s:s}",
+ "error", "client error",
+ "hint", hint);
+}
/* end of taler-mint-httpd_responses.c */