exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

taler-exchange-helper-measure-challenger-postal-context-check (5144B)


      1 #!/bin/bash
      2 #
      3 #  This file is part of TALER
      4 #  Copyright (C) 2025 Taler Systems SA
      5 #
      6 #  TALER is free software; you can redistribute it and/or modify it under the
      7 #  terms of the GNU General Public License as published by the Free Software
      8 #  Foundation; either version 3, or (at your option) any later version.
      9 #
     10 #  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     11 #  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     12 #  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     13 #
     14 #  You should have received a copy of the GNU General Public License along with
     15 #  TALER; see the file COPYING.  If not, If not, see <http://www.gnu.org/license>
     16 #
     17 
     18 # Hard error reporting on.
     19 set -eu
     20 
     21 # Exit, with error message (hard failure)
     22 function exit_fail() {
     23     echo " FAIL: " "$@" >&2
     24     EXIT_STATUS=1
     25     exit "$EXIT_STATUS"
     26 }
     27 
     28 CONF="$HOME/.config/taler-exchange.conf"
     29 VERBOSE=0
     30 
     31 while getopts 'ac:hirvV' OPTION;
     32 do
     33     case "$OPTION" in
     34         a)
     35             exit 0
     36             ;;
     37         c)
     38             # shellcheck disable=SC2034
     39             CONF="$OPTARG"
     40             ;;
     41         h)
     42             echo "This is an AML program that asks the customer to validate an address it given to the measure from the context. It is to be used when AML officers want a specific address to be validated via postal letter."
     43             echo 'Supported options:'
     44             echo '  -a           -- show required attributes'
     45             # shellcheck disable=SC2016
     46             echo '  -c $CONF     -- set configuration'
     47             echo '  -h           -- print this help'
     48             echo '  -i           -- show required inputs'
     49             echo '  -r           -- show required context'
     50             echo '  -v           -- show version'
     51             echo '  -V           -- be verbose'
     52             exit 0
     53             ;;
     54         i)
     55             # Need attributes, context and current_rules.
     56             echo "context"
     57             echo "current_rules"
     58             echo "default_rules"
     59             exit 0
     60             ;;
     61         r)
     62             echo "FULL_NAME"
     63             echo "ADDRESS_LINES"
     64             echo "ADDRESS_COUNTRY"
     65             exit 0
     66             ;;
     67         v)
     68             echo "$0 v0.0.1"
     69             exit 0
     70             ;;
     71         V)
     72             VERBOSE=1
     73             ;;
     74         ?)
     75         exit_fail "Unrecognized command line option"
     76         ;;
     77     esac
     78 done
     79 
     80 if [ 1 = "$VERBOSE" ]
     81 then
     82     echo "Running $0" 1>&2
     83 fi
     84 
     85 # See https://docs.taler.net/taler-kyc-manual.html#tsref-type-AmlProgramInput
     86 # for the full JSON with possible inputs.
     87 
     88 # First, extract inputs we need
     89 INPUTS=$(jq '{"current_rules":(.current_rules // .default_rules // error("neither current_rules nor default_rules provided")),"context":.context}')
     90 
     91 # Get address data
     92 J_CONTACT_NAME=$(echo "$INPUTS" | jq '.context.FULL_NAME')
     93 J_ADDRESS_LINES=$(echo "$INPUTS" | jq '.context.ADDRESS_LINES')
     94 J_ADDRESS_COUNTRY=$(echo "$INPUTS" | jq '.context.ADDRESS_COUNTRY // null')
     95 
     96 # Convert address data to Challenger format as best we can.
     97 ADDRESS=$(jq -n \
     98     --argjson contact_name "$J_CONTACT_NAME" \
     99     --argjson address_lines "$J_ADDRESS_LINES" \
    100     --argjson address_country "$J_ADDRESS_COUNTRY" \
    101     '{"CONTACT_NAME":$contact_name,"ADDRESS_LINES":$address_lines,"ADDRESS_COUNTRY":$address_country,"read_only":true}')
    102 
    103 # Get current rules
    104 CURRENT_RULES=$(echo "$INPUTS" | jq '.current_rules // null')
    105 # Get context values
    106 EXPIRATION_TIME=$(echo "$INPUTS" | jq '.context.expiration_time // .current_rules.expiration_time // null')
    107 # Get successor measure from current rules, if any (still applies if this new measure expires)
    108 CSUCCESSOR_MEASURE=$(echo "$INPUTS" | jq '.current_rules.successor_measure // null')
    109 # Context for AML program EXEC_NAME, if any.
    110 NEXT_CONTEXT=$(echo "$INPUTS" | jq '.context.next_context // {}')
    111 # Get successor program from context
    112 EXEC_NAME=$(echo "$INPUTS" | jq '.context.exec_name // "taler-exchange-helper-measure-inform-investigate"')
    113 
    114 # Define custom measure for address validation.
    115 # We always first run a program to clear the address validation measure,
    116 # and then run whatever program we were given from the context (if any).
    117 # If none was given in the context, we run 'inform-investigate'.
    118 CUSTOM_AMEASURES=$(jq -n \
    119     --argjson address "$ADDRESS" \
    120     --argjson en "$EXEC_NAME" \
    121     --argjson nc "$NEXT_CONTEXT" \
    122     '{"custom-address-investigation":{"context":{"initial_address":$address,"exec_name":$en,"next_context":$nc,"clear_measure":"custom-address-investigation"},"check_name":"postal-registration","prog_name":"clear-measure-and-continue"}}')
    123 
    124 # Finally, output the new rules.
    125 # See https://docs.taler.net/taler-kyc-manual.html#tsref-type-AmlOutcome
    126 # for the required output format.
    127 
    128 jq -n \
    129     --argjson et "$EXPIRATION_TIME" \
    130     --argjson sm "$CSUCCESSOR_MEASURE" \
    131     --argjson nm '"custom-address-investigation"' \
    132     --argjson cma "$CUSTOM_AMEASURES" \
    133     --argjson nr "$CURRENT_RULES" \
    134     '{"new_measures":$nm,"new_rules":($nr+{"expiration_time":$et,"successor_measure":$sm,"custom_measures":({}+$nr.custom_measures+$cma)})}|del(..|nulls)'
    135 
    136 exit 0