diff options
author | Christian Grothoff <christian@grothoff.org> | 2023-05-04 21:57:52 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2023-05-04 21:57:52 +0200 |
commit | cbe046b30ab34ec07934bbdcbcb9b0438f24a821 (patch) | |
tree | 55828360b50e919e1ae518c5b9ccafff4fff5384 /src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c | |
parent | cdd68ba5a9d3dca49f00d4fff07caff600955abb (diff) |
wrap contract_terms in pay hook
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c b/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c index 5b5f6b05..130b9dde 100644 --- a/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c +++ b/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2014-2021 Taler Systems SA + (C) 2014-2023 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 published by the Free Software @@ -130,13 +130,13 @@ TMH_private_post_orders_ID_refund (const struct TMH_RequestHandler *rh, }; enum TALER_MERCHANTDB_RefundStatus rs; struct TALER_PrivateContractHashP h_contract; + json_t *contract_terms; + struct GNUNET_TIME_Timestamp timestamp; { enum GNUNET_DB_QueryStatus qs; - json_t *contract_terms; uint64_t order_serial; struct GNUNET_TIME_Timestamp refund_deadline; - struct GNUNET_TIME_Timestamp timestamp; bool paid = false; qs = TMH_db->lookup_contract_terms (TMH_db->cls, @@ -170,12 +170,12 @@ TMH_private_post_orders_ID_refund (const struct TMH_RequestHandler *rh, TALER_EC_MERCHANT_GENERIC_DB_CONTRACT_CONTENT_INVALID, "mandatory fields missing"); } - json_decref (contract_terms); if (GNUNET_TIME_timestamp_cmp (timestamp, ==, refund_deadline)) { /* refund was never allowed, so we should refuse hard */ + json_decref (contract_terms); return TALER_MHD_reply_with_error ( connection, MHD_HTTP_FORBIDDEN, @@ -191,6 +191,7 @@ TMH_private_post_orders_ID_refund (const struct TMH_RequestHandler *rh, } else { + json_decref (contract_terms); return TALER_MHD_reply_with_error (connection, MHD_HTTP_NOT_FOUND, TALER_EC_MERCHANT_GENERIC_ORDER_UNKNOWN, @@ -205,9 +206,12 @@ TMH_private_post_orders_ID_refund (const struct TMH_RequestHandler *rh, hc->request_body, spec); if (GNUNET_OK != res) + { + json_decref (contract_terms); return (GNUNET_NO == res) ? MHD_YES : MHD_NO; + } } TMH_db->preflight (TMH_db->cls); @@ -218,6 +222,7 @@ TMH_private_post_orders_ID_refund (const struct TMH_RequestHandler *rh, "increase refund")) { GNUNET_break (0); + json_decref (contract_terms); return TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, TALER_EC_GENERIC_DB_START_FAILED, @@ -238,8 +243,41 @@ TMH_private_post_orders_ID_refund (const struct TMH_RequestHandler *rh, if (TALER_MERCHANTDB_RS_SUCCESS == rs) { enum GNUNET_DB_QueryStatus qs; + json_t *rargs; - qs = TMH_db->commit (TMH_db->cls); + rargs = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_timestamp ("timestamp", + timestamp), + GNUNET_JSON_pack_string ("order_id", + hc->infix), + GNUNET_JSON_pack_object_incref ("contract_terms", + contract_terms), + TALER_JSON_pack_amount ("refund_amount", + &refund), + GNUNET_JSON_pack_string ("reason", + reason) + ); + GNUNET_assert (NULL != rargs); + qs = TMH_trigger_webhook ( + hc->instance->settings.id, + "refund", + rargs); + json_decref (rargs); + switch (qs) + { + case GNUNET_DB_STATUS_HARD_ERROR: + GNUNET_break (0); + TMH_db->rollback (TMH_db->cls); + rs = TALER_MERCHANTDB_RS_HARD_ERROR; + break; + case GNUNET_DB_STATUS_SOFT_ERROR: + TMH_db->rollback (TMH_db->cls); + continue; + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: + qs = TMH_db->commit (TMH_db->cls); + break; + } if (GNUNET_DB_STATUS_HARD_ERROR == qs) { GNUNET_break (0); @@ -253,6 +291,7 @@ TMH_private_post_orders_ID_refund (const struct TMH_RequestHandler *rh, } break; } /* retries loop */ + json_decref (contract_terms); switch (rs) { |