merchant

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

delete_unit.sql (1649B)


      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 -- @file delete_unit.sql
     17 -- @brief SQL for deleting units
     18 -- @author Bohdan Potuzhnyi
     19 
     20 
     21 DROP FUNCTION IF EXISTS merchant_do_delete_unit;
     22 CREATE FUNCTION merchant_do_delete_unit (
     23     IN in_unit_id TEXT,
     24     OUT out_no_instance BOOL,
     25     OUT out_no_unit BOOL,
     26     OUT out_builtin_conflict BOOL)
     27     LANGUAGE plpgsql
     28 AS $$
     29 DECLARE
     30     my_unit RECORD;
     31 BEGIN
     32     out_no_unit := FALSE;
     33     out_builtin_conflict := FALSE;
     34 
     35     SELECT *
     36       INTO my_unit
     37       FROM merchant_custom_units
     38      WHERE unit = in_unit_id
     39       FOR UPDATE;
     40 
     41     IF NOT FOUND THEN
     42         IF EXISTS (SELECT 1
     43                      FROM merchant.merchant_builtin_units bu
     44                     WHERE bu.unit = in_unit_id)
     45         THEN
     46             out_builtin_conflict := TRUE;
     47         ELSE
     48             out_no_unit := TRUE;
     49         END IF;
     50         RETURN;
     51     END IF;
     52 
     53     DELETE
     54        FROM merchant_custom_units
     55       WHERE unit_serial = my_unit.unit_serial;
     56 
     57     RETURN;
     58 END $$;