merchant

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

pg_select_accounts.sql (2429B)


      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.select_accounts;
     18 CREATE FUNCTION merchant.select_accounts()
     19 RETURNS TABLE(
     20   out_merchant_id TEXT,
     21   out_merchant_priv BYTEA,
     22   out_h_wire BYTEA,
     23   out_salt BYTEA,
     24   out_payto_uri TEXT,
     25   out_credit_facade_url TEXT,
     26   out_credit_facade_credentials JSONB,
     27   out_extra_wire_subject_metadata TEXT,
     28   out_active BOOLEAN)
     29 LANGUAGE plpgsql
     30 AS $$
     31 DECLARE
     32   rec RECORD;
     33 BEGIN
     34   FOR rec IN
     35     SELECT mi.merchant_serial
     36           ,mi.merchant_id
     37           ,mi.merchant_priv
     38       FROM merchant.merchant_instances mi
     39   LOOP
     40     BEGIN
     41       FOR out_h_wire,
     42           out_salt,
     43           out_payto_uri,
     44           out_credit_facade_url,
     45           out_credit_facade_credentials,
     46           out_extra_wire_subject_metadata,
     47           out_active
     48       IN EXECUTE format('SELECT'
     49                         ' h_wire'
     50                         ',salt'
     51                         ',payto_uri'
     52                         ',credit_facade_url'
     53                         ',credit_facade_credentials'
     54                         ',extra_wire_subject_metadata'
     55                         ',active'
     56                         ' FROM %I.merchant_accounts',
     57                         'merchant_instance_' || rec.merchant_serial::TEXT)
     58       LOOP
     59         out_merchant_id := rec.merchant_id;
     60         out_merchant_priv := rec.merchant_priv;
     61         RETURN NEXT;
     62       END LOOP;
     63     EXCEPTION
     64       WHEN undefined_table THEN
     65         NULL;
     66     END;
     67   END LOOP;
     68 END $$;
     69 
     70 COMMENT ON FUNCTION merchant.select_accounts()
     71   IS 'Returns one row per merchant_account across all (or one) instance schemas;'
     72      ' merchant_priv is read from merchant.merchant_instances (NULL if absent).'
     73      ' If in_merchant_id is non-NULL, only that instance is scanned.';