merchant

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

merchant-0032.sql (2485B)


      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 -- @file merchant-0032.sql
     17 -- @brief Add field for one-shot reports in the merchant_reports table
     18 -- @author Christian Grothoff
     19 
     20 BEGIN;
     21 
     22 -- Check patch versioning is in place.
     23 SELECT _v.register_patch('merchant-0032', NULL, NULL);
     24 
     25 SET search_path TO merchant;
     26 
     27 ALTER TABLE merchant_reports
     28   ADD COLUMN one_shot_hidden BOOL DEFAULT(FALSE);
     29 
     30 COMMENT ON COLUMN merchant_reports.one_shot_hidden
     31   IS 'True for reports that are only supposed to trigger once and that should be hidden from the user interface as they are internally generated. Used for alerts, such as those generated when the KYC status changes.';
     32 
     33 
     34 CREATE FUNCTION random_bytea(
     35   bytea_length INT
     36 )
     37 RETURNS BYTEA
     38   AS $body$
     39   SELECT decode(string_agg(lpad(to_hex(width_bucket(random(), 0, 1, 256)-1),2,'0') ,''), 'hex')
     40     FROM generate_series(1, $1);
     41   $body$
     42 LANGUAGE 'sql'
     43 VOLATILE;
     44 
     45 COMMENT ON FUNCTION random_bytea(INT)
     46   IS 'Create BYTEA of the given length and fill it with random bytes';
     47 
     48 
     49 CREATE FUNCTION merchant_kyc_insert_trigger()
     50 RETURNS trigger
     51 LANGUAGE plpgsql
     52 AS $$
     53 BEGIN
     54   CALL merchant_send_kyc_notification(NEW.account_serial,
     55                                       NEW.exchange_url);
     56   RETURN NEW;
     57 END $$;
     58 
     59 CREATE FUNCTION merchant_kyc_update_trigger()
     60 RETURNS trigger
     61 LANGUAGE plpgsql
     62 AS $$
     63 BEGIN
     64   CALL merchant_send_kyc_notification(NEW.account_serial,
     65                                       NEW.exchange_url);
     66   RETURN NEW;
     67 END $$;
     68 
     69 -- Whenever KYC status changes, call our trigger to generate a notification
     70 CREATE TRIGGER merchant_kyc_on_insert
     71   AFTER INSERT
     72      ON merchant_kyc
     73   FOR EACH ROW EXECUTE FUNCTION merchant_kyc_insert_trigger();
     74 
     75 CREATE TRIGGER merchant_kyc_on_update
     76   AFTER UPDATE
     77      ON merchant_kyc
     78   FOR EACH ROW EXECUTE FUNCTION merchant_kyc_update_trigger();
     79 
     80 
     81 COMMIT;