merchant

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

merchant-0050.sql (2694B)


      1 --
      2 -- This file is part of TALER
      3 -- Copyright (C) 2026 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 merchant-0050.sql
     17 -- @brief Re-check confirmation of expected transfers when expected_credit_amount is filled in
     18 -- @author Kimi Code
     19 
     20 -- taler-merchant-depositcheck inserts merchant_expected_transfers with
     21 -- expected_credit_amount = NULL because /deposits only returns the coin's
     22 -- contribution.  taler-merchant-reconciliation later fills in the actual
     23 -- total amount via /transfers/$WTID.  The INSERT triggers only fire when the
     24 -- expected-transfer row is first created, so transfers that already existed
     25 -- in merchant_transfers were never linked.  This migration installs the body
     26 -- of the UPDATE trigger that merchant-0037 already created as a placeholder.
     27 
     28 BEGIN;
     29 
     30 SELECT _v.register_patch('merchant-0050', NULL, NULL);
     31 
     32 SET search_path TO merchant;
     33 
     34 CREATE PROCEDURE merchant.merchant_0050_init(s TEXT)
     35   LANGUAGE plpgsql
     36   AS $OUTER$
     37 BEGIN
     38 
     39   EXECUTE format('SET LOCAL search_path TO %I', s);
     40 
     41   CREATE OR REPLACE FUNCTION merchant_expected_transfers_update_trigger()
     42   RETURNS trigger
     43   LANGUAGE plpgsql
     44   AS $$
     45   BEGIN
     46     IF ( (OLD.expected_credit_amount IS DISTINCT FROM NEW.expected_credit_amount)
     47          AND (NEW.expected_credit_amount IS NOT NULL)
     48          AND (NOT NEW.confirmed) )
     49     THEN
     50       UPDATE merchant_transfers
     51          SET expected = TRUE
     52        WHERE wtid = NEW.wtid
     53          AND exchange_url = NEW.exchange_url
     54          AND credit_amount = NEW.expected_credit_amount;
     55       IF FOUND THEN
     56         NEW.confirmed = TRUE;
     57       END IF;
     58     END IF;
     59     RETURN NEW;
     60   END $$;
     61 
     62   COMMENT ON FUNCTION merchant_expected_transfers_update_trigger IS
     63     'Sets "confirmed" to TRUE for the updated record if a matching merchant_transfers row appears once the expected_credit_amount becomes known.';
     64 
     65   SET LOCAL search_path TO merchant;
     66 
     67 END
     68 $OUTER$;
     69 
     70 INSERT INTO merchant.instance_fixups
     71   (migration_name
     72   ,version)
     73   VALUES
     74   ('merchant_0050_init'
     75   ,50);
     76 -- Apply new fix-up to existing instances
     77 CALL merchant.fixup_instance_schema (50::INT8);
     78 
     79 COMMIT;