sync

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

syncdb_increment_lifetime_TR.sql (1779B)


      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 LANGUAGE plpgsql
     26 AS $$
     27 DECLARE
     28   my_expiration INT8;
     29 BEGIN
     30   out_no_payment = 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   -- Get current expiration
     46   SELECT expiration_date
     47     INTO my_expiration
     48     FROM accounts
     49    WHERE account_pub=in_account_pub;
     50 
     51   IF NOT FOUND
     52   THEN
     53     -- No account yet, create one with expiration = now + lifetime
     54     INSERT INTO accounts
     55       (account_pub
     56       ,expiration_date)
     57     VALUES
     58       (in_account_pub
     59       ,in_now_us + in_lifetime_us);
     60   ELSE
     61     -- Account exists, extend expiration
     62     UPDATE accounts
     63        SET expiration_date=my_expiration + in_lifetime_us
     64      WHERE account_pub=in_account_pub;
     65   END IF;
     66 END $$;