merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 60d84b6a4468b22b3a801b169c7f978f344c5fbc
parent 879be3f7d27eb5279bbe51194a66aab4fcc8d8ce
Author: Özgür Kesim <oec@codeblau.de>
Date:   Fri, 23 Jul 2021 19:09:42 +0200

-simplify

Diffstat:
Msrc/backend/taler-merchant-httpd_post-orders-ID-paid.c | 87++++++++++++++++++++++++++++---------------------------------------------------
1 file changed, 31 insertions(+), 56 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-paid.c b/src/backend/taler-merchant-httpd_post-orders-ID-paid.c @@ -34,7 +34,7 @@ TMH_post_orders_ID_paid (const struct TMH_RequestHandler *rh, struct MHD_Connection *connection, struct TMH_HandlerContext *hc) { - struct PaymentResponsePS pr = { + struct TALER_PaymentResponsePS pr = { .purpose.purpose = htonl (TALER_SIGNATURE_MERCHANT_PAYMENT_OK), .purpose.size = htonl (sizeof (pr)) }; @@ -42,6 +42,7 @@ TMH_post_orders_ID_paid (const struct TMH_RequestHandler *rh, struct TALER_MerchantSignatureP merchant_sig; const char *session_id; json_t *contract_terms; + const char *fulfillment_url; enum GNUNET_DB_QueryStatus qs; { @@ -102,7 +103,7 @@ TMH_post_orders_ID_paid (const struct TMH_RequestHandler *rh, return TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, TALER_EC_GENERIC_DB_FETCH_FAILED, - "contract terms"); + "lookup_contract_terms"); } if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) { @@ -134,68 +135,42 @@ TMH_post_orders_ID_paid (const struct TMH_RequestHandler *rh, { json_decref (contract_terms); return TALER_MHD_reply_with_error (connection, - MHD_HTTP_CONFLICT, + MHD_HTTP_BAD_REQUEST, TALER_EC_MERCHANT_POST_ORDERS_ID_PAID_CONTRACT_HASH_MISMATCH, NULL); } } - if (NULL != session_id) - { - if (GNUNET_OK != - TMH_db->start (TMH_db->cls, - "post /paid")) - { - json_decref (contract_terms); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_START_FAILED, - NULL); - } - { - const char *fulfillment_url; - - fulfillment_url - = json_string_value (json_object_get (contract_terms, - "fulfillment_url")); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Marking contract %s with %s/%s as paid\n", - order_id, - session_id, - fulfillment_url); - } - qs = TMH_db->mark_contract_paid (TMH_db->cls, - hc->instance->settings.id, - &pr.h_contract_terms, - session_id); - /* Since the order was paid already, we get qs == 0. */ - if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) - { - qs = TMH_db->commit (TMH_db->cls); - if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) - qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; - } - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) - { - TMH_db->rollback (TMH_db->cls); - json_decref (contract_terms); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_STORE_FAILED, - "mark contract paid"); - } - } - if (NULL != session_id) - { - const char *fulfillment_url; - fulfillment_url - = json_string_value (json_object_get (contract_terms, + + fulfillment_url + = json_string_value (json_object_get (contract_terms, "fulfillment_url")); - if (NULL != fulfillment_url) - TMH_long_poll_resume2 (session_id, - fulfillment_url); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Marking contract %s with %s/%s as paid\n", + order_id, + session_id, + fulfillment_url); + qs = TMH_db->mark_contract_paid (TMH_db->cls, + hc->instance->settings.id, + &pr.h_contract_terms, + session_id); + /* If the order was paid already, we get qs == 0. */ + if (0 > qs) + { + GNUNET_break (0); + json_decref (contract_terms); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "mark_contract_paid"); } + + /* Wake everybody up who waits for this fulfillment_url and session_id */ + if (NULL != fulfillment_url) + TMH_long_poll_resume2 (session_id, + fulfillment_url); + /* fulfillment_url is part of the contract_terms */ json_decref (contract_terms); /* Resume clients waiting on the order */ TMH_long_poll_resume (order_id,