summaryrefslogtreecommitdiff
path: root/src/lib/merchant_api_post_transfers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/merchant_api_post_transfers.c')
-rw-r--r--src/lib/merchant_api_post_transfers.c156
1 files changed, 30 insertions, 126 deletions
diff --git a/src/lib/merchant_api_post_transfers.c b/src/lib/merchant_api_post_transfers.c
index 450b46d9..615453fa 100644
--- a/src/lib/merchant_api_post_transfers.c
+++ b/src/lib/merchant_api_post_transfers.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2021 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License as published by the Free Software
@@ -85,116 +85,22 @@ handle_post_transfers_finished (void *cls,
const void *response)
{
struct TALER_MERCHANT_PostTransfersHandle *pth = cls;
- const json_t *json = response;
- json_t *deposit_sum = NULL;
- struct TALER_MERCHANT_HttpResponse hr = {
- .http_status = (unsigned int) response_code,
- .reply = json
+ struct TALER_MERCHANT_PostTransfersResponse ptr = {
+ .hr.reply = response,
+ .hr.http_status = (unsigned int) response_code
};
pth->job = NULL;
switch (response_code)
{
case 0:
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ ptr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
break;
- case MHD_HTTP_OK:
- {
- struct TALER_Amount total;
- struct TALER_Amount wire_fee;
- struct GNUNET_TIME_Timestamp execution_time;
- json_t *deposit_sums;
- struct GNUNET_JSON_Specification spec[] = {
- TALER_JSON_spec_amount_any ("total",
- &total),
- TALER_JSON_spec_amount_any ("wire_fee",
- &wire_fee),
- GNUNET_JSON_spec_timestamp ("execution_time",
- &execution_time),
- GNUNET_JSON_spec_json ("deposit_sums",
- &deposit_sums),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (json,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- hr.http_status = 0;
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- break;
- }
- else
- {
- size_t deposit_sums_length;
- struct TALER_MERCHANT_TrackTransferDetail *details;
- unsigned int i;
- bool ok;
-
- if (! json_is_array (deposit_sums))
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- hr.http_status = 0;
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- break;
- }
- deposit_sums_length = json_array_size (deposit_sums);
- details = GNUNET_new_array (deposit_sums_length,
- struct TALER_MERCHANT_TrackTransferDetail);
- ok = true;
- json_array_foreach (deposit_sums, i, deposit_sum) {
- struct TALER_MERCHANT_TrackTransferDetail *d = &details[i];
- struct GNUNET_JSON_Specification ispec[] = {
- GNUNET_JSON_spec_string ("order_id",
- &d->order_id),
- TALER_JSON_spec_amount_any ("deposit_value",
- &d->deposit_value),
- TALER_JSON_spec_amount_any ("deposit_fee",
- &d->deposit_fee),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (deposit_sum,
- ispec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- ok = false;
- break;
- }
- }
-
- if (! ok)
- {
- GNUNET_break_op (0);
- GNUNET_free (details);
- GNUNET_JSON_parse_free (spec);
- hr.http_status = 0;
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- break;
- }
- pth->cb (pth->cb_cls,
- &hr,
- execution_time,
- &total,
- &wire_fee,
- deposit_sums_length,
- details);
- GNUNET_free (details);
- GNUNET_JSON_parse_free (spec);
- TALER_MERCHANT_transfers_post_cancel (pth);
- return;
- }
- }
- case MHD_HTTP_ACCEPTED:
+ case MHD_HTTP_NO_CONTENT:
break;
case MHD_HTTP_UNAUTHORIZED:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ ptr.hr.ec = TALER_JSON_get_error_code (ptr.hr.reply);
+ ptr.hr.hint = TALER_JSON_get_error_hint (ptr.hr.reply);
/* Nothing really to verify, merchant says we need to authenticate. */
break;
case MHD_HTTP_NOT_FOUND:
@@ -202,44 +108,47 @@ handle_post_transfers_finished (void *cls,
happen, we should pass the JSON reply to the application */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Did not find any data\n");
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ ptr.hr.ec = TALER_JSON_get_error_code (ptr.hr.reply);
+ ptr.hr.hint = TALER_JSON_get_error_hint (ptr.hr.reply);
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ ptr.hr.ec = TALER_JSON_get_error_code (ptr.hr.reply);
+ ptr.hr.hint = TALER_JSON_get_error_hint (ptr.hr.reply);
break;
case MHD_HTTP_BAD_GATEWAY:
/* Exchange had an issue; we should retry, but this API
leaves this to the application */
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ ptr.hr.ec = TALER_JSON_get_error_code (ptr.hr.reply);
+ ptr.hr.hint = TALER_JSON_get_error_hint (ptr.hr.reply);
{
- uint32_t eec;
uint32_t ehc;
struct GNUNET_JSON_Specification ispec[] = {
- GNUNET_JSON_spec_uint32 ("exchange_code",
- &eec),
+ TALER_JSON_spec_ec ("exchange_code",
+ &ptr.details.bad_gateway.exchange_ec),
GNUNET_JSON_spec_uint32 ("exchange_http_status",
&ehc),
GNUNET_JSON_spec_end ()
};
if (GNUNET_OK !=
- GNUNET_JSON_parse (deposit_sum,
+ GNUNET_JSON_parse (ptr.hr.reply,
ispec,
NULL, NULL))
{
GNUNET_break_op (0);
+ ptr.details.bad_gateway.exchange_http_status = 0;
+ ptr.details.bad_gateway.exchange_ec = TALER_EC_NONE;
break;
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ ptr.details.bad_gateway.exchange_http_status
+ = (unsigned int) ehc;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Exchange returned %u/%u\n",
- (unsigned int) eec,
+ (unsigned int) ptr.details.bad_gateway.exchange_ec,
(unsigned int) ehc);
}
}
@@ -247,28 +156,23 @@ handle_post_transfers_finished (void *cls,
case MHD_HTTP_GATEWAY_TIMEOUT:
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ ptr.hr.ec = TALER_JSON_get_error_code (ptr.hr.reply);
+ ptr.hr.hint = TALER_JSON_get_error_hint (ptr.hr.reply);
break;
default:
/* unexpected response code */
GNUNET_break_op (0);
- TALER_MERCHANT_parse_error_details_ (json,
+ TALER_MERCHANT_parse_error_details_ (ptr.hr.reply,
response_code,
- &hr);
+ &ptr.hr);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d\n",
- (unsigned int) response_code,
- (int) hr.ec);
+ (unsigned int) ptr.hr.http_status,
+ (int) ptr.hr.ec);
break;
}
pth->cb (pth->cb_cls,
- &hr,
- GNUNET_TIME_UNIT_FOREVER_TS,
- NULL,
- NULL,
- 0,
- NULL);
+ &ptr);
TALER_MERCHANT_transfers_post_cancel (pth);
}