[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] 03/04: fixed some payment issues
From: |
gnunet |
Subject: |
[taler-anastasis] 03/04: fixed some payment issues |
Date: |
Thu, 03 Sep 2020 14:37:02 +0200 |
This is an automated email from the git hooks/post-receive script.
dennis-neufeld pushed a commit to branch master
in repository anastasis.
commit df92c376bd58bc36fcd3f7b9166effbd1f5e6659
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Thu Sep 3 12:25:34 2020 +0200
fixed some payment issues
---
src/backend/anastasis-httpd_policy_upload.c | 63 ++++++++++++++++++++---------
src/include/anastasis_database_plugin.h | 18 +++++++++
src/stasis/plugin_anastasis_postgres.c | 52 ++++++++++++++++++++++++
src/stasis/test_anastasis_db.c | 14 +++++++
4 files changed, 129 insertions(+), 18 deletions(-)
diff --git a/src/backend/anastasis-httpd_policy_upload.c
b/src/backend/anastasis-httpd_policy_upload.c
index 66a4546..b0fbee2 100644
--- a/src/backend/anastasis-httpd_policy_upload.c
+++ b/src/backend/anastasis-httpd_policy_upload.c
@@ -345,7 +345,7 @@ proposal_cb (void *cls,
{
GNUNET_break (0);
puc->resp = TALER_MHD_make_error (TALER_EC_SYNC_PAYMENT_CREATE_DB_ERROR,
- "Failed to persist payment request in
sync database");
+ "Failed to persist payment request in
anastasis database");
puc->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
return;
}
@@ -508,25 +508,22 @@ begin_payment (struct PolicyUploadContext *puc,
enum ANASTASIS_DB_QueryStatus qs;
const char *order_id;
- if (GNUNET_NO == pay_req)
+ qs = db->lookup_pending_payments_by_account (db->cls,
+ &puc->account,
+ &ongoing_payment_cb,
+ puc);
+ if (qs < 0)
{
- qs = db->lookup_pending_payments_by_account (db->cls,
- &puc->account,
- &ongoing_payment_cb,
- puc);
- if (qs < 0)
- {
- struct MHD_Response *resp;
- MHD_RESULT ret;
+ struct MHD_Response *resp;
+ MHD_RESULT ret;
- resp = TALER_MHD_make_error (TALER_EC_SYNC_PAYMENT_CHECK_ORDER_DB_ERROR,
- "Failed to check for expired payment in
anastasis database");
- ret = MHD_queue_response (puc->con,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- resp);
- MHD_destroy_response (resp);
- return ret;
- }
+ resp = TALER_MHD_make_error (TALER_EC_SYNC_PAYMENT_CHECK_ORDER_DB_ERROR,
+ "Failed to check for expired payment in
anastasis database");
+ ret = MHD_queue_response (puc->con,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ resp);
+ MHD_destroy_response (resp);
+ return ret;
}
if (NULL != puc->existing_order_id)
@@ -880,12 +877,42 @@ AH_handler_policy_post (struct MHD_Connection *connection,
"Payment-Identifier does not
include a base32-encoded Payment-Identifier");
}
if (pay_id)
+ {
+ // check if payment identifier is valid (existing and paid)
+ bool paid;
+ bool valid_counter;
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"At %s:%d Payment-Identifier from header is: %s\n",
__FILE__,
__LINE__,
TALER_B2S (&puc->payment_identifier));
+ qs = db->check_payment_identifier (db->cls,
+ &puc->payment_identifier,
+ &paid,
+ &valid_counter);
+ if (qs < 0)
+ return handle_database_error (puc,
+ qs);
+
+ if ((qs >= 0)&& (! paid || ! valid_counter))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "At %s:%d paid is: '%d' and valid_counter is '%d'\n",
+ __FILE__,
+ __LINE__,
+ paid,
+ valid_counter);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "At %s:%d Payment is required, starting payment
process.\n",
+ __FILE__,
+ __LINE__);
+ return begin_payment (puc,
+ GNUNET_YES);
+ }
+ }
+
if (! pay_id)
{
// generate new payment identifier
diff --git a/src/include/anastasis_database_plugin.h
b/src/include/anastasis_database_plugin.h
index c725be4..4ef5947 100644
--- a/src/include/anastasis_database_plugin.h
+++ b/src/include/anastasis_database_plugin.h
@@ -316,6 +316,7 @@ struct ANASTASIS_DatabasePlugin
* @param anastasis_pub account to look for pending payment under
* @param it iterator to call on all pending payments
* @param it_cls closure for @a it
+ * @return transaction status
*/
enum ANASTASIS_DB_QueryStatus
(*lookup_pending_payments_by_account)(void *cls,
@@ -325,6 +326,23 @@ struct ANASTASIS_DatabasePlugin
ANASTASIS_DB_PaymentPendingIterator it,
void *it_cls);
+/**
+ * Check payment identifier. Used to check if a payment identifier given by
+ * the user is valid (existing and paid).
+ *
+ * @param cls closure
+ * @param payment_secret payment secret which the user must provide with every
upload
+ * @param paid bool value to show if payment is paid
+ * @param valid_counter bool value to show if post_counter is > 0
+ * @return transaction status
+ */
+ enum ANASTASIS_DB_QueryStatus
+ (*check_payment_identifier)(void *cls,
+ const struct
+ ANASTASIS_PaymentSecretP *payment_secret,
+ bool *paid,
+ bool *valid_counter);
+
/**
* Increment account lifetime.
*
diff --git a/src/stasis/plugin_anastasis_postgres.c
b/src/stasis/plugin_anastasis_postgres.c
index 4a3039d..e09aac5 100644
--- a/src/stasis/plugin_anastasis_postgres.c
+++ b/src/stasis/plugin_anastasis_postgres.c
@@ -978,6 +978,56 @@ postgres_record_payment (void *cls,
}
+/**
+ * Check payment identifier. Used to check if a payment identifier given by
+ * the user is valid (existing and paid).
+ *
+ * @param cls closure
+ * @param payment_secret payment secret which the user must provide with every
upload
+ * @param paid[OUT] bool value to show if payment is paid
+ * @param valid_counter[OUT] bool value to show if post_counter is > 0
+ * @return transaction status
+ */
+static enum ANASTASIS_DB_QueryStatus
+postgres_check_payment_identifier (void *cls,
+ const struct
+ ANASTASIS_PaymentSecretP *payment_secret,
+ bool *paid,
+ bool *valid_counter)
+{
+ struct PostgresClosure *pg = cls;
+ enum ANASTASIS_DB_QueryStatus qs;
+ uint32_t counter;
+
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (payment_secret),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("paid",
+ paid),
+ GNUNET_PQ_result_spec_uint32 ("post_counter",
+ &counter),
+ GNUNET_PQ_result_spec_end
+ };
+ check_connection (pg);
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "payment_select",
+ params,
+ rs);
+
+ if (qs == ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT)
+ {
+ if (counter > 0)
+ *valid_counter = true;
+ else
+ *valid_counter = false;
+ }
+
+ return qs;
+}
+
+
/**
* Upload Truth, which contains the Truth and the KeyShare.
*
@@ -1464,6 +1514,7 @@ libanastasis_plugin_db_postgres_init (void *cls)
GNUNET_PQ_make_prepare ("payment_select",
"SELECT"
" timestamp"
+ ",post_counter"
",amount_val"
",amount_frac"
",paid"
@@ -1638,6 +1689,7 @@ libanastasis_plugin_db_postgres_init (void *cls)
plugin->get_latest_recovery_document =
&postgres_get_latest_recovery_document;
plugin->get_recovery_document = &postgres_get_recovery_document;
plugin->lookup_account = &postgres_lookup_account;
+ plugin->check_payment_identifier = &postgres_check_payment_identifier;
plugin->lookup_pending_payments_by_account =
&postgres_lookup_pending_payments_by_account;
plugin->increment_lifetime = &postgres_increment_lifetime;
diff --git a/src/stasis/test_anastasis_db.c b/src/stasis/test_anastasis_db.c
index e57c8cf..e158607 100644
--- a/src/stasis/test_anastasis_db.c
+++ b/src/stasis/test_anastasis_db.c
@@ -207,6 +207,8 @@ run (void *cls)
unsigned char aes_gcm_tag[16];
RND_BLK (&aes_gcm_tag);
+ bool paid;
+ bool valid_counter;
post_counter = 2;
mime_type = "Picture";
method = "Methode";
@@ -230,6 +232,12 @@ run (void *cls)
TALER_string_to_amount ("EUR:1",
&amount));
+ FAILIF (ANASTASIS_DB_STATUS_NO_RESULTS !=
+ plugin->check_payment_identifier (plugin->cls,
+ &paymentSecretP,
+ &paid,
+ &valid_counter));
+
FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->record_payment (plugin->cls,
&accountPubP,
@@ -243,6 +251,12 @@ run (void *cls)
&paymentSecretP,
rel_time));
+ FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->check_payment_identifier (plugin->cls,
+ &paymentSecretP,
+ &paid,
+ &valid_counter));
+
FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->store_truth (plugin->cls,
&truth_public_key,
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.