merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

account_kyc_get_outdated.sql (2057B)


      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 DROP FUNCTION IF EXISTS merchant.account_kyc_get_outdated;
     18 CREATE FUNCTION merchant.account_kyc_get_outdated(
     19   IN in_now INT8
     20 )
     21 RETURNS TABLE(
     22   out_merchant_id TEXT,
     23   out_h_wire BYTEA,
     24   out_exchange_url TEXT)
     25 LANGUAGE plpgsql
     26 AS $FN$
     27 DECLARE
     28   rec RECORD;
     29   s TEXT;
     30   inner_rec RECORD;
     31 BEGIN
     32   FOR rec IN
     33     SELECT merchant_serial
     34           ,merchant_id
     35       FROM merchant.merchant_instances
     36   LOOP
     37     s := 'merchant_instance_' || rec.merchant_serial::TEXT;
     38     BEGIN
     39       FOR inner_rec
     40       IN
     41         EXECUTE format('SELECT ma.h_wire AS h_wire, kyc.exchange_url AS exchange_url'
     42                        ' FROM %I.merchant_kyc kyc'
     43                        ' JOIN %I.merchant_accounts ma USING (account_serial)'
     44                        ' WHERE kyc.next_kyc_poll < $1'
     45                        ' ORDER BY kyc.next_kyc_poll ASC', s, s)
     46         USING in_now
     47       LOOP
     48         out_merchant_id := rec.merchant_id;
     49         out_h_wire := inner_rec.h_wire;
     50         out_exchange_url := inner_rec.exchange_url;
     51         RETURN NEXT;
     52       END LOOP;
     53     EXCEPTION
     54       WHEN undefined_table
     55       THEN
     56         NULL;
     57     END;
     58   END LOOP;
     59 END
     60 $FN$;
     61 COMMENT ON FUNCTION merchant.account_kyc_get_outdated(INT8)
     62   IS 'Returns one row per outdated KYC entry across all instance schemas.'
     63      ' An entry is outdated if its next_kyc_poll value is less than in_now.';