exchange_do_insert_sanction_list_hit.sql (2117B)
1 -- 2 -- This file is part of TALER 3 -- Copyright (C) 2025 Taler Systems SA 4 -- 5 -- TALER is free software; you can redistribute it and/or modify it under the 6 -- terms of the GNU General Public License as published by the Free Software 7 -- Foundation; either version 3, or (at your option) any later version. 8 -- 9 -- TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 -- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 -- A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 -- 13 -- You should have received a copy of the GNU General Public License along with 14 -- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 -- 16 17 DROP FUNCTION IF EXISTS exchange_do_insert_sanction_list_hit; 18 CREATE FUNCTION exchange_do_insert_sanction_list_hit( 19 IN in_h_normalized_payto BYTEA, 20 IN in_decision_time INT8, 21 IN in_expiration_time INT8, 22 IN in_properties JSONB, -- can be NULL 23 IN in_new_rules JSONB, -- can be NULL 24 IN in_to_investigate BOOLEAN, 25 IN in_notify_s TEXT, 26 IN ina_events TEXT[], 27 OUT out_outcome_serial_id INT8) 28 LANGUAGE plpgsql 29 AS $$ 30 DECLARE 31 my_i INT4; 32 ini_event TEXT; 33 BEGIN 34 35 -- Disable all previous legitimization outcomes. 36 UPDATE legitimization_outcomes 37 SET is_active=FALSE 38 WHERE h_payto=in_h_normalized_payto; 39 40 INSERT INTO legitimization_outcomes 41 (h_payto 42 ,decision_time 43 ,expiration_time 44 ,jproperties 45 ,to_investigate 46 ,jnew_rules 47 ) 48 VALUES 49 (in_h_normalized_payto 50 ,in_decision_time 51 ,in_expiration_time 52 ,in_properties 53 ,in_to_investigate 54 ,in_new_rules 55 ) 56 RETURNING 57 outcome_serial_id 58 INTO 59 out_outcome_serial_id; 60 61 -- Trigger events 62 FOR i IN 1..COALESCE(array_length(ina_events,1),0) 63 LOOP 64 ini_event = ina_events[i]; 65 INSERT INTO kyc_events 66 (event_timestamp 67 ,event_type) 68 VALUES 69 (in_decision_time 70 ,ini_event); 71 END LOOP; 72 73 EXECUTE FORMAT ( 74 'NOTIFY %s' 75 ,in_notify_s); 76 77 78 END $$; 79 80 81 COMMENT ON FUNCTION exchange_do_insert_sanction_list_hit(BYTEA, INT8, INT8, JSONB, JSONB, BOOLEAN, TEXT, TEXT[]) 82 IS 'Insert result from sanction list check into the table';