account_kyc_set_status.sql (2588B)
1 -- 2 -- This file is part of TALER 3 -- Copyright (C) 2024, 2026 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 FUNCTION IF EXISTS merchant_do_account_kyc_set_status; 19 CREATE FUNCTION merchant_do_account_kyc_set_status ( 20 IN in_h_wire BYTEA, 21 IN in_exchange_url TEXT, 22 IN in_timestamp INT8, 23 IN in_exchange_http_status INT4, 24 IN in_exchange_ec_code INT4, 25 IN in_access_token BYTEA, -- can be NULL 26 IN in_jlimits JSONB, 27 IN in_aml_active BOOL, 28 IN in_kyc_ok BOOL, 29 IN in_notify_str TEXT, 30 IN in_notify2_str TEXT, 31 IN in_rule_gen INT8, 32 IN in_next_time INT8, 33 IN in_kyc_backoff INT8, 34 OUT out_no_account BOOL) 35 LANGUAGE plpgsql 36 AS $$ 37 DECLARE 38 my_account_serial INT8; 39 BEGIN 40 41 out_no_account=FALSE; 42 43 SELECT account_serial 44 INTO my_account_serial 45 FROM merchant_accounts 46 WHERE h_wire=in_h_wire; 47 48 IF NOT FOUND 49 THEN 50 out_no_account=TRUE; 51 RETURN; 52 END IF; 53 54 UPDATE merchant_kyc 55 SET kyc_timestamp=in_timestamp 56 ,kyc_ok=in_kyc_ok 57 ,jaccount_limits=in_jlimits 58 ,aml_review=in_aml_active 59 ,exchange_http_status=in_exchange_http_status 60 ,exchange_ec_code=in_exchange_ec_code 61 ,access_token=in_access_token 62 ,last_rule_gen=in_rule_gen 63 ,next_kyc_poll=in_next_time 64 ,kyc_backoff=in_kyc_backoff 65 WHERE account_serial=my_account_serial 66 AND exchange_url=in_exchange_url; 67 68 IF NOT FOUND 69 THEN 70 71 INSERT INTO merchant_kyc 72 (kyc_timestamp 73 ,kyc_ok 74 ,account_serial 75 ,exchange_url 76 ,jaccount_limits 77 ,aml_review 78 ,exchange_http_status 79 ,exchange_ec_code 80 ,access_token 81 ,last_rule_gen 82 ,next_kyc_poll 83 ,kyc_backoff) 84 VALUES 85 (in_timestamp 86 ,in_kyc_ok 87 ,my_account_serial 88 ,in_exchange_url 89 ,in_jlimits 90 ,in_aml_active 91 ,in_exchange_http_status 92 ,in_exchange_ec_code 93 ,in_access_token 94 ,in_rule_gen 95 ,in_next_time 96 ,in_kyc_backoff); 97 END IF; 98 99 EXECUTE FORMAT ( 100 'NOTIFY %s' 101 ,in_notify_str); 102 103 EXECUTE FORMAT ( 104 'NOTIFY %s' 105 ,in_notify2_str); 106 107 108 -- Success! 109 END $$;