merchant

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

pg_insert_issued_token.sql (1759B)


      1 --
      2 -- This file is part of TALER
      3 -- Copyright (C) 2025 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_issued_token;
     19 CREATE FUNCTION merchant_do_insert_issued_token (
     20   IN in_h_issue_pub BYTEA,
     21   IN in_h_contract_terms BYTEA,
     22   IN in_blind_sig BYTEA,
     23   OUT out_no_family BOOL,
     24   OUT out_existed BOOL)
     25 LANGUAGE plpgsql
     26 AS $$
     27 DECLARE
     28   my_rec RECORD;
     29   my_tfk_serial INT8;
     30   my_tf_serial INT8;
     31 BEGIN
     32 
     33 SELECT token_family_key_serial
     34       ,token_family_serial
     35   INTO my_rec
     36   FROM merchant_token_family_keys
     37  WHERE h_pub = in_h_issue_pub;
     38 
     39 IF NOT FOUND
     40 THEN
     41   out_no_family = TRUE;
     42   out_existed = FALSE;
     43   return;
     44 END IF;
     45 
     46 my_tfk_serial = my_rec.token_family_key_serial;
     47 my_tf_serial = my_rec.token_family_serial;
     48 out_no_family = FALSE;
     49 
     50 INSERT INTO merchant_issued_tokens
     51   (token_family_key_serial
     52   ,h_contract_terms
     53   ,blind_sig
     54   ) VALUES
     55   (my_tfk_serial
     56   ,in_h_contract_terms
     57   ,in_blind_sig)
     58   ON CONFLICT DO NOTHING;
     59 
     60 IF NOT FOUND
     61 THEN
     62   out_existed = TRUE;
     63   return;
     64 END IF;
     65 out_existed = FALSE;
     66 
     67 UPDATE merchant_token_families
     68    SET issued=issued+1
     69   WHERE token_family_serial=my_tf_serial;
     70   
     71 
     72 END $$;