From 587382674490778f398c05e970f95cbc2c58f2c3 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 29 Sep 2024 15:45:11 +0200 Subject: re-trigger exchange KYC checks if we failed to create an order due to low limits --- .../taler-merchant-httpd_private-post-orders.c | 49 ++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c index 075c2bbe..cd8644e1 100644 --- a/src/backend/taler-merchant-httpd_private-post-orders.c +++ b/src/backend/taler-merchant-httpd_private-post-orders.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include "taler-merchant-httpd.h" #include "taler-merchant-httpd_private-post-orders.h" @@ -405,9 +406,9 @@ struct OrderContext struct { /** - * Array of exchanges we find acceptable for this - * order. - */ + * Array of exchanges we find acceptable for this + * order. + */ json_t *exchanges; /** @@ -2062,6 +2063,47 @@ get_exchange_keys (void *cls, } +/** + * Check our KYC status at all exchanges as our current limit is + * too low and we failed to create an order. + * + * @param oc order context + */ +static void +notify_kyc_required (const struct OrderContext *oc) +{ + struct GNUNET_DB_EventHeaderP es = { + .size = htons (sizeof (es)), + .type = htons (TALER_DBEVENT_MERCHANT_EXCHANGE_KYC_RULE_TRIGGERED) + }; + char *hws; + char *extra; + json_t *exchange; + size_t i; + + hws = GNUNET_STRINGS_data_to_string_alloc ( + &oc->add_payment_details.wm->h_wire, + sizeof (oc->add_payment_details.wm->h_wire)); + json_array_foreach (oc->set_exchanges.exchanges, i, exchange) + { + const char *exchange_url + = json_string_value (json_object_get (exchange, + "url")); + + GNUNET_asprintf (&extra, + "%s %s", + hws, + exchange_url); + TMH_db->event_notify (TMH_db->cls, + &es, + extra, + strlen (extra) + 1); + GNUNET_free (extra); + } + GNUNET_free (hws); +} + + /** * Set list of acceptable exchanges in @a oc. Upon success, continue * processing with set_max_fee(). @@ -2135,6 +2177,7 @@ set_exchanges (struct OrderContext *oc) GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Cannot create order: %s is the sum of hard limits from supported exchanges\n", TALER_amount2s (&oc->set_exchanges.total_exchange_limit)); + notify_kyc_required (oc); reply_with_error ( oc, MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS, -- cgit v1.2.3