exchange_do_insert_aml_program_failure.sql (2337B)
1 -- 2 -- This file is part of TALER 3 -- Copyright (C) 2023, 2024 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_aml_program_failure; 18 CREATE FUNCTION exchange_do_insert_aml_program_failure ( 19 IN in_legitimization_process_serial_id INT8, 20 IN in_h_payto BYTEA, 21 IN in_now INT8, 22 IN in_error_code INT4, 23 IN in_error_message TEXT, 24 IN in_kyc_completed_notify_s TEXT, 25 OUT out_update BOOLEAN) -- set to true if we had a legi process matching in_process_row and in_provider_name for this account 26 LANGUAGE plpgsql 27 AS $$ 28 BEGIN 29 30 31 UPDATE legitimization_processes 32 SET finished=TRUE 33 ,error_code=in_error_code 34 ,error_message=in_error_message 35 WHERE h_payto=in_h_payto 36 AND legitimization_process_serial_id=in_legitimization_process_serial_id; 37 out_update = FOUND; 38 IF NOT FOUND 39 THEN 40 -- Note: in_legitimization_process_serial_id should always be 0 here. 41 -- But we do not check and simply always create a new entry to at least 42 -- not loose information about the event! 43 INSERT INTO legitimization_processes 44 (finished 45 ,error_code 46 ,error_message 47 ,h_payto 48 ,start_time 49 ,provider_section 50 ) VALUES ( 51 TRUE 52 ,in_error_code 53 ,in_error_message 54 ,in_h_payto 55 ,in_now 56 ,'skip' 57 ); 58 END IF; 59 60 EXECUTE FORMAT ( 61 'NOTIFY %s' 62 ,in_kyc_completed_notify_s); 63 64 INSERT INTO kyc_alerts 65 (h_payto 66 ,trigger_type) 67 VALUES 68 (in_h_payto,1) 69 ON CONFLICT DO NOTHING; 70 71 END $$; 72 73 74 COMMENT ON FUNCTION exchange_do_insert_aml_program_failure(INT8, BYTEA, INT8, INT4, TEXT, TEXT) 75 IS 'Stores information about an AML program run that failed into the legitimization_processes table. Either updates a row of an existing legitimization process, or creates a new entry.';