syncdb_account_check.sql (1526B)
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 -- Helper to check that an account exists and has a valid (non-expired) payment. 19 -- Returns TRUE in out_account_missing if the account is missing or expired. 20 -- 21 22 DROP FUNCTION IF EXISTS sync_check_account_payment; 23 CREATE FUNCTION sync_check_account_payment( 24 IN in_account_pub BYTEA) 25 RETURNS TABLE ( 26 out_account_missing BOOLEAN) 27 LANGUAGE plpgsql 28 AS $$ 29 DECLARE 30 my_expiration_date INT8; 31 BEGIN 32 out_account_missing := FALSE; 33 34 SELECT expiration_date 35 INTO my_expiration_date 36 FROM accounts 37 WHERE account_pub = in_account_pub; 38 39 IF NOT FOUND 40 THEN 41 out_account_missing := TRUE; 42 RETURN NEXT; 43 RETURN; 44 END IF; 45 46 IF my_expiration_date <= (EXTRACT(EPOCH FROM NOW()) * 1000000)::INT8 47 THEN 48 out_account_missing := TRUE; 49 RETURN NEXT; 50 RETURN; 51 END IF; 52 53 RETURN NEXT; 54 RETURN; 55 END $$;