merchant

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

pg_account_kyc_set_failed.sql (2237B)


      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 merchant_do_account_kyc_set_failed;
     19 
     20 CREATE FUNCTION merchant_do_account_kyc_set_failed (
     21   IN in_merchant_id TEXT,
     22   IN in_h_wire BYTEA,
     23   IN in_exchange_url TEXT,
     24   IN in_timestamp INT8,
     25   IN in_exchange_http_status INT4,
     26   IN in_kyc_ok BOOL,
     27   IN in_notify_str TEXT,
     28   IN in_notify2_str TEXT,
     29   OUT out_no_instance BOOL,
     30   OUT out_no_account BOOL)
     31 LANGUAGE plpgsql
     32 AS $$
     33 DECLARE
     34   my_merchant_id INT8;
     35   my_account_serial INT8;
     36 BEGIN
     37 
     38 out_no_instance=FALSE;
     39 out_no_account=FALSE;
     40 
     41 -- Which instance are we using?
     42 SELECT merchant_serial
     43   INTO my_merchant_id
     44   FROM merchant_instances
     45  WHERE merchant_id=in_merchant_id;
     46 
     47 IF NOT FOUND
     48 THEN
     49   out_no_instance=TRUE;
     50   RETURN;
     51 END IF;
     52 
     53 SELECT account_serial
     54   INTO my_account_serial
     55   FROM merchant_accounts
     56  WHERE merchant_serial=my_merchant_id
     57    AND h_wire=in_h_wire;
     58 
     59 IF NOT FOUND
     60 THEN
     61   out_no_account=TRUE;
     62   RETURN;
     63 END IF;
     64 
     65 UPDATE merchant_kyc
     66    SET kyc_timestamp=in_timestamp
     67       ,kyc_ok=in_kyc_ok
     68       ,exchange_http_status=in_exchange_http_status
     69       ,exchange_ec_code=0
     70  WHERE account_serial=my_account_serial
     71    AND exchange_url=in_exchange_url;
     72 
     73 IF NOT FOUND
     74 THEN
     75 
     76   INSERT INTO merchant_kyc
     77     (kyc_timestamp
     78     ,kyc_ok
     79     ,account_serial
     80     ,exchange_url
     81     ,exchange_http_status)
     82   VALUES
     83     (in_timestamp
     84     ,in_kyc_ok
     85     ,my_account_serial
     86     ,in_exchange_url
     87     ,in_exchange_http_status);
     88 END IF;
     89 
     90 EXECUTE FORMAT (
     91    'NOTIFY %s'
     92   ,in_notify_str);
     93 
     94 EXECUTE FORMAT (
     95    'NOTIFY %s'
     96   ,in_notify2_str);
     97 
     98 
     99 -- Success!
    100 END $$;