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