LCOV - code coverage report
Current view: top level - backenddb - get_order_by_fulfillment.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 11 11
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) 2023 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/get_order_by_fulfillment.c
      18              :  * @brief Implementation of the get_order_by_fulfillment function for Postgres
      19              :  * @author Iván Ávalos
      20              :  */
      21              : #include "platform.h"
      22              : #include <taler/taler_pq_lib.h>
      23              : #include "merchant-database/get_order_by_fulfillment.h"
      24              : #include "helper.h"
      25              : 
      26              : 
      27              : enum GNUNET_DB_QueryStatus
      28           23 : TALER_MERCHANTDB_get_order_by_fulfillment (
      29              :   struct TALER_MERCHANTDB_PostgresContext *pg,
      30              :   const char *instance_id,
      31              :   const char *fulfillment_url,
      32              :   const char *session_id,
      33              :   bool allow_refunded_for_repurchase,
      34              :   char **order_id)
      35              : {
      36           23 :   struct GNUNET_PQ_QueryParam params[] = {
      37           23 :     GNUNET_PQ_query_param_string (fulfillment_url),
      38           23 :     GNUNET_PQ_query_param_string (session_id),
      39           23 :     GNUNET_PQ_query_param_bool (allow_refunded_for_repurchase),
      40              :     GNUNET_PQ_query_param_end
      41              :   };
      42           23 :   struct GNUNET_PQ_ResultSpec rs[] = {
      43           23 :     GNUNET_PQ_result_spec_string ("order_id",
      44              :                                   order_id),
      45              :     GNUNET_PQ_result_spec_end
      46              :   };
      47              : 
      48           23 :   GNUNET_assert (NULL != pg->current_merchant_id);
      49           23 :   GNUNET_assert (0 == strcmp (instance_id,
      50              :                               pg->current_merchant_id));
      51           23 :   TMH_PQ_prepare_anon (pg,
      52              :                        "SELECT"
      53              :                        "  mct.order_id"
      54              :                        " FROM merchant_contract_terms mct"
      55              :                        " LEFT JOIN merchant_refunds mref"
      56              :                        "   USING (order_serial)"
      57              :                        " WHERE fulfillment_url=$1"
      58              :                        "   AND session_id=$2"
      59              :                        "   AND ((CAST($3 AS BOOL)) OR"
      60              :                        "        mref.refund_serial IS NULL)"
      61              :                        /* Theoretically, multiple paid orders
      62              :                           for the same fulfillment URL could
      63              :                           exist for this session_id -- if a
      64              :                           wallet was broken and did multiple
      65              :                           payments without repurchase detection.
      66              :                           So we need to limit to 1 when returning! */
      67              :                        " ORDER BY order_id DESC"
      68              :                        " LIMIT 1;");
      69           23 :   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
      70              :                                                    "",
      71              :                                                    params,
      72              :                                                    rs);
      73              : }
        

Generated by: LCOV version 2.0-1