merchant

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

commit f5c5811e9d0c7078ce8d429876d4c5a1f3d4e41e
parent 4998506a34e5855319b5d4fb738539c08910e75a
Author: Bohdan Potuzhnyi <potub1@bfh.ch>
Date:   Thu,  3 Oct 2024 20:08:26 +0000

adding donau tables, implementing lookup_donau_keys, upsert_donau_keys

Diffstat:
Msrc/backenddb/Makefile.am | 1+
Asrc/backenddb/merchant-0012.sql | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/pg_delete_donau.c | 27+++++++++++++++++++++++++++
Asrc/backenddb/pg_delete_donau.h | 30++++++++++++++++++++++++++++++
Asrc/backenddb/pg_insert_donau.c | 28++++++++++++++++++++++++++++
Asrc/backenddb/pg_insert_donau.h | 30++++++++++++++++++++++++++++++
Asrc/backenddb/pg_lookup_donau_keys.c | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/pg_lookup_donau_keys.h | 43+++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/pg_select_donau.c | 27+++++++++++++++++++++++++++
Asrc/backenddb/pg_select_donau.h | 29+++++++++++++++++++++++++++++
Asrc/backenddb/pg_upsert_donau_keys.c | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/pg_upsert_donau_keys.h | 41+++++++++++++++++++++++++++++++++++++++++
12 files changed, 464 insertions(+), 0 deletions(-)

