diff options
author | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-06-25 01:55:15 -0400 |
---|---|---|
committer | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-06-25 01:55:15 -0400 |
commit | 9d0a68e578a77cbe9c1443dc1831de157b8a0fa8 (patch) | |
tree | 13c5f0e7d15086fbc541f7c5eececd19f352d716 /src/backend/taler-merchant-httpd_get-orders-ID.c | |
parent | 0fbdd6c6cda1c7e0ad0b4ffc3f22bac3e1176c1d (diff) | |
download | merchant-9d0a68e578a77cbe9c1443dc1831de157b8a0fa8.tar.gz merchant-9d0a68e578a77cbe9c1443dc1831de157b8a0fa8.tar.bz2 merchant-9d0a68e578a77cbe9c1443dc1831de157b8a0fa8.zip |
wallet get order handles refunds properly
Diffstat (limited to 'src/backend/taler-merchant-httpd_get-orders-ID.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_get-orders-ID.c | 113 |
1 files changed, 80 insertions, 33 deletions
diff --git a/src/backend/taler-merchant-httpd_get-orders-ID.c b/src/backend/taler-merchant-httpd_get-orders-ID.c index 8dd858a3..1a7c16a4 100644 --- a/src/backend/taler-merchant-httpd_get-orders-ID.c +++ b/src/backend/taler-merchant-httpd_get-orders-ID.c @@ -646,6 +646,7 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh, god->ec = TALER_EC_NONE; god->hc = hc; god->order_id = order_id; + god->cr_head = NULL; { const char *cts; @@ -887,7 +888,34 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh, } /* At this point, we know the contract was paid. Let's check for - refunds */ + refunds. First, clear away refunds found from previous invocations. */ + { + struct CoinRefund *cr; + + while (NULL != (cr = god->cr_head)) + { + GNUNET_CONTAINER_DLL_remove (god->cr_head, + god->cr_tail, + cr); + if (NULL != cr->fo) + { + TMH_EXCHANGES_find_exchange_cancel (cr->fo); + cr->fo = NULL; + } + if (NULL != cr->rh) + { + TALER_EXCHANGE_refund_cancel (cr->rh); + cr->rh = NULL; + } + if (NULL != cr->exchange_reply) + { + json_decref (cr->exchange_reply); + cr->exchange_reply = NULL; + } + GNUNET_free (cr->exchange_url); + GNUNET_free (cr); + } + } GNUNET_assert (GNUNET_OK == TALER_amount_get_zero (TMH_currency, &god->refund_amount)); qs = TMH_db->lookup_refunds_detailed (TMH_db->cls, @@ -984,40 +1012,59 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh, NULL != cr; cr = cr->next) { + json_t *refund; + if (MHD_HTTP_OK != cr->exchange_status) + { + if (NULL == cr->exchange_reply) + { + refund = json_pack ("{s:I,s:I,s:o,s:o}" + "exchange_status", + (json_int_t) cr->exchange_status, + "rtransaction_id", + (json_int_t) cr->rtransaction_id, + "coin_pub", + GNUNET_JSON_from_data_auto (&cr->coin_pub), + "refund_amount", + TALER_JSON_from_amount (&cr->refund_amount)); + } + else + { + refund = json_pack ("{s:I,s:I,s:o,s:I,s:o,s:o}" + "exchange_status", + (json_int_t) cr->exchange_status, + "exchange_code", + (json_int_t) cr->exchange_code, + "exchange_reply", + cr->exchange_reply, + "rtransaction_id", + (json_int_t) cr->rtransaction_id, + "coin_pub", + GNUNET_JSON_from_data_auto (&cr->coin_pub), + "refund_amount", + TALER_JSON_from_amount (&cr->refund_amount)); + } + } + else + { + refund = json_pack ("{s:I,s:o,s:o,s:I,s:o,s:o}", + "exchange_status", + (json_int_t) cr->exchange_status, + "exchange_sig", + GNUNET_JSON_from_data_auto (&cr->exchange_sig), + "exchange_pub", + GNUNET_JSON_from_data_auto (&cr->exchange_pub), + "rtransaction_id", + (json_int_t) cr->rtransaction_id, + "coin_pub", + GNUNET_JSON_from_data_auto (&cr->coin_pub), + "refund_amount", + TALER_JSON_from_amount (&cr->refund_amount), + "exchange_http_status"); + } GNUNET_assert ( 0 == - json_array_append_new ( - ra, - (MHD_HTTP_OK != cr->exchange_status) - ? json_pack ((NULL != cr->exchange_reply) - ? "{s:o,s:o,s:I,s:I,s:I,s:O}" - : "{s:o,s:o,s:I,s:I:s:I}", - "coin_pub", - GNUNET_JSON_from_data_auto (&cr->coin_pub), - "refund_amount", - TALER_JSON_from_amount (&cr->refund_amount), - "exchange_http_status", - (json_int_t) cr->exchange_status, - "rtransaction_id", - (json_int_t) cr->rtransaction_id, - "exchange_code", - (json_int_t) cr->exchange_code, - "exchange_reply", - cr->exchange_reply) - : json_pack ("{s:o,s:o,s:I,s:I,s:o,s:o}", - "coin_pub", - GNUNET_JSON_from_data_auto (&cr->coin_pub), - "refund_amount", - TALER_JSON_from_amount (&cr->refund_amount), - "exchange_http_status", - (json_int_t) cr->exchange_status, - "rtransaction_id", - (json_int_t) cr->rtransaction_id, - "exchange_pub", - GNUNET_JSON_from_data_auto (&cr->exchange_pub), - "exchange_sig", - GNUNET_JSON_from_data_auto (&cr->exchange_sig) - ))); + json_array_append_new (ra, + refund)); } return TALER_MHD_reply_json_pack ( |