exchange_do_kycauth_in_insert.sql (2385B)
1 -- 2 -- This file is part of TALER 3 -- Copyright (C) 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 18 DROP PROCEDURE IF EXISTS exchange_do_kycauth_in_insert; 19 CREATE PROCEDURE exchange_do_kycauth_in_insert( 20 IN in_account_pub BYTEA, 21 IN in_wire_reference INT8, 22 IN in_credit taler_amount, 23 IN in_wire_source_h_payto BYTEA, 24 IN in_h_normalized_payto BYTEA, 25 IN in_payto_uri TEXT, 26 IN in_exchange_account_name TEXT, 27 IN in_execution_date INT8, 28 IN in_notify_s TEXT) 29 LANGUAGE plpgsql 30 AS $$ 31 DECLARE 32 my_is_wallet BOOL; 33 BEGIN 34 35 INSERT INTO kycauths_in 36 (account_pub 37 ,wire_reference 38 ,credit 39 ,wire_source_h_payto 40 ,exchange_account_section 41 ,execution_date 42 ) VALUES ( 43 in_account_pub 44 ,in_wire_reference 45 ,in_credit 46 ,in_wire_source_h_payto 47 ,in_exchange_account_name 48 ,in_execution_date 49 ) 50 ON CONFLICT DO NOTHING; 51 52 IF NOT FOUND 53 THEN 54 -- presumably already done 55 RETURN; 56 END IF; 57 58 UPDATE kyc_targets 59 SET target_pub=in_account_pub 60 WHERE h_normalized_payto=in_h_normalized_payto; 61 62 IF NOT FOUND 63 THEN 64 -- First time we see this account, setup everything. 65 my_is_wallet 66 = (LOWER (SUBSTRING (in_payto_uri, 0, 23)) = 67 'payto://taler-reserve/') OR 68 (LOWER (SUBSTRING (in_payto_uri, 0, 28)) = 69 'payto://taler-reserve-http/'); 70 INSERT INTO kyc_targets 71 (h_normalized_payto 72 ,is_wallet 73 ,target_pub 74 ) VALUES ( 75 in_h_normalized_payto 76 ,my_is_wallet 77 ,in_account_pub); 78 INSERT INTO wire_targets 79 (wire_target_h_payto 80 ,h_normalized_payto 81 ,payto_uri 82 ) VALUES ( 83 in_wire_source_h_payto 84 ,in_h_normalized_payto 85 ,in_payto_uri); 86 END IF; 87 88 EXECUTE FORMAT ( 89 'NOTIFY %s' 90 ,in_notify_s); 91 92 END $$;