insert_unclaim_signature.sql (1916B)
1 -- 2 -- This file is part of TALER 3 -- Copyright (C) 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_insert_unclaim_signature; 19 CREATE FUNCTION merchant_do_insert_unclaim_signature ( 20 IN in_order_id TEXT, 21 IN in_nonce_str TEXT, 22 IN in_notify_str TEXT, 23 IN in_h_contract_terms BYTEA, 24 IN in_nonce_sig BYTEA, 25 OUT out_found BOOL) 26 LANGUAGE plpgsql 27 AS $$ 28 DECLARE 29 my_expiration_time INT8; 30 BEGIN 31 32 SELECT pay_deadline 33 INTO my_expiration_time 34 FROM merchant_contract_terms 35 WHERE order_id=in_order_id 36 AND contract_terms->>'nonce' = in_nonce_str; 37 38 IF NOT FOUND 39 THEN 40 -- FIXME: distinguish better between 41 -- different "not found" cases (contract, unclaim sig exists) 42 out_found = FALSE; 43 RETURN; 44 END IF; 45 46 INSERT INTO merchant_unclaim_signatures 47 (h_contract_terms 48 ,unclaim_sig 49 ,expiration_time) 50 VALUES 51 (in_h_contract_terms 52 ,in_nonce_sig 53 ,my_expiration_time) 54 ON CONFLICT DO NOTHING; 55 56 IF FOUND 57 THEN 58 out_found = TRUE; 59 60 -- order status change notification 61 EXECUTE FORMAT ( 62 'NOTIFY %s' 63 ,in_notify_str); 64 65 RETURN; 66 END IF; 67 68 PERFORM FROM merchant_unclaim_signatures 69 WHERE h_contract_terms = in_h_contract_terms 70 AND unclaim_sig = in_nonce_sig; 71 out_found = FOUND; 72 73 END $$;