merchant

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

commit 28b80ac78306bfa216ab9638f40f65bd86eef716
parent 0f3490dc022620c7e42b86426e14198a04c2e17f
Author: Christian Grothoff <grothoff@gnunet.org>
Date:   Fri, 13 Oct 2023 21:06:58 +0200

add currency specification parsing to /config logic in libtalermerchant

Diffstat:
Msrc/include/taler_merchant_service.h | 17+++++++++++++++--
Msrc/lib/merchant_api_common.c | 2+-
Msrc/lib/merchant_api_get_config.c | 40++++++++++++++++++++++++++++++++++++++--
3 files changed, 54 insertions(+), 5 deletions(-)

diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h @@ -211,7 +211,7 @@ struct TALER_MERCHANT_RefundUriData * @param[out] parse_data data extracted from the URI. Must be free'd. * @return #GNUNET_SYSERR if @e refund_uri is malformed, #GNUNET_OK otherwise. */ -int +enum GNUNET_GenericReturnValue TALER_MERCHANT_parse_refund_uri ( const char *refund_uri, struct TALER_MERCHANT_RefundUriData *parse_data); @@ -288,7 +288,8 @@ enum TALER_MERCHANT_VersionCompatibility struct TALER_MERCHANT_ConfigInformation { /** - * Currency used/supported by the merchant. + * Default currency of the merchant. See cspecs + * for all currencies supported by the merchant. */ const char *currency; @@ -333,6 +334,18 @@ struct TALER_MERCHANT_ConfigResponse * protocol compatibility information */ enum TALER_MERCHANT_VersionCompatibility compat; + + /** + * Length of the @e cspecs array. + */ + unsigned int num_cspecs; + + /** + * Array with rendering specifications for the currencies + * supported by this merchant backend. + */ + const struct TALER_CurrencySpecification *cspecs; + } ok; } details; }; diff --git a/src/lib/merchant_api_common.c b/src/lib/merchant_api_common.c @@ -245,7 +245,7 @@ TALER_MERCHANT_parse_pay_uri_free ( } -int +enum GNUNET_GenericReturnValue TALER_MERCHANT_parse_refund_uri ( const char *refund_uri, struct TALER_MERCHANT_RefundUriData *parse_data) diff --git a/src/lib/merchant_api_get_config.c b/src/lib/merchant_api_get_config.c @@ -104,7 +104,10 @@ handle_config_finished (void *cls, { case MHD_HTTP_OK: { + const json_t *jcs; struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_object_const ("currencies", + &jcs), GNUNET_JSON_spec_string ("currency", &cr.details.ok.ci.currency), GNUNET_JSON_spec_string ("version", @@ -153,8 +156,41 @@ handle_config_finished (void *cls, } } } - vgh->cb (vgh->cb_cls, - &cr); + { + unsigned int nspec = json_object_size (jcs); + struct TALER_CurrencySpecification *cspecs; + unsigned int off = 0; + json_t *obj; + const char *curr; + + cspecs = GNUNET_new_array (nspec, + struct TALER_CurrencySpecification); + cr.details.ok.num_cspecs = nspec; + cr.details.ok.cspecs = cspecs; + json_object_foreach ((json_t *) jcs, curr, obj) + { + struct TALER_CurrencySpecification *cs = &cspecs[off++]; + struct GNUNET_JSON_Specification cspec[] = { + TALER_JSON_spec_currency_specification (curr, + cs), + GNUNET_JSON_spec_end () + }; + + if (GNUNET_OK != + GNUNET_JSON_parse (jcs, + cspec, + NULL, NULL)) + { + cr.hr.http_status = 0; + cr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + break; + } + } + vgh->cb (vgh->cb_cls, + &cr); + TALER_CONFIG_free_currencies (nspec, + cspecs); + } TALER_MERCHANT_config_get_cancel (vgh); return; }