lookup_order.c (3358B)
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/lookup_order.c 18 * @brief Implementation of the lookup_order 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 "merchant-database/lookup_order.h" 26 #include "helper.h" 27 28 enum GNUNET_DB_QueryStatus 29 TALER_MERCHANTDB_lookup_order (struct TALER_MERCHANTDB_PostgresContext *pg, 30 const char *instance_id, 31 const char *order_id, 32 struct TALER_ClaimTokenP *claim_token, 33 struct TALER_MerchantPostDataHashP *h_post_data, 34 json_t **contract_terms) 35 { 36 json_t *j; 37 struct TALER_ClaimTokenP ct; 38 enum GNUNET_DB_QueryStatus qs; 39 struct GNUNET_PQ_QueryParam params[] = { 40 GNUNET_PQ_query_param_string (instance_id), 41 GNUNET_PQ_query_param_string (order_id), 42 GNUNET_PQ_query_param_end 43 }; 44 struct GNUNET_PQ_ResultSpec rs[] = { 45 TALER_PQ_result_spec_json ("contract_terms", 46 &j), 47 GNUNET_PQ_result_spec_auto_from_type ("claim_token", 48 &ct), 49 GNUNET_PQ_result_spec_auto_from_type ("h_post_data", 50 h_post_data), 51 GNUNET_PQ_result_spec_end 52 }; 53 54 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 55 "Finding contract term, order_id: '%s', instance_id: '%s'.\n", 56 order_id, 57 instance_id); 58 check_connection (pg); 59 PREPARE (pg, 60 "lookup_order", 61 "SELECT" 62 " contract_terms::TEXT" 63 ",claim_token" 64 ",h_post_data" 65 ",pos_key" 66 " FROM merchant_orders" 67 " WHERE merchant_orders.merchant_serial=" 68 " (SELECT merchant_serial " 69 " FROM merchant_instances" 70 " WHERE merchant_id=$1)" 71 " AND merchant_orders.order_id=$2"); 72 qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 73 "lookup_order", 74 params, 75 rs); 76 if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) 77 { 78 if (NULL != contract_terms) 79 *contract_terms = j; 80 else 81 json_decref (j); 82 if (NULL != claim_token) 83 *claim_token = ct; 84 } 85 else 86 { 87 /* just to be safe: NULL it */ 88 if (NULL != contract_terms) 89 *contract_terms = NULL; 90 if (NULL != claim_token) 91 *claim_token = (struct TALER_ClaimTokenP) { 0 } 92 ; 93 } 94 return qs; 95 }