merchant

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

pg_insert_unclaim_signature.sql (2096B)


      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 DROP FUNCTION IF EXISTS merchant_do_insert_unclaim_signature;
     19 CREATE FUNCTION merchant_do_insert_unclaim_signature (
     20   IN in_instance_id TEXT,
     21   IN in_order_id TEXT,
     22   IN in_nonce_str TEXT,
     23   IN in_notify_str TEXT,
     24   IN in_h_contract_terms BYTEA,
     25   IN in_nonce_sig BYTEA,
     26   OUT out_found BOOL)
     27 LANGUAGE plpgsql
     28 AS $$
     29 DECLARE
     30   my_merchant_serial INT8;
     31   my_expiration_time INT8;
     32 BEGIN
     33 
     34   SELECT merchant_serial
     35     INTO my_merchant_serial
     36     FROM merchant_instances
     37    WHERE merchant_id=in_instance_id;
     38 
     39   IF NOT FOUND
     40   THEN
     41     out_found = FALSE;
     42     RETURN;
     43   END IF;
     44 
     45   SELECT pay_deadline
     46     INTO my_expiration_time
     47     FROM merchant_contract_terms
     48     WHERE order_id=in_order_id
     49       AND merchant_serial = my_merchant_serial
     50       AND contract_terms->>'nonce' = in_nonce_str;
     51 
     52   IF NOT FOUND
     53   THEN
     54     out_found = FALSE;
     55     RETURN;
     56   END IF;
     57 
     58   INSERT INTO merchant_unclaim_signatures
     59     (h_contract_terms
     60     ,unclaim_sig
     61     ,expiration_time)
     62     VALUES
     63     (in_h_contract_terms
     64     ,in_nonce_sig
     65     ,my_expiration_time)
     66     ON CONFLICT DO NOTHING:
     67 
     68   IF FOUND
     69   THEN
     70     out_found = TRUE;
     71 
     72     -- order status change notification
     73     EXECUTE FORMAT (
     74       'NOTIFY %s'
     75      ,in_notify_str);
     76 
     77     RETURN;
     78   END IF;
     79 
     80   PERFORM FROM merchant_unclaim_signatures
     81     WHERE h_contract_terms = in_h_contract_terms
     82       AND unclaim_sig = in_nonce_sig;
     83   out_found = FOUND;
     84 
     85 END $$;