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 backenddb/pg_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_error_codes.h> 23 : #include <taler/taler_dbevents.h> 24 : #include <taler/taler_pq_lib.h> 25 : #include "pg_update_contract_terms.h" 26 : #include "pg_helper.h" 27 : 28 : enum GNUNET_DB_QueryStatus 29 0 : TMH_PG_update_contract_terms (void *cls, 30 : const char *instance_id, 31 : const char *order_id, 32 : json_t *contract_terms) 33 : { 34 0 : struct PostgresClosure *pg = cls; 35 : struct GNUNET_TIME_Timestamp pay_deadline; 36 : struct GNUNET_TIME_Timestamp refund_deadline; 37 0 : const char *fulfillment_url = NULL; 38 : struct TALER_PrivateContractHashP h_contract_terms; 39 : 40 0 : if (GNUNET_OK != 41 0 : TALER_JSON_contract_hash (contract_terms, 42 : &h_contract_terms)) 43 : { 44 0 : GNUNET_break (0); 45 0 : return GNUNET_DB_STATUS_HARD_ERROR; 46 : } 47 : 48 : { 49 : struct GNUNET_JSON_Specification spec[] = { 50 0 : GNUNET_JSON_spec_timestamp ("pay_deadline", 51 : &pay_deadline), 52 0 : GNUNET_JSON_spec_timestamp ("refund_deadline", 53 : &refund_deadline), 54 0 : GNUNET_JSON_spec_mark_optional ( 55 : GNUNET_JSON_spec_string ("fulfillment_url", 56 : &fulfillment_url), 57 : NULL), 58 0 : GNUNET_JSON_spec_end () 59 : }; 60 : enum GNUNET_GenericReturnValue res; 61 : const char *error_json_name; 62 : unsigned int error_line; 63 : 64 0 : res = GNUNET_JSON_parse (contract_terms, 65 : spec, 66 : &error_json_name, 67 : &error_line); 68 0 : if (GNUNET_OK != res) 69 : { 70 0 : GNUNET_break (0); 71 0 : return GNUNET_DB_STATUS_HARD_ERROR; 72 : } 73 : } 74 : 75 0 : check_connection (pg); 76 : { 77 0 : struct GNUNET_PQ_QueryParam params[] = { 78 0 : GNUNET_PQ_query_param_string (instance_id), 79 0 : GNUNET_PQ_query_param_string (order_id), 80 0 : TALER_PQ_query_param_json (contract_terms), 81 0 : GNUNET_PQ_query_param_auto_from_type (&h_contract_terms), 82 0 : GNUNET_PQ_query_param_timestamp (&pay_deadline), 83 0 : GNUNET_PQ_query_param_timestamp (&refund_deadline), 84 0 : (NULL == fulfillment_url) 85 0 : ? GNUNET_PQ_query_param_null () 86 0 : : GNUNET_PQ_query_param_string (fulfillment_url), 87 : GNUNET_PQ_query_param_end 88 : }; 89 0 : PREPARE (pg, 90 : "update_contract_terms", 91 : "UPDATE merchant_contract_terms SET" 92 : " contract_terms=$3" 93 : ",h_contract_terms=$4" 94 : ",pay_deadline=$5" 95 : ",refund_deadline=$6" 96 : ",fulfillment_url=$7" 97 : " WHERE order_id=$2" 98 : " AND merchant_serial=" 99 : " (SELECT merchant_serial" 100 : " FROM merchant_instances" 101 : " WHERE merchant_id=$1)"); 102 0 : return GNUNET_PQ_eval_prepared_non_select (pg->conn, 103 : "update_contract_terms", 104 : params); 105 : } 106 : }