LCOV - code coverage report
Current view: top level - backenddb - update_contract_terms.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 81.5 % 27 22
Test Date: 2026-09-04 23:42:01 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /*
       2              :    This file is part of TALER
       3              :    Copyright (C) 2022 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              :  * @file src/backenddb/update_contract_terms.c
      18              :  * @brief Implementation of the update_contract_terms function for Postgres
      19              :  * @author Iván Ávalos
      20              :  */
      21              : #include "platform.h"
      22              : #include <taler/taler_pq_lib.h>
      23              : #include "merchant-database/update_contract_terms.h"
      24              : #include "helper.h"
      25              : 
      26              : 
      27              : enum GNUNET_DB_QueryStatus
      28            1 : TALER_MERCHANTDB_update_contract_terms (
      29              :   struct TALER_MERCHANTDB_PostgresContext *pg,
      30              :   const char *instance_id,
      31              :   const char *order_id,
      32              :   json_t *contract_terms)
      33              : {
      34              :   struct GNUNET_TIME_Timestamp pay_deadline;
      35              :   struct GNUNET_TIME_Timestamp refund_deadline;
      36            1 :   const char *fulfillment_url = NULL;
      37              :   struct TALER_PrivateContractHashP h_contract_terms;
      38              : 
      39            1 :   if (GNUNET_OK !=
      40            1 :       TALER_JSON_contract_hash (contract_terms,
      41              :                                 &h_contract_terms))
      42              :   {
      43            0 :     GNUNET_break (0);
      44            0 :     return GNUNET_DB_STATUS_HARD_ERROR;
      45              :   }
      46              : 
      47              :   {
      48              :     struct GNUNET_JSON_Specification spec[] = {
      49            1 :       GNUNET_JSON_spec_timestamp ("pay_deadline",
      50              :                                   &pay_deadline),
      51            1 :       GNUNET_JSON_spec_timestamp ("refund_deadline",
      52              :                                   &refund_deadline),
      53            1 :       GNUNET_JSON_spec_mark_optional (
      54              :         GNUNET_JSON_spec_string ("fulfillment_url",
      55              :                                  &fulfillment_url),
      56              :         NULL),
      57            1 :       GNUNET_JSON_spec_end ()
      58              :     };
      59              :     enum GNUNET_GenericReturnValue res;
      60              :     const char *error_json_name;
      61              :     unsigned int error_line;
      62              : 
      63            1 :     res = GNUNET_JSON_parse (contract_terms,
      64              :                              spec,
      65              :                              &error_json_name,
      66              :                              &error_line);
      67            1 :     if (GNUNET_OK != res)
      68              :     {
      69            0 :       GNUNET_break (0);
      70            0 :       return GNUNET_DB_STATUS_HARD_ERROR;
      71              :     }
      72              :   }
      73              : 
      74            1 :   GNUNET_assert (NULL != pg->current_merchant_id);
      75            1 :   GNUNET_assert (0 == strcmp (instance_id,
      76              :                               pg->current_merchant_id));
      77              :   {
      78            1 :     struct GNUNET_PQ_QueryParam params[] = {
      79            1 :       GNUNET_PQ_query_param_string (order_id),
      80            1 :       TALER_PQ_query_param_json (contract_terms),
      81            1 :       GNUNET_PQ_query_param_auto_from_type (&h_contract_terms),
      82            1 :       GNUNET_PQ_query_param_timestamp (&pay_deadline),
      83            1 :       GNUNET_PQ_query_param_timestamp (&refund_deadline),
      84            1 :       (NULL == fulfillment_url)
      85            0 :       ? GNUNET_PQ_query_param_null ()
      86            1 :       : GNUNET_PQ_query_param_string (fulfillment_url),
      87              :       GNUNET_PQ_query_param_end
      88              :     };
      89              : 
      90            1 :     TMH_PQ_prepare_anon (pg,
      91              :                          "UPDATE merchant_contract_terms SET"
      92              :                          " contract_terms=$2::TEXT::JSONB"
      93              :                          ",h_contract_terms=$3"
      94              :                          ",pay_deadline=$4"
      95              :                          ",refund_deadline=$5"
      96              :                          ",fulfillment_url=$6"
      97              :                          " WHERE order_id=$1");
      98            1 :     return GNUNET_PQ_eval_prepared_non_select (pg->conn,
      99              :                                                "",
     100              :                                                params);
     101              :   }
     102              : }
        

Generated by: LCOV version 2.0-1