summaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd_private-get-tips-ID.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-05-21 23:06:59 +0200
committerChristian Grothoff <christian@grothoff.org>2020-05-21 23:06:59 +0200
commitfe19d9ada3f6dfdf3014b9610090b8750de32db8 (patch)
treec4bcdcca15c53bfbef46497892d99248036c7c49 /src/backend/taler-merchant-httpd_private-get-tips-ID.c
parentd46bd871bcd34b9e0d633ab15fd9a4747861616c (diff)
downloadmerchant-fe19d9ada3f6dfdf3014b9610090b8750de32db8.tar.gz
merchant-fe19d9ada3f6dfdf3014b9610090b8750de32db8.tar.bz2
merchant-fe19d9ada3f6dfdf3014b9610090b8750de32db8.zip
towards POST tips pickup impl
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-get-tips-ID.c')
-rw-r--r--src/backend/taler-merchant-httpd_private-get-tips-ID.c94
1 files changed, 64 insertions, 30 deletions
diff --git a/src/backend/taler-merchant-httpd_private-get-tips-ID.c b/src/backend/taler-merchant-httpd_private-get-tips-ID.c
index f186363d..6276189f 100644
--- a/src/backend/taler-merchant-httpd_private-get-tips-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-tips-ID.c
@@ -42,14 +42,17 @@ TMH_private_get_tips_ID (const struct TMH_RequestHandler *rh,
struct MHD_Connection *connection,
struct TMH_HandlerContext *hc)
{
- char *exchange_url;
struct GNUNET_HashCode tip_id;
- struct TALER_Amount tip_amount;
- struct TALER_Amount tip_amount_left;
- struct GNUNET_TIME_Absolute timestamp;
+ struct TALER_Amount total_authorized;
+ struct TALER_Amount total_picked_up;
+ char *reason;
+ struct GNUNET_TIME_Absolute expiration;
+ unsigned int pickups_length = 0;
+ struct TALER_MERCHANTDB_PickupDetails *pickups = NULL;
struct GNUNET_TIME_Absolute timestamp_expire;
- MHD_RESULT ret;
enum GNUNET_DB_QueryStatus qs;
+ bool fpu;
+ json_t *pickups_json;
GNUNET_assert (NULL != hc->infix);
if (GNUNET_OK !=
@@ -63,17 +66,27 @@ TMH_private_get_tips_ID (const struct TMH_RequestHandler *rh,
TALER_EC_PARAMETER_MALFORMED,
"tip_id malformed");
}
+ {
+ const char *pstr;
+ pstr = MHD_lookup_connection_value (connection,
+ MHD_GET_ARGUMENT_KIND,
+ "pickups");
+ fpu = (NULL != pstr) ? 0 == strcasecmp (pstr, "yes") :
+ false;
+ }
db->preflight (db->cls);
- // FIXME: logic here is completely bonkers!
- qs = db->lookup_tip_by_id (db->cls,
- &tip_id,
- &exchange_url,
- &extra,
- &tip_amount,
- &tip_amount_left,
- &timestamp);
-
+ qs = db->lookup_tip_details (db->cls,
+ hc->instance->settings.id,
+ &tip_id,
+ fpu,
+ &total_authorized,
+ &total_picked_up,
+ &reason,
+ &expiration,
+ &reserve_pub,
+ &pickups_length,
+ &pickups);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
{
unsigned int response_code;
@@ -104,21 +117,42 @@ TMH_private_get_tips_ID (const struct TMH_RequestHandler *rh,
ec,
"Could not determine exchange URL for the given tip id");
}
+ if (fpu)
+ {
+ pickups_json = json_array ();
+ GNUNET_assert (NULL != pickups_json);
+ for (unsigned int i = 0; i<pickups_length; i++)
+ {
+ json_array_append_new (
+ pickups_json,
+ json_pack ("{s:o,s:o,s:o,s:I}",
+ "pickup_id",
+ GNUNET_JSON_from_data_auto (&pickups[i].pickup_id),
+ "requested_amount",
+ TALER_JSON_from_amount (&pickups[i].requested_amount),
+ "exchange_amount",
+ TALER_JSON_from_amount (&pickups[i].exchange_amount),
+ "num_planchets",
+ (json_int_t) pickups[i].num_planchets));
+ }
+ }
+ GNUNET_array_grow (pickups,
+ pickups_length,
+ 0);
+ {
+ MHD_RESULT ret;
- timestamp_expire = GNUNET_TIME_absolute_add (timestamp,
- GNUNET_TIME_UNIT_DAYS);
-
- ret = TALER_MHD_reply_json_pack (
- connection,
- MHD_HTTP_OK,
- "{s:s, s:o, s:o, s:o, s:o, s:o?}",
- "reason", reason,
- "total_authorized", TALER_JSON_from_amount (&tip_amount),
- "total_picked_up", TALER_JSON_from_amount (&tip_amount_left),
- "reserve_pub", GNUNET_JSON_from_data_auto (&reserve_pub),
- "expiration", GNUNET_JSON_from_time_abs (timestamp_expire),
- "pickups", pickups);
-
- GNUNET_free (exchange_url);
- return ret;
+ ret = TALER_MHD_reply_json_pack (
+ connection,
+ MHD_HTTP_OK,
+ "{s:s, s:o, s:o, s:o, s:o, s:o?}",
+ "reason", reason,
+ "total_authorized", TALER_JSON_from_amount (&total_authorized),
+ "total_picked_up", TALER_JSON_from_amount (&total_picked_up),
+ "reserve_pub", GNUNET_JSON_from_data_auto (&reserve_pub),
+ "expiration", GNUNET_JSON_from_time_abs (expiration),
+ "pickups", pickups_json);
+ GNUNET_free (reason);
+ return ret;
+ }
}