summaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd_private-post-orders.c
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2023-09-01 14:27:48 +0200
committerChristian Grothoff <grothoff@gnunet.org>2023-09-01 14:27:48 +0200
commit35dcd4514a93ba0f5353ecd1194fc9b515f2aad4 (patch)
tree399d8f8fbebf5e8ac383fc318b7be08901279a31 /src/backend/taler-merchant-httpd_private-post-orders.c
parent858e3047b8b595ab693e16ce0bbe0b8983b072ed (diff)
downloadmerchant-35dcd4514a93ba0f5353ecd1194fc9b515f2aad4.tar.gz
merchant-35dcd4514a93ba0f5353ecd1194fc9b515f2aad4.tar.bz2
merchant-35dcd4514a93ba0f5353ecd1194fc9b515f2aad4.zip
new CRUD APIs for OTP devices and merchant accounts (fixes #7929, #7824), one minor test is still failing...
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-post-orders.c')
-rw-r--r--src/backend/taler-merchant-httpd_private-post-orders.c69
1 files changed, 49 insertions, 20 deletions
diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c
index 1c888508..34fac6a0 100644
--- a/src/backend/taler-merchant-httpd_private-post-orders.c
+++ b/src/backend/taler-merchant-httpd_private-post-orders.c
@@ -1760,11 +1760,17 @@ merge_inventory (struct OrderContext *oc)
}
+/**
+ * Parse the basics of the client request.
+ *
+ * @param[in,out] oc order context to process
+ */
static void
parse_order_request (struct OrderContext *oc)
{
const json_t *ip = NULL;
const json_t *uuid = NULL;
+ const char *otp_id = NULL;
bool create_token = true; /* default */
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_json ("order",
@@ -1789,6 +1795,10 @@ parse_order_request (struct OrderContext *oc)
GNUNET_JSON_spec_bool ("create_token",
&create_token),
NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("otp_id",
+ &otp_id),
+ NULL),
GNUNET_JSON_spec_end ()
};
enum GNUNET_GenericReturnValue ret;
@@ -1808,6 +1818,43 @@ parse_order_request (struct OrderContext *oc)
GNUNET_TIME_relative2s (oc->refund_delay,
false));
TMH_db->expire_locks (TMH_db->cls);
+ if (NULL != otp_id)
+ {
+ struct TALER_MERCHANTDB_OtpDeviceDetails td;
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = TMH_db->select_otp (TMH_db->cls,
+ oc->hc->instance->settings.id,
+ otp_id,
+ &td);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ reply_with_error (oc,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "select_otp");
+ return;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ GNUNET_break (0);
+ reply_with_error (oc,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_SOFT_FAILURE,
+ "select_otp");
+ return;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ reply_with_error (oc,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_MERCHANT_GENERIC_OTP_DEVICE_UNKNOWN,
+ otp_id);
+ break;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ break;
+ }
+ oc->pos_key = td.otp_key;
+ oc->pos_algorithm = td.otp_algorithm;
+ }
if (create_token)
{
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
@@ -1912,12 +1959,10 @@ parse_order_request (struct OrderContext *oc)
MHD_RESULT
-TMH_private_post_orders_with_pos_secrets (
+TMH_private_post_orders (
const struct TMH_RequestHandler *rh,
struct MHD_Connection *connection,
- struct TMH_HandlerContext *hc,
- const char *pos_key,
- enum TALER_MerchantConfirmationAlgorithm pos_algorithm)
+ struct TMH_HandlerContext *hc)
{
struct OrderContext *oc = hc->ctx;
@@ -1928,8 +1973,6 @@ TMH_private_post_orders_with_pos_secrets (
hc->cc = &clean_order;
oc->connection = connection;
oc->hc = hc;
- oc->pos_key = pos_key;
- oc->pos_algorithm = pos_algorithm;
}
while (1)
{
@@ -1976,18 +2019,4 @@ TMH_private_post_orders_with_pos_secrets (
}
-MHD_RESULT
-TMH_private_post_orders (
- const struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- struct TMH_HandlerContext *hc)
-{
- return TMH_private_post_orders_with_pos_secrets (rh,
- connection,
- hc,
- NULL,
- TALER_MCA_NONE);
-}
-
-
/* end of taler-merchant-httpd_private-post-orders.c */