summaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd_post-orders-ID-abort.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-08-01 22:49:04 +0200
committerChristian Grothoff <christian@grothoff.org>2021-08-01 22:49:04 +0200
commit92b86cc5a7277de1a3b3ab55aaf37c83a649930e (patch)
treeeef73525a65c6fe6825559f050b8ea971ca8302a /src/backend/taler-merchant-httpd_post-orders-ID-abort.c
parent4e18bf19dfed52aa448a0b0d8547c0be182ba36a (diff)
downloadmerchant-92b86cc5a7277de1a3b3ab55aaf37c83a649930e.tar.gz
merchant-92b86cc5a7277de1a3b3ab55aaf37c83a649930e.tar.bz2
merchant-92b86cc5a7277de1a3b3ab55aaf37c83a649930e.zip
finish implementing #6935
Diffstat (limited to 'src/backend/taler-merchant-httpd_post-orders-ID-abort.c')
-rw-r--r--src/backend/taler-merchant-httpd_post-orders-ID-abort.c98
1 files changed, 43 insertions, 55 deletions
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-abort.c b/src/backend/taler-merchant-httpd_post-orders-ID-abort.c
index 759c3ba5..f0b2a0c2 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-abort.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-abort.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2014-2020 Taler Systems SA
+ (C) 2014-2021 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
@@ -27,6 +27,7 @@
#include <taler/taler_json_lib.h>
#include <taler/taler_exchange_service.h>
#include "taler-merchant-httpd_exchanges.h"
+#include "taler-merchant-httpd_helper.h"
/**
@@ -366,49 +367,44 @@ generate_success_response (struct AbortContext *ac)
(0 == rdi->http_status) ||
(NULL == rdi->exchange_reply) )
hc = MHD_HTTP_BAD_GATEWAY;
- detail = (MHD_HTTP_OK != rdi->http_status)
- ? json_pack ("{s:s, s:I, s:I, s:O?}",
- "type",
- "failure",
- "exchange_status",
- (json_int_t) rdi->http_status,
- "exchange_code",
- (json_int_t)
- (NULL != rdi->exchange_reply)
- ? TALER_JSON_get_error_code (
- rdi->exchange_reply)
- : TALER_EC_GENERIC_INVALID_RESPONSE,
- "exchange_reply",
- rdi->exchange_reply)
- : json_pack ("{s:s, s:I, s:o, s:o}",
- "type",
- "success",
- "exchange_status",
- (json_int_t) rdi->http_status,
- "exchange_sig",
- GNUNET_JSON_from_data_auto (&rdi->exchange_sig),
- "exchange_pub",
- GNUNET_JSON_from_data_auto (&rdi->exchange_pub));
- if ( (NULL == detail) ||
- (0 != json_array_append_new (refunds,
- detail)) )
- {
- json_decref (refunds);
- GNUNET_break (0);
- resume_abort_with_error (ac,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_JSON_ALLOCATION_FAILURE,
- "could not create JSON array");
- return;
- }
+ if (MHD_HTTP_OK != rdi->http_status)
+ detail = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "failure"),
+ GNUNET_JSON_pack_uint64 ("exchange_status",
+ rdi->http_status),
+ GNUNET_JSON_pack_uint64 ("exchange_code",
+ (NULL != rdi->exchange_reply)
+ ?
+ TALER_JSON_get_error_code (
+ rdi->exchange_reply)
+ :
+ TALER_EC_GENERIC_INVALID_RESPONSE),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("exchange_reply",
+ rdi->exchange_reply)));
+ else
+ detail = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "success"),
+ GNUNET_JSON_pack_uint64 ("exchange_status",
+ rdi->http_status),
+ GNUNET_JSON_pack_data_auto ("exchange_sig",
+ &rdi->exchange_sig),
+ GNUNET_JSON_pack_data_auto ("exchange_pub",
+ &rdi->exchange_pub));
+ GNUNET_assert (0 ==
+ json_array_append_new (refunds,
+ detail));
}
/* Resume and send back the response. */
- resume_abort_with_response (ac,
- hc,
- TALER_MHD_make_json_pack ("{s:o}",
- "refunds",
- refunds));
+ resume_abort_with_response (
+ ac,
+ hc,
+ TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_array_steal ("refunds",
+ refunds)));
}
@@ -534,13 +530,9 @@ process_abort_with_exchange (void *cls,
resume_abort_with_response (
ac,
MHD_HTTP_GATEWAY_TIMEOUT,
- TALER_MHD_make_json_pack (
- "{s:s, s:I}",
- "hint",
- TALER_ErrorCode_get_hint (
- TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT),
- "code",
- (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT));
+ TALER_MHD_make_error (
+ TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT,
+ NULL));
return;
}
if (NULL == exchange_handle)
@@ -550,14 +542,10 @@ process_abort_with_exchange (void *cls,
resume_abort_with_response (
ac,
MHD_HTTP_BAD_GATEWAY,
- TALER_MHD_make_json_pack (
- "{s:s, s:I, s:I, s:I, s:O?}",
- "hint", TALER_ErrorCode_get_hint (
+ TALER_MHD_MAKE_JSON_PACK (
+ TALER_JSON_pack_ec (
TALER_EC_MERCHANT_GENERIC_EXCHANGE_CONNECT_FAILURE),
- "code", (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_CONNECT_FAILURE,
- "exchange_http_status", (json_int_t) hr->http_status,
- "exchange_code", (json_int_t) hr->ec,
- "exchange_reply", hr->reply));
+ TMH_pack_exchange_reply (hr)));
return;
}
/* Initiate refund operation for all coins of