sync

Backup service to store encrypted wallet databases (experimental)
Log | Files | Refs | Submodules | README | LICENSE

syncdb_increment_lifetime_TR.sql (1535B)


      1 --
      2 -- This file is part of TALER
      3 -- Copyright (C) 2024 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 sync_do_increment_lifetime;
     19 CREATE FUNCTION sync_do_increment_lifetime (
     20   IN in_account_pub BYTEA,
     21   IN in_order_id TEXT,
     22   IN in_lifetime_us INT8,
     23   IN in_now_us INT8,
     24   OUT out_no_payment BOOLEAN,
     25   OUT out_no_account BOOLEAN)
     26 LANGUAGE plpgsql
     27 AS $$
     28 BEGIN
     29   out_no_payment := FALSE;
     30   out_no_account := FALSE;
     31 
     32   -- Mark payment as done
     33   UPDATE payments
     34      SET paid=TRUE
     35    WHERE order_id=in_order_id
     36      AND account_pub=in_account_pub
     37      AND paid=FALSE;
     38 
     39   IF NOT FOUND
     40   THEN
     41     out_no_payment := TRUE;
     42     RETURN;
     43   END IF;
     44 
     45   -- Extend account expiration (account already created by store_payment)
     46   UPDATE accounts
     47      SET expiration_date=expiration_date + in_lifetime_us
     48    WHERE account_pub=in_account_pub;
     49 
     50   IF NOT FOUND
     51   THEN
     52     out_no_account := TRUE;
     53     RETURN;
     54   END IF;
     55 END $$;