merchant

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

commit 96726fd5ab6dc067af4957c3d1826f9fd2745c95
parent 0232c377c39611f4c476ec9464356f0ae40497d9
Author: Christian Grothoff <christian@grothoff.org>
Date:   Tue,  2 Feb 2021 12:20:43 +0100

extend client and testing libs to support setting authentication tokens (#6731)

Diffstat:
Msrc/backend/taler-merchant-httpd.c | 2+-
Msrc/include/taler_merchant_service.h | 25++++++++++++++++---------
Msrc/include/taler_merchant_testing_lib.h | 4++++
Msrc/lib/merchant_api_patch_instance.c | 5++++-
Msrc/lib/merchant_api_post_instances.c | 8++++++--
Msrc/testing/test_merchant_api.c | 3+++
Msrc/testing/testing_api_cmd_patch_instance.c | 8++++++++
Msrc/testing/testing_api_cmd_post_instances.c | 9+++++++++
8 files changed, 51 insertions(+), 13 deletions(-)

diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2014-2020 Taler Systems SA + (C) 2014-2021 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h @@ -503,6 +503,7 @@ typedef void * @param default_max_deposit_fee default maximum deposit fee merchant is willing to pay * @param default_wire_transfer_delay default wire transfer delay merchant will ask for * @param default_pay_delay default validity period for offers merchant makes + * @param auth_token authorization token needed to access the instance, can be NULL * @param cb function to call with the * backend's instances information * @param cb_cls closure for @a config_cb @@ -523,6 +524,7 @@ TALER_MERCHANT_instances_post ( const struct TALER_Amount *default_max_deposit_fee, struct GNUNET_TIME_Relative default_wire_transfer_delay, struct GNUNET_TIME_Relative default_pay_delay, + const char *auth_token, TALER_MERCHANT_InstancesPostCallback cb, void *cb_cls); @@ -572,6 +574,7 @@ typedef void * @param default_max_deposit_fee default maximum deposit fee merchant is willing to pay * @param default_wire_transfer_delay default wire transfer delay merchant will ask for * @param default_pay_delay default validity period for offers merchant makes + * @param auth_token authorization token needed to access the instance, can be NULL * @param cb function to call with the * backend's instances information * @param cb_cls closure for @a config_cb @@ -592,6 +595,7 @@ TALER_MERCHANT_instance_patch ( const struct TALER_Amount *default_max_deposit_fee, struct GNUNET_TIME_Relative default_wire_transfer_delay, struct GNUNET_TIME_Relative default_pay_delay, + const char *auth_token, TALER_MERCHANT_InstancePatchCallback cb, void *cb_cls); @@ -1244,14 +1248,16 @@ struct TALER_MERCHANT_PostOrdersReply * Details of the reply, depending on the HTTP * status code. */ - union { + union + { /** * Details provided if the @e hr.http_status is * #MHD_HTTP_OK and the order was created. */ - struct { - + struct + { + /** * order id of the newly created order */ @@ -1262,14 +1268,15 @@ struct TALER_MERCHANT_PostOrdersReply * (NULL if it was NOT generated). */ const struct TALER_ClaimTokenP *token; - + } ok; /** * Details provided if the @e hr.http_status is * #MHD_HTTP_GONE because a product was out of stock. - */ - struct { + */ + struct + { /** * ID of the product of the order that is out of * stock. @@ -1291,11 +1298,11 @@ struct TALER_MERCHANT_PostOrdersReply * restocked? 0 for unknown. */ struct GNUNET_TIME_Absolute restock_expected; - + } gone; - + } details; - + }; diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h @@ -137,6 +137,7 @@ TALER_TESTING_cmd_merchant_post_instances (const char *label, * @param default_max_deposit_fee default maximum deposit fee merchant is willing to pay * @param default_wire_transfer_delay default wire transfer delay merchant will ask for * @param default_pay_delay default validity period for offers merchant makes + * @param auth_token authorization token needed to access the instance, can be NULL * @param http_status expected HTTP response code. * @return the command. */ @@ -155,6 +156,7 @@ TALER_TESTING_cmd_merchant_post_instances2 ( const char *default_max_deposit_fee, struct GNUNET_TIME_Relative default_wire_transfer_delay, struct GNUNET_TIME_Relative default_pay_delay, + const char *auth_token, unsigned int http_status); @@ -175,6 +177,7 @@ TALER_TESTING_cmd_merchant_post_instances2 ( * @param default_max_deposit_fee default maximum deposit fee merchant is willing to pay * @param default_wire_transfer_delay default wire transfer delay merchant will ask for * @param default_pay_delay default validity period for offers merchant makes + * @param auth_token authorization token needed to access the instance, can be NULL * @param http_status expected HTTP response code. * @return the command. */ @@ -193,6 +196,7 @@ TALER_TESTING_cmd_merchant_patch_instance ( const char *default_max_deposit_fee, struct GNUNET_TIME_Relative default_wire_transfer_delay, struct GNUNET_TIME_Relative default_pay_delay, + const char *auth_token, unsigned int http_status); diff --git a/src/lib/merchant_api_patch_instance.c b/src/lib/merchant_api_patch_instance.c @@ -164,6 +164,7 @@ TALER_MERCHANT_instance_patch ( const struct TALER_Amount *default_max_deposit_fee, struct GNUNET_TIME_Relative default_wire_transfer_delay, struct GNUNET_TIME_Relative default_pay_delay, + const char *auth_token, TALER_MERCHANT_InstancePatchCallback cb, void *cb_cls) { @@ -188,8 +189,10 @@ TALER_MERCHANT_instance_patch ( return NULL; } } - req_obj = json_pack ("{s:o, s:s, s:O, s:O" + req_obj = json_pack ("{s:s?, s:o, s:s, s:O, s:O" " s:o, s:I: s:o, s:o, s:o}", + "auth_token", + auth_token, "payto_uris", jpayto_uris, "name", diff --git a/src/lib/merchant_api_post_instances.c b/src/lib/merchant_api_post_instances.c @@ -166,6 +166,7 @@ TALER_MERCHANT_instances_post ( const struct TALER_Amount *default_max_deposit_fee, struct GNUNET_TIME_Relative default_wire_transfer_delay, struct GNUNET_TIME_Relative default_pay_delay, + const char *auth_token, TALER_MERCHANT_InstancesPostCallback cb, void *cb_cls) { @@ -191,7 +192,8 @@ TALER_MERCHANT_instances_post ( } } req_obj = json_pack ("{s:o, s:s, s:s, s:O, s:O" - " s:o, s:I: s:o, s:o, s:o}", + ",s:o, s:I: s:o, s:o, s:o" + ",s:s?}", "payto_uris", jpayto_uris, "id", @@ -212,7 +214,9 @@ TALER_MERCHANT_instances_post ( "default_wire_transfer_delay", GNUNET_JSON_from_time_rel (default_wire_transfer_delay), "default_pay_delay", - GNUNET_JSON_from_time_rel (default_pay_delay)); + GNUNET_JSON_from_time_rel (default_pay_delay), + "auth_token", + auth_token); if (NULL == req_obj) { GNUNET_break (0); diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c @@ -1181,6 +1181,7 @@ run (void *cls, "USD:0.5", GNUNET_TIME_UNIT_MINUTES, GNUNET_TIME_UNIT_MINUTES, + NULL, MHD_HTTP_CONFLICT), TALER_TESTING_cmd_merchant_patch_instance ("instance-patch-i1", merchant_url, @@ -1199,6 +1200,7 @@ run (void *cls, "EUR:0.5", GNUNET_TIME_UNIT_MINUTES, GNUNET_TIME_UNIT_MINUTES, + NULL, MHD_HTTP_NO_CONTENT), TALER_TESTING_cmd_merchant_get_instance2 ("instances-get-i1-2", merchant_url, @@ -1227,6 +1229,7 @@ run (void *cls, "EUR:0.5", GNUNET_TIME_UNIT_MINUTES, GNUNET_TIME_UNIT_MINUTES, + NULL, MHD_HTTP_NO_CONTENT), TALER_TESTING_cmd_merchant_get_instance2 ("instances-get-i1-3", merchant_url, diff --git a/src/testing/testing_api_cmd_patch_instance.c b/src/testing/testing_api_cmd_patch_instance.c @@ -80,6 +80,11 @@ struct PatchInstanceState json_t *jurisdiction; /** + * Authentication token to require, can be NULL. + */ + const char *auth_token; + + /** * Wire fee to use. */ struct TALER_Amount default_max_wire_fee; @@ -177,6 +182,7 @@ patch_instance_run (void *cls, &pis->default_max_deposit_fee, pis->default_wire_transfer_delay, pis->default_pay_delay, + pis->auth_token, &patch_instance_cb, pis); GNUNET_assert (NULL != pis->iph); @@ -279,6 +285,7 @@ TALER_TESTING_cmd_merchant_patch_instance ( const char *default_max_deposit_fee, struct GNUNET_TIME_Relative default_wire_transfer_delay, struct GNUNET_TIME_Relative default_pay_delay, + const char *auth_token, unsigned int http_status) { struct PatchInstanceState *pis; @@ -305,6 +312,7 @@ TALER_TESTING_cmd_merchant_patch_instance ( &pis->default_max_deposit_fee)); pis->default_wire_transfer_delay = default_wire_transfer_delay; pis->default_pay_delay = default_pay_delay; + pis->auth_token = auth_token; { struct TALER_TESTING_Command cmd = { .cls = pis, diff --git a/src/testing/testing_api_cmd_post_instances.c b/src/testing/testing_api_cmd_post_instances.c @@ -80,6 +80,11 @@ struct PostInstancesState json_t *jurisdiction; /** + * Authentication token to require for this instance. + */ + const char *auth_token; + + /** * Wire fee to use. */ struct TALER_Amount default_max_wire_fee; @@ -180,6 +185,7 @@ post_instances_run (void *cls, &pis->default_max_deposit_fee, pis->default_wire_transfer_delay, pis->default_pay_delay, + pis->auth_token, &post_instances_cb, pis); GNUNET_assert (NULL != pis->iph); @@ -282,6 +288,7 @@ TALER_TESTING_cmd_merchant_post_instances2 ( const char *default_max_deposit_fee, struct GNUNET_TIME_Relative default_wire_transfer_delay, struct GNUNET_TIME_Relative default_pay_delay, + const char *auth_token, unsigned int http_status) { struct PostInstancesState *pis; @@ -308,6 +315,7 @@ TALER_TESTING_cmd_merchant_post_instances2 ( &pis->default_max_deposit_fee)); pis->default_wire_transfer_delay = default_wire_transfer_delay; pis->default_pay_delay = default_pay_delay; + pis->auth_token = auth_token; { struct TALER_TESTING_Command cmd = { .cls = pis, @@ -356,6 +364,7 @@ TALER_TESTING_cmd_merchant_post_instances (const char *label, default_max_fee_s, GNUNET_TIME_UNIT_ZERO, /* no wire transfer delay */ GNUNET_TIME_UNIT_MINUTES, + NULL, http_status); }