merchant

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

merchant-0046.sql (3113B)


      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-0046.sql
     17 -- @brief Add table for external refunds (DD96 partial payments)
     18 -- @author Bohdan Potuzhnyi
     19 -- @author Volodymyr Potuzhnyi
     20 
     21 BEGIN;
     22 
     23 SELECT _v.register_patch('merchant-0046', NULL, NULL);
     24 
     25 SET search_path TO merchant;
     26 
     27 CREATE PROCEDURE merchant.merchant_0046_init(s TEXT)
     28   LANGUAGE plpgsql
     29   AS $OUTER$
     30 BEGIN
     31   EXECUTE format('SET LOCAL search_path TO %I', s);
     32 
     33   CREATE TABLE merchant_refunds_external (
     34     refund_external_serial INT8 GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
     35     order_serial INT8 NOT NULL,
     36     refund_id TEXT NOT NULL,
     37     h_post_data BYTEA NOT NULL CHECK (LENGTH(h_post_data)=64),
     38     refund_timestamp INT8 NOT NULL,
     39     refund_method TEXT NOT NULL,
     40     payment_id TEXT DEFAULT NULL,
     41     refund_amount merchant.taler_amount_currency NOT NULL,
     42     reason TEXT NOT NULL,
     43     UNIQUE (order_serial, refund_id),
     44     CONSTRAINT merchant_refunds_external_order_serial_fkey
     45       FOREIGN KEY (order_serial)
     46       REFERENCES merchant_contract_terms(order_serial) ON DELETE CASCADE
     47   );
     48   COMMENT ON TABLE merchant_refunds_external IS
     49     'Bookkeeping entries for refunds settled outside of Taler (DD96);'
     50     ' the actual return of funds is performed by the POS or external'
     51     ' payment integration';
     52   COMMENT ON COLUMN merchant_refunds_external.order_serial IS
     53     'order for which the external refund was recorded';
     54   COMMENT ON COLUMN merchant_refunds_external.refund_id IS
     55     'identifier of this external refund within the order, chosen by the'
     56     ' merchant; unique per order and used to make recording an external'
     57     ' refund idempotent';
     58   COMMENT ON COLUMN merchant_refunds_external.h_post_data IS
     59     'hash of the original POST request body, used to distinguish an'
     60     ' idempotent replay from a conflicting reuse of refund_id';
     61   COMMENT ON COLUMN merchant_refunds_external.refund_method IS
     62     'external payment method used to return the funds, never "taler"';
     63   COMMENT ON COLUMN merchant_refunds_external.payment_id IS
     64     'optional id of the amount_external entry this refund reverses';
     65   COMMENT ON COLUMN merchant_refunds_external.reason IS
     66     'human-readable refund justification';
     67 
     68   SET LOCAL search_path TO merchant;
     69 END
     70 $OUTER$;
     71 
     72 INSERT INTO merchant.instance_fixups
     73   (migration_name
     74   ,version)
     75   VALUES
     76   ('merchant_0046_init'
     77   ,46);
     78 -- Apply new fix-up to existing instances
     79 CALL merchant.fixup_instance_schema (46::INT8);
     80 
     81 COMMIT;