merchant

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

select_wirewatch_accounts.sql (2125B)


      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_wirewatch_accounts();
     18 CREATE FUNCTION merchant.select_wirewatch_accounts()
     19 RETURNS TABLE(
     20   out_merchant_id TEXT,
     21   out_payto_uri TEXT,
     22   out_credit_facade_url TEXT,
     23   out_credit_facade_credentials JSONB,
     24   out_last_bank_serial INT8)
     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 IN
     40         EXECUTE format(
     41           'SELECT'
     42           '  payto_uri AS pu'
     43           ' ,credit_facade_url AS cfu'
     44           ' ,credit_facade_credentials AS cfc'
     45           ' ,last_bank_serial AS lbs'
     46           ' FROM %I.merchant_accounts'
     47           ' WHERE active'
     48           '   AND credit_facade_url IS NOT NULL', s)
     49       LOOP
     50         out_merchant_id := rec.merchant_id;
     51         out_payto_uri := inner_rec.pu;
     52         out_credit_facade_url := inner_rec.cfu;
     53         out_credit_facade_credentials := inner_rec.cfc;
     54         out_last_bank_serial := inner_rec.lbs;
     55         RETURN NEXT;
     56       END LOOP;
     57     EXCEPTION
     58       WHEN undefined_table
     59       THEN
     60         NULL;
     61     END;
     62   END LOOP;
     63 END
     64 $FN$;
     65 COMMENT ON FUNCTION merchant.select_wirewatch_accounts()
     66   IS 'Returns one row per active credit-facade-enabled merchant_account'
     67      ' across all instance schemas.';