add document download logic for kycaid

This commit is contained in:
Christian Grothoff 2023-05-23 15:44:23 +02:00
parent 89e2a02380
commit ae6e62a0a3
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
3 changed files with 44 additions and 9 deletions

View File

@ -941,12 +941,16 @@ handle_webhook_finished (void *cls,
resp); resp);
break; break;
} }
wh->econ = TALER_JSON_external_conversion_start (j, wh->econ
&webhook_conversion_cb, = TALER_JSON_external_conversion_start (
wh, j,
wh->pd->conversion_helper, &webhook_conversion_cb,
wh->pd->conversion_helper, wh,
NULL); wh->pd->conversion_helper,
wh->pd->conversion_helper,
"-a",
wh->pd->auth_token,
NULL);
return; return;
} }
break; break;

View File

@ -24,13 +24,43 @@ while getopts ':a:' OPTION; do
done done
# First, extract everything from stdin. # First, extract everything from stdin.
J=$(jq '{"type":.type,"email":.email,"phone":.phone,"first_name":.first_name,"name-middle":.middle_name,"last_name":.last_name,"dob":.dob,"residence_country":.residence_country,"gender":.gender,"pep":.pep,"addresses":.addresses,"documents":.documents,"company_name":.company_name,"business_activity_id":.business_activity_id,"registration_country":.registration_country}') J=$(jq '{"type":.type,"email":.email,"phone":.phone,"first_name":.first_name,"name-middle":.middle_name,"last_name":.last_name,"dob":.dob,"residence_country":.residence_country,"gender":.gender,"pep":.pep,"addresses":.addresses,"documents":.documents,"company_name":.company_name,"business_activity_id":.business_activity_id,"registration_country":.registration_country,"documents":.documents,"decline_reasons":.decline_reasons}')
# TODO: # TODO:
# log_failure (json_object_get (j, "decline_reasons")); # log_failure (json_object_get (j, "decline_reasons"));
TYPE=$(echo "$J" | jq -r '.person') TYPE=$(echo "$J" | jq -r '.person')
N=0
DOCS_RAW=""
DOCS_JSON=""
for ID in $(jq -r '.documents[]|select(.status=="valid")|.id')
do
TYPE=$(jq -r ".documents[]|select(.id==\"$ID\")|.type")
EXPIRY=$(jq -r ".documents[]|select(.id==\"$ID\")|.expiry_date")
DOCUMENT_FILE=$(mktemp -t tmp.XXXXXXXXXX)
# Authoriazation: Token $TOKEN
DOCUMENT_URL="https://api.kycaid.com/documents/$ID"
if [ -z "${TOKEN:-}" ]
then
wget -q --output-document=- "$DOCUMENT_URL" \
| gnunet-base32 > ${DOCUMENT_FILE}
else
wget -q --output-document=- "$DOCUMENT_URL" \
--header "Authorization: Token $TOKEN" \
| gnunet-base32 > ${DOCUMENT_FILE}
fi
DOCS_RAW="$DOCS_RAW --rawfile photo$N \"${DOCUMENT_FILE}\""
if [ "$N" = 0 ]
then
DOCS_JSON="{\"type\":\"$TYPE\",\"image\":\$photo$N}"
else
DOCS_JSON="{\"type\":\"$TYPE\",\"image\":\$photo$N},$DOCS_JSON"
fi
N=$(expr $N + 1)
done
if [ "person" = "${TYPE}" ] if [ "person" = "${TYPE}" ]
then then
@ -49,7 +79,8 @@ else
# Combine into final result for business. # Combine into final result for business.
echo "$J" | jq \ echo "$J" | jq \
--arg full_name "${FULLNAME}" \ --arg full_name "${FULLNAME}" \
'{"company_name":.company_name,"phone":.phone,"email":.email,"registration_country":.registration_country}' $DOCS_RAW \
"{\"company_name\":.company_name,\"phone\":.phone,\"email\":.email,\"registration_country\":.registration_country,\"documents\":[${DOCS_JSON}]}"
fi fi
exit 0 exit 0

View File

@ -78,7 +78,7 @@ TALER_MHD_parse_config (const struct GNUNET_CONFIGURATION_Handle *cfg,
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (cfg, GNUNET_CONFIGURATION_get_value_number (cfg,
section, section,
"port", "PORT",
&port)) &port))
{ {
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,