merchant

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

set_tos_accepted_early.sql (2273B)


      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 CREATE OR REPLACE FUNCTION merchant_do_set_tos_accepted_early (
     19   IN in_exchange_url TEXT,
     20   IN in_tos_version TEXT, -- NULL clears the early acceptance
     21   IN in_account_event_prefix BYTEA, -- event header and merchant public key
     22   IN in_instance_notify TEXT)
     23 RETURNS BOOL
     24 LANGUAGE plpgsql
     25 AS $$
     26 DECLARE
     27   my_h_wire BYTEA;
     28 BEGIN
     29   IF in_tos_version IS NULL
     30   THEN
     31     DELETE FROM merchant_tos_accepted
     32      WHERE exchange_url=in_exchange_url;
     33   ELSE
     34     INSERT INTO merchant_tos_accepted (exchange_url, tos_version)
     35     VALUES (in_exchange_url, in_tos_version)
     36     ON CONFLICT (exchange_url) DO UPDATE
     37       SET tos_version=EXCLUDED.tos_version
     38       WHERE merchant_tos_accepted.tos_version IS DISTINCT FROM EXCLUDED.tos_version;
     39   END IF;
     40   IF NOT FOUND
     41   THEN
     42     RETURN FALSE;
     43   END IF;
     44 
     45   -- Acceptance is per exchange and instance, and can appear in the KYC
     46   -- response for any active account, including one without a cached status.
     47   -- Queue notifications in the same transaction as the actual change.
     48   PERFORM pg_notify (lower (in_instance_notify), '');
     49   FOR my_h_wire IN
     50     SELECT h_wire FROM merchant_accounts WHERE active
     51   LOOP
     52     -- GNUNET_PQ_get_event_notify_channel: X followed by Crockford base32
     53     -- of the first 32 bytes of SHA-512 over the packed event. The C caller
     54     -- supplies its header and merchant public key; append this account.
     55     PERFORM pg_notify (
     56       lower ('X' || merchant.base32_crockford (
     57         substring (sha512 (in_account_event_prefix || my_h_wire) FROM 1 FOR 32))),
     58       '');
     59   END LOOP;
     60   RETURN TRUE;
     61 END $$;