merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 2eaa81fe039f69f31eae74309f229e11c2b006e9
parent 4b1b5854773cf3c62972f35a4b0e4961fb3547c1
Author: Christian Grothoff <christian@grothoff.org>
Date:   Mon, 27 Jul 2020 12:30:31 +0200

make create_token optional

Diffstat:
Msrc/backend/taler-merchant-httpd_private-post-orders.c | 50++++++++++++++++++++++++++++++++++++--------------
1 file changed, 36 insertions(+), 14 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c @@ -1035,12 +1035,9 @@ TMH_private_post_orders (const struct TMH_RequestHandler *rh, unsigned int uuids_len = 0; struct GNUNET_Uuid *uuids = NULL; struct TALER_ClaimTokenP claim_token; - bool create_token; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_json ("order", &order), - GNUNET_JSON_spec_bool ("create_token", - &create_token), GNUNET_JSON_spec_end () }; enum GNUNET_GenericReturnValue ret; @@ -1053,18 +1050,43 @@ TMH_private_post_orders (const struct TMH_RequestHandler *rh, return (GNUNET_NO == ret) ? MHD_YES : MHD_NO; - if (create_token) - { - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, - &claim_token, - sizeof (claim_token)); - } - else + + /* parse and handle the create_token (optionally given) */ { - /* we use all-zeros for 'no token' */ - memset (&claim_token, - 0, - sizeof (claim_token)); + bool create_token = true; /* default */ + + if (NULL != json_object_get (hc->request_body, + "create_token")) + { + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_bool ("create_token", + &create_token), + GNUNET_JSON_spec_end () + }; + enum GNUNET_GenericReturnValue ret; + + (void) rh; + ret = TALER_MHD_parse_json_data (connection, + hc->request_body, + spec); + if (GNUNET_OK != ret) + return (GNUNET_NO == ret) + ? MHD_YES + : MHD_NO; + } + if (create_token) + { + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, + &claim_token, + sizeof (claim_token)); + } + else + { + /* we use all-zeros for 'no token' */ + memset (&claim_token, + 0, + sizeof (claim_token)); + } } /* parse the refund_delay (optionally given) */ if (NULL != json_object_get (hc->request_body,