[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] 03/04: fix some payment logic
From: |
gnunet |
Subject: |
[taler-anastasis] 03/04: fix some payment logic |
Date: |
Tue, 01 Sep 2020 18:47:16 +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 4d530fd07ec045b563ef7025c7f08bb040609b46
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Tue Sep 1 18:16:01 2020 +0200
fix some payment logic
---
src/backend/anastasis-httpd_policy_upload.c | 105 ++++++++++++++++------------
src/cli/anastasis-cli-splitter.c | 3 +-
2 files changed, 63 insertions(+), 45 deletions(-)
diff --git a/src/backend/anastasis-httpd_policy_upload.c
b/src/backend/anastasis-httpd_policy_upload.c
index f15b992..ca7f33b 100644
--- a/src/backend/anastasis-httpd_policy_upload.c
+++ b/src/backend/anastasis-httpd_policy_upload.c
@@ -669,6 +669,12 @@ AH_handler_policy_post (struct MHD_Connection *connection,
{
struct PolicyUploadContext *puc;
struct ANASTASIS_CRYPTO_AccountPublicKeyP accountPubP;
+ struct TALER_Amount zero_amount;
+ bool zero_cost = false;
+
+ TALER_amount_get_zero (AH_currency, &zero_amount);
+ if (0 == TALER_amount_cmp (&AH_annual_fee, &zero_amount))
+ zero_cost = true;
puc = *con_cls;
if (NULL == puc)
@@ -850,10 +856,34 @@ AH_handler_policy_post (struct MHD_Connection *connection,
{
struct GNUNET_HashCode hc;
enum ANASTASIS_DB_QueryStatus qs;
- struct TALER_Amount zero_cost;
+ const char *pay_id;
- TALER_amount_get_zero (AH_currency, &zero_cost);
- if (0 == TALER_amount_cmp (&AH_annual_fee, &zero_cost))
+ pay_id = MHD_lookup_connection_value (connection,
+ MHD_HEADER_KIND,
+ "Payment-Identifier");
+ if ( pay_id &&
+ (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (pay_id,
+ strlen (pay_id),
+ &puc->payment_identifier,
+ sizeof (struct
+ ANASTASIS_PaymentSecretP)))
)
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ // FIXME: find error code
+ TALER_EC_SYNC_BAD_IF_MATCH,
+ "Payment-Identifier does not
include a base32-encoded Payment-Identifier");
+ }
+ if (pay_id)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "At %s:%d Payment-Identifier from header is: %s\n",
+ __FILE__,
+ __LINE__,
+ TALER_B2S (&puc->payment_identifier));
+
+ if (! pay_id)
{
// generate new payment identifier
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
@@ -866,24 +896,37 @@ AH_handler_policy_post (struct MHD_Connection *connection,
__LINE__,
TALER_B2S (&puc->payment_identifier));
- /** FIXME: not really reasonable */
- int post_counter = 10;
+ if (zero_cost)
+ {
+ /** FIXME: not really reasonable */
+ int post_counter = 10;
+
+ qs = db->record_payment (db->cls,
+ &accountPubP,
+ post_counter,
+ &puc->payment_identifier,
+ &AH_annual_fee);
+ if (qs >= 0)
+ {
+ qs = db->increment_lifetime (db->cls,
+ &accountPubP,
+ &puc->payment_identifier,
+ GNUNET_TIME_UNIT_YEARS);
+ }
+ if (qs < 0)
+ return handle_database_error (puc,
+ qs);
+ }
- qs = db->record_payment (db->cls,
- &accountPubP,
- post_counter,
- &puc->payment_identifier,
- &AH_annual_fee);
- if (qs >= 0)
+ else
{
- qs = db->increment_lifetime (db->cls,
- &accountPubP,
- &puc->payment_identifier,
- GNUNET_TIME_UNIT_YEARS);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "At %s:%d Payment is required, starting payment
process\n",
+ __FILE__,
+ __LINE__);
+ return begin_payment (puc,
+ GNUNET_NO);
}
- if (qs < 0)
- return handle_database_error (puc,
- qs);
}
qs = db->lookup_account (db->cls,
@@ -947,32 +990,6 @@ AH_handler_policy_post (struct MHD_Connection *connection,
"Upload starting\n");
return MHD_YES;
}
- {
- // Check if header contains Payment-Identifier
- const char *pay_id;
-
- pay_id = MHD_lookup_connection_value (connection,
- MHD_HEADER_KIND,
- "Payment-Identifier");
- if ( pay_id &&
- (GNUNET_OK !=
- GNUNET_STRINGS_string_to_data (pay_id,
- strlen (pay_id),
- &puc->payment_identifier,
- sizeof (struct
- ANASTASIS_PaymentSecretP))) )
- {
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_BAD_REQUEST,
- // FIXME: find error code
- TALER_EC_SYNC_BAD_IF_MATCH,
- "Payment-Identifier does not include
a base32-encoded Payment-Identifier");
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Payment-Identifier from header: %s\n",
- TALER_B2S (&puc->payment_identifier));
- }
/* handle upload */
if (0 != *recovery_data_size)
diff --git a/src/cli/anastasis-cli-splitter.c b/src/cli/anastasis-cli-splitter.c
index 34bca71..5c0ef46 100644
--- a/src/cli/anastasis-cli-splitter.c
+++ b/src/cli/anastasis-cli-splitter.c
@@ -383,7 +383,8 @@ secret_share_payment_cb (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"At %s:%d we are in SPC\n",
__FILE__, __LINE__);
- if (sss->http_status != MHD_HTTP_PAYMENT_REQUIRED)
+ if (! ((sss->http_status == MHD_HTTP_PAYMENT_REQUIRED)
+ || (sss->http_status == MHD_HTTP_NO_CONTENT) ))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d in %s:%u\n",
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.