merchant

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

update_money_pot.sql (1965B)


      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_update_money_pot;
     19 CREATE FUNCTION merchant_do_update_money_pot (
     20   IN in_money_pot_serial INT8,
     21   IN in_name TEXT,
     22   IN in_description TEXT,
     23   IN in_old_totals merchant.taler_amount_currency[], -- can be NULL!
     24   IN in_new_totals merchant.taler_amount_currency[], -- can be NULL!
     25   OUT out_conflict_total BOOL,
     26   OUT out_conflict_name BOOL,
     27   OUT out_not_found BOOL)
     28 LANGUAGE plpgsql
     29 AS $$
     30 BEGIN
     31 
     32 BEGIN
     33   UPDATE merchant_money_pots SET
     34     money_pot_name=in_name
     35    ,money_pot_description=in_description
     36    ,pot_totals=COALESCE(in_new_totals, pot_totals)
     37    WHERE money_pot_serial=in_money_pot_serial
     38      AND ( (in_old_totals IS NULL) OR (pot_totals=in_old_totals) );
     39   IF NOT FOUND
     40   THEN
     41     -- Check if pot_total was the problem
     42     PERFORM FROM merchant_money_pots
     43            WHERE money_pot_serial=in_money_pot_serial;
     44     out_conflict_total = FOUND;
     45     out_not_found = NOT FOUND;
     46     out_conflict_name = FALSE;
     47   ELSE
     48     out_conflict_total = FALSE;
     49     out_not_found = FALSE;
     50     out_conflict_name = FALSE;
     51   END IF;
     52   RETURN;
     53 EXCEPTION
     54   -- money_pot_name already used
     55   WHEN unique_violation
     56   THEN
     57     out_conflict_name = TRUE;
     58     out_conflict_total = FALSE;
     59     out_not_found = FALSE;
     60     RETURN;
     61 END;
     62 
     63 END $$;