summaryrefslogtreecommitdiff
path: root/src/exchange/taler-exchange-httpd_kyc-webhook.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/exchange/taler-exchange-httpd_kyc-webhook.c')
-rw-r--r--src/exchange/taler-exchange-httpd_kyc-webhook.c157
1 files changed, 97 insertions, 60 deletions
diff --git a/src/exchange/taler-exchange-httpd_kyc-webhook.c b/src/exchange/taler-exchange-httpd_kyc-webhook.c
index f8fe711da..b92b43e69 100644
--- a/src/exchange/taler-exchange-httpd_kyc-webhook.c
+++ b/src/exchange/taler-exchange-httpd_kyc-webhook.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ Copyright (C) 2022-2023 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
@@ -28,6 +28,7 @@
#include "taler_json_lib.h"
#include "taler_mhd_lib.h"
#include "taler_kyclogic_lib.h"
+#include "taler-exchange-httpd_common_kyc.h"
#include "taler-exchange-httpd_kyc-webhook.h"
#include "taler-exchange-httpd_responses.h"
@@ -54,6 +55,11 @@ struct KycWebhookContext
struct TEH_RequestContext *rc;
/**
+ * Handle for the KYC-AML trigger interaction.
+ */
+ struct TEH_KycAmlTrigger *kat;
+
+ /**
* Plugin responsible for the webhook.
*/
struct TALER_KYCLOGIC_Plugin *plugin;
@@ -141,6 +147,28 @@ TEH_kyc_webhook_cleanup (void)
/**
+ * Function called after the KYC-AML trigger is done.
+ *
+ * @param cls closure with a `struct KycWebhookContext *`
+ * @param http_status final HTTP status to return
+ * @param[in] response final HTTP ro return
+ */
+static void
+kyc_aml_webhook_finished (
+ void *cls,
+ unsigned int http_status,
+ struct MHD_Response *response)
+{
+ struct KycWebhookContext *kwh = cls;
+
+ kwh->kat = NULL;
+ kwh->response = response;
+ kwh->response_code = http_status;
+ kwh_resume (kwh);
+}
+
+
+/**
* Function called with the result of a KYC webhook operation.
*
* Note that the "decref" for the @a response
@@ -178,58 +206,53 @@ webhook_finished_cb (
switch (status)
{
case TALER_KYCLOGIC_STATUS_SUCCESS:
- /* _successfully_ resumed case */
+ kwh->kat = TEH_kyc_finished (
+ &kwh->rc->async_scope_id,
+ process_row,
+ account_id,
+ provider_section,
+ provider_user_id,
+ provider_legitimization_id,
+ expiration,
+ attributes,
+ http_status,
+ response,
+ &kyc_aml_webhook_finished,
+ kwh);
+ if (NULL == kwh->kat)
+ {
+ if (NULL != response)
+ MHD_destroy_response (response);
+ http_status = MHD_HTTP_INTERNAL_SERVER_ERROR;
+ response = TALER_MHD_make_error (
+ TALER_EC_EXCHANGE_GENERIC_BAD_CONFIGURATION,
+ "[exchange] AML_KYC_TRIGGER");
+ break;
+ }
+ return;
+ case TALER_KYCLOGIC_STATUS_FAILED:
+ case TALER_KYCLOGIC_STATUS_PROVIDER_FAILED:
+ case TALER_KYCLOGIC_STATUS_USER_ABORTED:
+ case TALER_KYCLOGIC_STATUS_ABORTED:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC process %s/%s (Row #%llu) failed: %d\n",
+ provider_user_id,
+ provider_legitimization_id,
+ (unsigned long long) process_row,
+ status);
+ if (! TEH_kyc_failed (process_row,
+ account_id,
+ provider_section,
+ provider_user_id,
+ provider_legitimization_id))
{
- enum GNUNET_DB_QueryStatus qs;
- size_t eas;
- void *ea;
- const char *birthdate;
- struct GNUNET_ShortHashCode kyc_prox;
-
- TALER_CRYPTO_attributes_to_kyc_prox (attributes,
- &kyc_prox);
- birthdate = json_string_value (json_object_get (attributes,
- TALER_ATTRIBUTE_BIRTHDATE));
- TALER_CRYPTO_kyc_attributes_encrypt (&TEH_attribute_key,
- attributes,
- &ea,
- &eas);
- qs = TEH_plugin->insert_kyc_attributes (
- TEH_plugin->cls,
- account_id,
- &kyc_prox,
- provider_section,
- birthdate,
- GNUNET_TIME_timestamp_get (),
- GNUNET_TIME_absolute_to_timestamp (expiration),
- eas,
- ea);
- GNUNET_free (ea);
- if (qs < 0)
- {
- GNUNET_break (0);
- kwh->response = TALER_MHD_make_error (TALER_EC_GENERIC_DB_STORE_FAILED,
- "insert_kyc_attributes");
- kwh->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
- kwh_resume (kwh);
- return;
- }
- qs = TEH_plugin->update_kyc_process_by_row (TEH_plugin->cls,
- process_row,
- provider_section,
- account_id,
- provider_user_id,
- provider_legitimization_id,
- expiration);
- if (qs < 0)
- {
- GNUNET_break (0);
- kwh->response = TALER_MHD_make_error (TALER_EC_GENERIC_DB_STORE_FAILED,
- "set_kyc_ok");
- kwh->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
- kwh_resume (kwh);
- return;
- }
+ GNUNET_break (0);
+ if (NULL != response)
+ MHD_destroy_response (response);
+ http_status = MHD_HTTP_INTERNAL_SERVER_ERROR;
+ response = TALER_MHD_make_error (
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "insert_kyc_failure");
}
break;
default:
@@ -238,12 +261,13 @@ webhook_finished_cb (
provider_user_id,
provider_legitimization_id,
(unsigned long long) process_row,
- status);
+ (int) status);
break;
}
- kwh->response = response;
- kwh->response_code = http_status;
- kwh_resume (kwh);
+ GNUNET_break (NULL == kwh->kat);
+ kyc_aml_webhook_finished (kwh,
+ http_status,
+ response);
}
@@ -262,6 +286,11 @@ clean_kwh (struct TEH_RequestContext *rc)
kwh->plugin->webhook_cancel (kwh->wh);
kwh->wh = NULL;
}
+ if (NULL != kwh->kat)
+ {
+ TEH_kyc_finished_cancel (kwh->kat);
+ kwh->kat = NULL;
+ }
if (NULL != kwh->response)
{
MHD_destroy_response (kwh->response);
@@ -311,6 +340,10 @@ handler_kyc_webhook_generic (
TALER_EC_EXCHANGE_KYC_GENERIC_LOGIC_UNKNOWN,
args[0]);
}
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC logic `%s' mapped to section %s\n",
+ args[0],
+ kwh->provider_section);
kwh->wh = kwh->plugin->webhook (kwh->plugin->cls,
kwh->pd,
TEH_plugin->kyc_provider_account_lookup,
@@ -336,13 +369,17 @@ handler_kyc_webhook_generic (
MHD_suspend_connection (rc->connection);
return MHD_YES;
}
+ GNUNET_break (GNUNET_NO == kwh->suspended);
if (NULL != kwh->response)
{
- /* handle _failed_ resumed cases */
- return MHD_queue_response (rc->connection,
- kwh->response_code,
- kwh->response);
+ MHD_RESULT res;
+
+ res = MHD_queue_response (rc->connection,
+ kwh->response_code,
+ kwh->response);
+ GNUNET_break (MHD_YES == res);
+ return res;
}
/* We resumed, but got no response? This should