merchant

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

pg_account_kyc_set_status.sql (2927B)


      1 --
      2 -- This file is part of TALER
      3 -- Copyright (C) 2024, 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 
     17 
     18 DROP FUNCTION IF EXISTS merchant_do_account_kyc_set_status;
     19 
     20 CREATE FUNCTION merchant_do_account_kyc_set_status (
     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_exchange_ec_code INT4,
     27   IN in_access_token BYTEA, -- can be NULL
     28   IN in_jlimits JSONB,
     29   IN in_aml_active BOOL,
     30   IN in_kyc_ok BOOL,
     31   IN in_notify_str TEXT,
     32   IN in_notify2_str TEXT,
     33   IN in_rule_gen INT8,
     34   IN in_next_time INT8,
     35   IN in_kyc_backoff INT8,
     36   OUT out_no_instance BOOL,
     37   OUT out_no_account BOOL)
     38 LANGUAGE plpgsql
     39 AS $$
     40 DECLARE
     41   my_merchant_id INT8;
     42   my_account_serial INT8;
     43 BEGIN
     44 
     45 out_no_instance=FALSE;
     46 out_no_account=FALSE;
     47 
     48 -- Which instance are we using?
     49 SELECT merchant_serial
     50   INTO my_merchant_id
     51   FROM merchant_instances
     52  WHERE merchant_id=in_merchant_id;
     53 
     54 IF NOT FOUND
     55 THEN
     56   out_no_instance=TRUE;
     57   RETURN;
     58 END IF;
     59 
     60 SELECT account_serial
     61   INTO my_account_serial
     62   FROM merchant_accounts
     63  WHERE merchant_serial=my_merchant_id
     64    AND h_wire=in_h_wire;
     65 
     66 IF NOT FOUND
     67 THEN
     68   out_no_account=TRUE;
     69   RETURN;
     70 END IF;
     71 
     72 UPDATE merchant_kyc
     73    SET kyc_timestamp=in_timestamp
     74       ,kyc_ok=in_kyc_ok
     75       ,jaccount_limits=in_jlimits
     76       ,aml_review=in_aml_active
     77       ,exchange_http_status=in_exchange_http_status
     78       ,exchange_ec_code=in_exchange_ec_code
     79       ,access_token=in_access_token
     80       ,last_rule_gen=in_rule_gen
     81       ,next_kyc_poll=in_next_time
     82       ,kyc_backoff=in_kyc_backoff
     83  WHERE account_serial=my_account_serial
     84    AND exchange_url=in_exchange_url;
     85 
     86 IF NOT FOUND
     87 THEN
     88 
     89   INSERT INTO merchant_kyc
     90     (kyc_timestamp
     91     ,kyc_ok
     92     ,account_serial
     93     ,exchange_url
     94     ,jaccount_limits
     95     ,aml_review
     96     ,exchange_http_status
     97     ,exchange_ec_code
     98     ,access_token
     99     ,last_rule_gen
    100     ,next_kyc_poll
    101     ,kyc_backoff)
    102   VALUES
    103     (in_timestamp
    104     ,in_kyc_ok
    105     ,my_account_serial
    106     ,in_exchange_url
    107     ,in_jlimits
    108     ,in_aml_active
    109     ,in_exchange_http_status
    110     ,in_exchange_ec_code
    111     ,in_access_token
    112     ,in_rule_gen
    113     ,in_next_time
    114     ,in_kyc_backoff);
    115 END IF;
    116 
    117 EXECUTE FORMAT (
    118    'NOTIFY %s'
    119   ,in_notify_str);
    120 
    121 EXECUTE FORMAT (
    122    'NOTIFY %s'
    123   ,in_notify2_str);
    124 
    125 
    126 -- Success!
    127 END $$;