diff --git a/src/backenddb/Makefile.am b/src/backenddb/Makefile.am @@ -28,6 +28,7 @@ sql_DATA = \ merchant-0009.sql \ merchant-0010.sql \ merchant-0011.sql \ + merchant-0012.sql \ drop.sql BUILT_SOURCES = \ diff --git a/src/backenddb/merchant-0012.sql b/src/backenddb/merchant-0012.sql @@ -0,0 +1,72 @@ +-- +-- This file is part of TALER +-- Copyright (C) 2024 Taler Systems SA +-- +-- TALER is free software; you can redistribute it and/or modify it under the +-- terms of the GNU General Public License as published by the Free Software +-- Foundation; either version 3, or (at your option) any later version. +-- +-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY +-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +-- A PARTICULAR PURPOSE. See the GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License along with +-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +-- + +-- @file merchant-0012.sql +-- @brief Create table to store donau related information +-- @author Bohdan Potuzhnyi +-- @author Vlada Svirsh + +BEGIN; + +-- Check patch versioning is in place. +SELECT _v.register_patch('merchant-0012', NULL, NULL); + +SET search_path TO merchant; + +CREATE TABLE IF NOT EXISTS merchant_donau_keys + (donau_keys_serial BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE + ,donau_url TEXT PRIMARY KEY + ,keys_json TEXT NOT NULL + ); + +COMMENT ON TABLE merchant_donau_keys + IS 'Here we store the cached /keys response from Donau in JSON format'; +COMMENT ON COLUMN merchant_donau_keys.donau_keys_serial + IS 'Unique serial identifier for each cached key entry'; +COMMENT ON COLUMN merchant_donau_keys.donau_url + IS 'Base URL of Donau associated with these keys'; +COMMENT ON COLUMN merchant_donau_keys.keys_json + IS 'JSON string of the /keys as generated by Donau'; + +CREATE TABLE IF NOT EXISTS merchant_donau_instances + (donau_instances_serial BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY + ,donau_url TEXT NOT NULL + ,charity_pub_key BYTEA CHECK (LENGTH(charity_pub_key)=32) + ,charity_id BIGINT NOT NULL + ,charity_max_per_year taler_amount_currency NOT NULL + ,charity_receipts_to_date taler_amount_currency NOT NULL + ,current_year INT8 NOT NULL + ); + +COMMENT ON TABLE merchant_donau_instances + IS 'Here we store information about individual Donau instances, including details about associated charities and donation limits'; +COMMENT ON COLUMN merchant_donau_instances.donau_instances_serial + IS 'Unique serial identifier for each Donau instance'; +COMMENT ON COLUMN merchant_donau_instances.donau_url + IS 'The URL associated with the Donau system for this instance'; +COMMENT ON COLUMN merchant_donau_instances.charity_pub_key + IS 'The public key of the charity organization linked to this instance, with a 32-byte length constraint'; +COMMENT ON COLUMN merchant_donau_instances.charity_id + IS 'The unique identifier for the charity organization linked to this Donau instance'; +COMMENT ON COLUMN merchant_donau_instances.charity_max_per_year + IS 'Maximum allowable donation amount per year for the charity associated with this instance, stored in taler_amount_currency'; +COMMENT ON COLUMN merchant_donau_instances.charity_receipts_to_date + IS 'The total amount of donations received to date for this instance, stored in taler_amount_currency'; +COMMENT ON COLUMN merchant_donau_instances.current_year + IS 'The current year for tracking donations for this instance, stored as an 8-byte integer'; + + +COMMIT; +\ No newline at end of file diff --git a/src/backenddb/pg_delete_donau.c b/src/backenddb/pg_delete_donau.c @@ -0,0 +1,27 @@ +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file backenddb/pg_delete_donau.c + * @brief Implementation of the delete_donau function for Postgres + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ +#include "platform.h" +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "pg_delete_donau.h" +#include "pg_helper.h" diff --git a/src/backenddb/pg_delete_donau.h b/src/backenddb/pg_delete_donau.h @@ -0,0 +1,30 @@ +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file backenddb/pg_delete_donau.h + * @brief implementation of the delete_donau function for Postgres + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ +#ifndef PG_DELETE_DONAU_H +#define PG_DELETE_DONAU_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "taler_merchantdb_plugin.h" + + +#endif diff --git a/src/backenddb/pg_insert_donau.c b/src/backenddb/pg_insert_donau.c @@ -0,0 +1,28 @@ +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file backenddb/pg_insert_donau.c + * @brief Implementation of the insert_donau function for Postgres + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ +#include "platform.h" +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "pg_insert_donau.h" +#include "pg_helper.h" + diff --git a/src/backenddb/pg_insert_donau.h b/src/backenddb/pg_insert_donau.h @@ -0,0 +1,30 @@ +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file backenddb/pg_insert_donau.h + * @brief implementation of the insert_donau function for Postgres + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ +#ifndef PG_INSERT_DONAU_H +#define PG_INSERT_DONAU_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "taler_merchantdb_plugin.h" + + +#endif diff --git a/src/backenddb/pg_lookup_donau_keys.c b/src/backenddb/pg_lookup_donau_keys.c @@ -0,0 +1,68 @@ +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file backenddb/pg_lookup_donau_keys.c + * @brief Implementation of the lookup_donau_keys function for Postgres + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ +#include "platform.h" +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "pg_lookup_donau_keys.h" +#include "pg_helper.h" + +enum GNUNET_DB_QueryStatus +TMH_PG_lookup_donau_keys (void *cls, + const char *donau_url, + struct DONAU_Keys **keys) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (donau_url), + GNUNET_PQ_query_param_end + }; + json_t *jkeys; + struct GNUNET_PQ_ResultSpec rs[] = { + TALER_PQ_result_spec_json ("keys_json", + &jkeys), + GNUNET_PQ_result_spec_end + }; + enum GNUNET_DB_QueryStatus qs; + + check_connection (pg); + PREPARE (pg, + "lookup_donau_keys", + "SELECT" + " keys_json" + " FROM merchant_donau_keys" + " WHERE donau_url=$1;"); + qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "lookup_donau_keys", + params, + rs); + if (qs <= 0) + return qs; + *keys = DONAU_keys_from_json (jkeys); + json_decref (jkeys); + if (NULL == *keys) + { + GNUNET_break (0); + return GNUNET_DB_STATUS_HARD_ERROR; + } + return qs; +} +\ No newline at end of file diff --git a/src/backenddb/pg_lookup_donau_keys.h b/src/backenddb/pg_lookup_donau_keys.h @@ -0,0 +1,43 @@ +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file backenddb/pg_lookup_donau_keys.h + * @brief implementation of the lookup_donau_keys function for Postgres + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ +#ifndef PG_LOOKUP_DONAU_KEYS_H +#define PG_LOOKUP_DONAU_KEYS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "taler_merchantdb_plugin.h" + +/** + * Retrieve donau's keys from the database. + * + * @param cls plugin closure + * @param donau_url base URL of the exchange + * @param[out] keys set to the keys of the exchange + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TMH_PG_lookup_donau_keys (void *cls, + const char *donau_url, + struct DONAU_Keys **keys); + + +#endif diff --git a/src/backenddb/pg_select_donau.c b/src/backenddb/pg_select_donau.c @@ -0,0 +1,27 @@ +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file backenddb/pg_select_donau.c + * @brief Implementation of the select_donau function for Postgres + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ +#include "platform.h" +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "pg_select_donau.h" +#include "pg_helper.h" diff --git a/src/backenddb/pg_select_donau.h b/src/backenddb/pg_select_donau.h @@ -0,0 +1,29 @@ +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file backenddb/pg_select_donau.h + * @brief implementation of the select_donau function for Postgres + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ +#ifndef PG_SELECT_DONAU_H +#define PG_SELECT_DONAU_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "taler_merchantdb_plugin.h" + +#endif diff --git a/src/backenddb/pg_upsert_donau_keys.c b/src/backenddb/pg_upsert_donau_keys.c @@ -0,0 +1,65 @@ +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file backenddb/pg_upsert_donau_keys.c + * @brief Implementation of the upsert_donau_keys function for Postgres + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ +#include "platform.h" +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "pg_upsert_donau_keys.h" +#include "pg_helper.h" + +enum GNUNET_DB_QueryStatus +TMH_PG_upsert_donau_keys ( + void *cls, + const struct DONAU_Keys *keys) +{ + struct PostgresClosure *pg = cls; + json_t *jkeys = DONAU_keys_to_json(keys); + struct GNUNET_PQ_QueryParam params[] = { + TALER_PQ_query_param_json(jkeys), + GNUNET_PQ_query_param_string(&keys->donau_url), + GNUNET_PQ_query_param_end + }; + + check_connection(pg); + PREPARE(pg, + "upsert_donau_keys", + "INSERT INTO merchant_donau_keys" + "(keys_json" + ",donau_url" + ") VALUES ($1, $2);"); + PREPARE (pg, + "update_donau_keys", + "UPDATE merchant_donau_keys SET" + " keys_json=$1" + " WHERE" + " donau_url=$2;"); + + qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, + "update_exchange_keys", + params); + if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) + qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, + "upsert_exchange_keys", + params); + json_decref (jkeys); + return qs; +} +\ No newline at end of file diff --git a/src/backenddb/pg_upsert_donau_keys.h b/src/backenddb/pg_upsert_donau_keys.h @@ -0,0 +1,41 @@ +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file backenddb/pg_upsert_donau_keys.h + * @brief implementation of the upsert_donau_keys function for Postgres + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ +#ifndef PG_UPSERT_DONAU_KEYS_H +#define PG_UPSERT_DONAU_KEYS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "taler_merchantdb_plugin.h" + +/** + * Function to insert or update Donau keys in the merchant_donau_keys table. + * + * @param cls closure + * @param keys the DONAU_Keys object + * @return GNUNET_DB_QueryStatus transaction status + */ +enum GNUNET_DB_QueryStatus +TMH_PG_insert_donau_keys(void *cls, + const struct DONAU_Keys *keys); + + +#endif