diff options
Diffstat (limited to 'src/backend/taler-merchant-httpd_post-orders-ID-pay.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_post-orders-ID-pay.c | 144 |
1 files changed, 46 insertions, 98 deletions
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c index 7e7642f0..85a1ed6a 100644 --- a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c +++ b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c @@ -30,6 +30,7 @@ #include <taler/taler_exchange_service.h> #include "taler-merchant-httpd_auditors.h" #include "taler-merchant-httpd_exchanges.h" +#include "taler-merchant-httpd_helper.h" #include "taler-merchant-httpd_post-orders-ID-pay.h" #include "taler-merchant-httpd_private-get-orders.h" @@ -599,18 +600,10 @@ deposit_cb (void *cls, /* internal server error at exchange */ resume_pay_with_response (pc, MHD_HTTP_BAD_GATEWAY, - TALER_MHD_make_json_pack ( - "{s:s, s:I, s:I, s:I}", - "hint", - TALER_ErrorCode_get_hint ( + TALER_MHD_MAKE_JSON_PACK ( + TALER_JSON_pack_ec ( TALER_EC_MERCHANT_GENERIC_EXCHANGE_UNEXPECTED_STATUS), - "code", - (json_int_t) - TALER_EC_MERCHANT_GENERIC_EXCHANGE_UNEXPECTED_STATUS, - "exchange_code", - (json_int_t) hr->ec, - "exchange_http_status", - (json_int_t) hr->http_status)); + TMH_pack_exchange_reply (hr))); } else if (NULL == hr->reply) { @@ -618,17 +611,10 @@ deposit_cb (void *cls, resume_pay_with_response ( pc, MHD_HTTP_BAD_GATEWAY, - TALER_MHD_make_json_pack ( - "{s:s, s:I, s:I, s:I}", - "hint", - TALER_ErrorCode_get_hint ( + TALER_MHD_MAKE_JSON_PACK ( + TALER_JSON_pack_ec ( TALER_EC_MERCHANT_GENERIC_EXCHANGE_REPLY_MALFORMED), - "code", - (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_REPLY_MALFORMED, - "exchange_code", - (json_int_t) hr->ec, - "exchange_http_status", - (json_int_t) hr->http_status)); + TMH_pack_exchange_reply (hr))); } else { @@ -639,42 +625,24 @@ deposit_cb (void *cls, resume_pay_with_response ( pc, MHD_HTTP_CONFLICT, - TALER_MHD_make_json_pack ("{s:s, s:I, s:I, s:I, s:o, s:O}", - "hint", - TALER_ErrorCode_get_hint ( - TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_INSUFFICIENT_FUNDS), - "code", - (json_int_t) - TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_INSUFFICIENT_FUNDS, - "exchange_code", - (json_int_t) hr->ec, - "exchange_http_status", - (json_int_t) hr->http_status, - "coin_pub", - GNUNET_JSON_from_data_auto (&dc->coin_pub), - "exchange_reply", - hr->reply)); + TALER_MHD_MAKE_JSON_PACK ( + TALER_JSON_pack_ec ( + TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_INSUFFICIENT_FUNDS), + TMH_pack_exchange_reply (hr), + GNUNET_JSON_pack_data_auto ("coin_pub", + &dc->coin_pub))); } else { resume_pay_with_response ( pc, MHD_HTTP_BAD_GATEWAY, - TALER_MHD_make_json_pack ("{s:s, s:I, s:I, s:I, s:o, s:O}", - "hint", - TALER_ErrorCode_get_hint ( - TALER_EC_MERCHANT_GENERIC_EXCHANGE_UNEXPECTED_STATUS), - "code", - (json_int_t) - TALER_EC_MERCHANT_GENERIC_EXCHANGE_UNEXPECTED_STATUS, - "exchange_code", - (json_int_t) hr->ec, - "exchange_http_status", - (json_int_t) hr->http_status, - "coin_pub", - GNUNET_JSON_from_data_auto (&dc->coin_pub), - "exchange_reply", - hr->reply)); + TALER_MHD_MAKE_JSON_PACK ( + TALER_JSON_pack_ec ( + TALER_EC_MERCHANT_GENERIC_EXCHANGE_UNEXPECTED_STATUS), + TMH_pack_exchange_reply (hr), + GNUNET_JSON_pack_data_auto ("coin_pub", + &dc->coin_pub))); } } return; @@ -763,13 +731,8 @@ process_pay_with_exchange (void *cls, resume_pay_with_response ( pc, 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_JSON_PACK ( + TALER_JSON_pack_ec (TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT))); return; } if ( (MHD_HTTP_OK != hr->http_status) || @@ -778,14 +741,10 @@ process_pay_with_exchange (void *cls, resume_pay_with_response ( pc, 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; } keys = TALER_EXCHANGE_get_keys (exchange_handle); @@ -839,15 +798,15 @@ process_pay_with_exchange (void *cls, resume_pay_with_response ( pc, MHD_HTTP_BAD_REQUEST, - TALER_MHD_make_json_pack ( - "{s:s, s:I, s:o, s:o?}", - "hint", - TALER_ErrorCode_get_hint ( + TALER_MHD_MAKE_JSON_PACK ( + TALER_JSON_pack_ec ( TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_DENOMINATION_KEY_NOT_FOUND), - "code", - TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_DENOMINATION_KEY_NOT_FOUND, - "h_denom_pub", GNUNET_JSON_from_data_auto (&dc->h_denom), - "exchange_keys", TALER_EXCHANGE_get_keys_raw (exchange_handle))); + GNUNET_JSON_pack_data_auto ("h_denom_pub", + &dc->h_denom), + GNUNET_JSON_pack_allow_null ( + GNUNET_JSON_pack_object_incref ( + "exchange_keys", + (json_t *) TALER_EXCHANGE_get_keys_raw (exchange_handle))))); return; } if (GNUNET_OK != @@ -873,14 +832,10 @@ process_pay_with_exchange (void *cls, resume_pay_with_response ( pc, http_status, - TALER_MHD_make_json_pack ( - "{s:s, s:I, s:o}", - "hint", - TALER_ErrorCode_get_hint (ec), - "code", - (json_int_t) ec, - "h_denom_pub", - GNUNET_JSON_from_data_auto (&denom_details->h_key))); + TALER_MHD_MAKE_JSON_PACK ( + TALER_JSON_pack_ec (ec), + GNUNET_JSON_pack_data_auto ("h_denom_pub", + &denom_details->h_key))); return; } @@ -914,11 +869,10 @@ process_pay_with_exchange (void *cls, resume_pay_with_response ( pc, TALER_ErrorCode_get_http_status_safe (ec), - TALER_MHD_make_json_pack ( - "{s:s, s:I, s:i}", - "hint", TALER_ErrorCode_get_hint (ec), - "code", (json_int_t) ec, - "coin_idx", i)); + TALER_MHD_MAKE_JSON_PACK ( + TALER_JSON_pack_ec (ec), + GNUNET_JSON_pack_uint64 ("coin_idx", + i))); return; } if (TMH_force_audit) @@ -1552,18 +1506,12 @@ execute_pay_transaction (struct PayContext *pc) } /* Build the response */ - { - json_t *resp; - - resp = json_pack ("{s:o}", - "sig", - GNUNET_JSON_from_data_auto (&sig)); - GNUNET_assert (NULL != resp); - resume_pay_with_response (pc, - MHD_HTTP_OK, - TALER_MHD_make_json (resp)); - json_decref (resp); - } + resume_pay_with_response ( + pc, + MHD_HTTP_OK, + TALER_MHD_MAKE_JSON_PACK ( + GNUNET_JSON_pack_data_auto ("sig", + &sig))); } } |