diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-01-06 20:24:05 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-01-06 20:24:05 +0100 |
commit | b1ccf194316920ff1898cca8c1a34169470dc164 (patch) | |
tree | 9fc065452e83b7bfa2718dfba2d1f4c2aea17faf /src/backend | |
parent | 4d920a818432ba757189f9b03a0886a37901dbb2 (diff) | |
download | merchant-b1ccf194316920ff1898cca8c1a34169470dc164.tar.gz merchant-b1ccf194316920ff1898cca8c1a34169470dc164.tar.bz2 merchant-b1ccf194316920ff1898cca8c1a34169470dc164.zip |
updating logic to use new depositcheck tooling (not yet working)
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/taler-merchant-httpd_private-get-orders-ID.c | 464 |
1 files changed, 13 insertions, 451 deletions
diff --git a/src/backend/taler-merchant-httpd_private-get-orders-ID.c b/src/backend/taler-merchant-httpd_private-get-orders-ID.c index 4f7959bd..fb8b9dd5 100644 --- a/src/backend/taler-merchant-httpd_private-get-orders-ID.c +++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.c @@ -31,13 +31,6 @@ /** - * How long do we wait on the exchange? - */ -#define EXCHANGE_TIMEOUT GNUNET_TIME_relative_multiply ( \ - GNUNET_TIME_UNIT_SECONDS, 30) - - -/** * Data structure we keep for a check payment request. */ struct GetOrderRequestContext; @@ -66,16 +59,6 @@ struct TransferQuery char *exchange_url; /** - * Handle to query exchange about deposit status. - */ - struct TALER_EXCHANGE_DepositGetHandle *dgh; - - /** - * Handle for ongoing exchange operation. - */ - struct TMH_EXCHANGES_KeysOperation *fo; - - /** * Overall request this TQ belongs with. */ struct GetOrderRequestContext *gorc; @@ -153,48 +136,41 @@ enum GetOrderPhase GOP_CHECK_REFUNDS = 6, /** - * Check if the exchange transferred the funds to - * the merchant. + * Load all deposits associated with the order. */ - GOP_CHECK_EXCHANGE_TRANSFERS = 7, - - /** - * We are suspended awaiting a response from the - * exchange. - */ - GOP_SUSPENDED_ON_EXCHANGE = 8, + GOP_CHECK_DEPOSITS = 7, /** * Check local records for transfers of funds to * the merchant. */ - GOP_CHECK_LOCAL_TRANSFERS = 9, + GOP_CHECK_LOCAL_TRANSFERS = 8, /** * Generate final comprehensive result. */ - GOP_REPLY_RESULT = 10, + GOP_REPLY_RESULT = 9, /** * End with the HTTP status and error code in * wire_hc and wire_ec. */ - GOP_ERROR = 11, + GOP_ERROR = 10, /** * We are suspended awaiting payment. */ - GOP_SUSPENDED_ON_UNPAID = 12, + GOP_SUSPENDED_ON_UNPAID = 11, /** * Processing is done, return #MHD_YES. */ - GOP_END_YES = 13, + GOP_END_YES = 12, /** * Processing is done, return #MHD_NO. */ - GOP_END_NO = 14 + GOP_END_NO = 13 }; @@ -298,12 +274,6 @@ struct GetOrderRequestContext json_t *wire_details; /** - * Problems we encountered when looking up Wire details - * for the payment, to be returned. NULL if not available. - */ - json_t *wire_reports; - - /** * Details about refunds, NULL if there are no refunds. */ json_t *refund_details; @@ -413,12 +383,6 @@ struct GetOrderRequestContext bool refund_pending; /** - * Did the client request us to fetch the wire transfer status? - * If false, we may still return it if it is available. - */ - bool transfer_status_requested; - - /** * Set to true if our database (incorrectly) has refunds * in a different currency than the currency of the * original payment for the order. @@ -463,65 +427,6 @@ TMH_force_gorc_resume (void) /** - * Resume processing the request, cancelling all pending asynchronous - * operations. - * - * @param gorc request to resume - */ -static void -gorc_resume (struct GetOrderRequestContext *gorc) -{ - struct TransferQuery *tq; - - if (NULL != gorc->tt) - { - GNUNET_SCHEDULER_cancel (gorc->tt); - gorc->tt = NULL; - } - while (NULL != (tq = gorc->tq_head)) - { - if (NULL != tq->fo) - { - TMH_EXCHANGES_keys4exchange_cancel (tq->fo); - tq->fo = NULL; - } - if (NULL != tq->dgh) - { - TALER_EXCHANGE_deposits_get_cancel (tq->dgh); - tq->dgh = NULL; - } - } - GNUNET_assert (GNUNET_YES == gorc->suspended); - GNUNET_CONTAINER_DLL_remove (gorc_head, - gorc_tail, - gorc); - gorc->suspended = GNUNET_NO; - MHD_resume_connection (gorc->sc.con); - TALER_MHD_daemon_trigger (); /* we resumed, kick MHD */ -} - - -/** - * Resume processing the request, cancelling all pending asynchronous - * operations. - * - * @param gorc request to resume - * @param http_status HTTP status to return, 0 to continue with success - * @param ec error code for the request, #TALER_EC_NONE on success - */ -static void -gorc_resume_error (struct GetOrderRequestContext *gorc, - unsigned int http_status, - enum TALER_ErrorCode ec) -{ - gorc->wire_hc = http_status; - gorc->wire_ec = ec; - gorc->phase = GOP_ERROR; - gorc_resume (gorc); -} - - -/** * We have received a trigger from the database * that we should (possibly) resume the request. * @@ -554,58 +459,6 @@ resume_by_event (void *cls, /** - * Add a report about trouble obtaining wire transfer data to the reply. - * - * @param gorc request to add wire report to - * @param ec error code to add - * @param coin_pub public key of the affected coin - * @param exchange_hr details from exchange, NULL if exchange is blameless - */ -static void -gorc_report (struct GetOrderRequestContext *gorc, - enum TALER_ErrorCode ec, - struct TALER_CoinSpendPublicKeyP *coin_pub, - const struct TALER_EXCHANGE_HttpResponse *exchange_hr) -{ - if (NULL != exchange_hr) - GNUNET_assert (0 == - json_array_append_new ( - gorc->wire_reports, - GNUNET_JSON_PACK ( - TALER_JSON_pack_ec (ec), - TMH_pack_exchange_reply (exchange_hr), - GNUNET_JSON_pack_data_auto ("coin_pub", - coin_pub)))); - else - GNUNET_assert (0 == - json_array_append_new ( - gorc->wire_reports, - GNUNET_JSON_PACK ( - TALER_JSON_pack_ec (ec), - GNUNET_JSON_pack_data_auto ("coin_pub", - coin_pub)))); -} - - -/** - * Timeout trying to get current wire transfer data from the exchange. - * Clean up and continue. - * - * @param cls closure, must be a `struct GetOrderRequestContext *` - */ -static void -exchange_timeout_cb (void *cls) -{ - struct GetOrderRequestContext *gorc = cls; - - gorc->tt = NULL; - gorc_resume_error (gorc, - MHD_HTTP_REQUEST_TIMEOUT, - TALER_EC_GENERIC_TIMEOUT); -} - - -/** * Clean up the session state for a GET /private/order/ID request. * * @param cls closure, must be a `struct GetOrderRequestContext *` @@ -621,8 +474,6 @@ gorc_cleanup (void *cls) json_decref (gorc->wire_details); if (NULL != gorc->refund_details) json_decref (gorc->refund_details); - if (NULL != gorc->wire_reports) - json_decref (gorc->wire_reports); if (NULL != gorc->tt) { GNUNET_SCHEDULER_cancel (gorc->tt); @@ -1245,243 +1096,6 @@ phase_check_refunds (struct GetOrderRequestContext *gorc) /** - * Function called with detailed wire transfer data. - * - * @param cls closure with a `struct TransferQuery *` - * @param dr HTTP response data - */ -static void -deposit_get_cb (void *cls, - const struct TALER_EXCHANGE_GetDepositResponse *dr) -{ - struct TransferQuery *tq = cls; - struct GetOrderRequestContext *gorc = tq->gorc; - - GNUNET_CONTAINER_DLL_remove (gorc->tq_head, - gorc->tq_tail, - tq); - switch (dr->hr.http_status) - { - case MHD_HTTP_OK: - { - enum GNUNET_DB_QueryStatus qs; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Exchange returned wire transfer over %s for deposited coin %s\n", - TALER_amount2s (&dr->details.ok.coin_contribution), - TALER_B2S (&tq->coin_pub)); - qs = TMH_db->insert_deposit_to_transfer (TMH_db->cls, - tq->deposit_serial, - &dr->details.ok); - if (qs < 0) - { - gorc_report (gorc, - TALER_EC_GENERIC_DB_STORE_FAILED, - &tq->coin_pub, - NULL); - GNUNET_free (tq->exchange_url); - GNUNET_free (tq); - if (NULL == gorc->tq_head) - { - gorc->phase++; - gorc_resume (gorc); - } - return; - } - /* Compute total amount *wired* */ - if ( (GNUNET_OK != - TALER_amount_cmp_currency ( - &gorc->deposits_total, - &dr->details.ok.coin_contribution)) || - (GNUNET_OK != - TALER_amount_cmp_currency ( - &gorc->deposit_fees_total, - &tq->deposit_fee)) ) - { - /* something very wrong in our database ... */ - GNUNET_break (0); - gorc_report (gorc, - TALER_EC_GENERIC_DB_FETCH_FAILED, - &tq->coin_pub, - NULL); - GNUNET_free (tq->exchange_url); - GNUNET_free (tq); - if (NULL == gorc->tq_head) - { - gorc->phase++; - gorc_resume (gorc); - } - return; - } - if (0 > - TALER_amount_add (&gorc->deposits_total, - &gorc->deposits_total, - &dr->details.ok.coin_contribution)) - { - gorc_report (gorc, - TALER_EC_MERCHANT_PRIVATE_GET_ORDERS_ID_AMOUNT_ARITHMETIC_FAILURE, - &tq->coin_pub, - NULL); - GNUNET_free (tq->exchange_url); - GNUNET_free (tq); - if (NULL == gorc->tq_head) - { - gorc->phase++; - gorc_resume (gorc); - } - return; - } - if (0 > - TALER_amount_add (&gorc->deposit_fees_total, - &gorc->deposit_fees_total, - &tq->deposit_fee)) - { - gorc_report (gorc, - TALER_EC_MERCHANT_PRIVATE_GET_ORDERS_ID_AMOUNT_ARITHMETIC_FAILURE, - &tq->coin_pub, - NULL); - GNUNET_free (tq->exchange_url); - GNUNET_free (tq); - if (NULL == gorc->tq_head) - { - gorc->phase++; - gorc_resume (gorc); - } - return; - } - break; - } - case MHD_HTTP_ACCEPTED: - { - /* got a 'preliminary' reply from the exchange, - remember our target UUID */ - enum GNUNET_DB_QueryStatus qs; - struct GNUNET_TIME_Timestamp now; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Exchange returned KYC requirement (%d/%d) for deposited coin %s\n", - dr->details.accepted.kyc_ok, - dr->details.accepted.aml_decision, - TALER_B2S (&tq->coin_pub)); - now = GNUNET_TIME_timestamp_get (); - qs = TMH_db->account_kyc_set_status ( - TMH_db->cls, - gorc->hc->instance->settings.id, - &tq->h_wire, - tq->exchange_url, - dr->details.accepted.requirement_row, - NULL, - NULL, - now, - dr->details.accepted.kyc_ok, - dr->details.accepted.aml_decision); - if (qs < 0) - { - gorc_report (gorc, - TALER_EC_GENERIC_DB_STORE_FAILED, - &tq->coin_pub, - NULL); - GNUNET_free (tq->exchange_url); - GNUNET_free (tq); - if (NULL == gorc->tq_head) - { - gorc->phase++; - gorc_resume (gorc); - } - return; - } - gorc_report (gorc, - TALER_EC_NONE, - &tq->coin_pub, - &dr->hr); - break; - } - default: - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Exchange returned tracking failure for deposited coin %s\n", - TALER_B2S (&tq->coin_pub)); - gorc_report (gorc, - TALER_EC_MERCHANT_GET_ORDERS_EXCHANGE_TRACKING_FAILURE, - &tq->coin_pub, - &dr->hr); - GNUNET_free (tq->exchange_url); - GNUNET_free (tq); - if (NULL == gorc->tq_head) - { - gorc->phase++; - gorc_resume (gorc); - } - return; - } - } /* end switch */ - GNUNET_free (tq->exchange_url); - GNUNET_free (tq); - if (NULL != gorc->tq_head) - return; - /* *all* are done, resume! */ - gorc->phase++; - gorc_resume (gorc); -} - - -/** - * Function called with the result of a #TMH_EXCHANGES_keys4exchange() - * operation. - * - * @param cls closure with a `struct GetOrderRequestContext *` - * @param keys keys of the exchange - * @param exchange representation of the exchange - */ -static void -exchange_found_cb (void *cls, - struct TALER_EXCHANGE_Keys *keys, - struct TMH_Exchange *exchange) -{ - struct TransferQuery *tq = cls; - struct GetOrderRequestContext *gorc = tq->gorc; - - (void) exchange; - tq->fo = NULL; - if (NULL == keys) - { - /* failed */ - GNUNET_CONTAINER_DLL_remove (gorc->tq_head, - gorc->tq_tail, - tq); - GNUNET_free (tq->exchange_url); - GNUNET_free (tq); - gorc_resume_error (gorc, - MHD_HTTP_GATEWAY_TIMEOUT, - TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT); - return; - } - tq->dgh = TALER_EXCHANGE_deposits_get ( - TMH_curl_ctx, - tq->exchange_url, - keys, - &gorc->hc->instance->merchant_priv, - &tq->h_wire, - &gorc->h_contract_terms, - &tq->coin_pub, - GNUNET_TIME_UNIT_ZERO, - &deposit_get_cb, - tq); - if (NULL == tq->dgh) - { - GNUNET_CONTAINER_DLL_remove (gorc->tq_head, - gorc->tq_tail, - tq); - GNUNET_free (tq->exchange_url); - GNUNET_free (tq); - gorc_resume_error (gorc, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_MERCHANT_GET_ORDERS_ID_EXCHANGE_REQUEST_FAILURE); - } -} - - -/** * Function called with each @a coin_pub that was deposited into the * @a h_wire account of the merchant for the @a deposit_serial as part * of the payment for the order identified by @a cls. @@ -1524,16 +1138,6 @@ deposit_cb (void *cls, tq->h_wire = *h_wire; tq->amount_with_fee = *amount_with_fee; tq->deposit_fee = *deposit_fee; - tq->fo = TMH_EXCHANGES_keys4exchange (exchange_url, - false, - &exchange_found_cb, - tq); - if (NULL == tq->fo) - { - gorc_resume_error (gorc, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_MERCHANT_GET_ORDERS_ID_EXCHANGE_LOOKUP_START_FAILURE); - } } @@ -1543,16 +1147,8 @@ deposit_cb (void *cls, * @param[in,out] gorc order context to update */ static void -phase_check_exchange_transfers (struct GetOrderRequestContext *gorc) +phase_check_deposits (struct GetOrderRequestContext *gorc) { - if (gorc->wired || - (! gorc->transfer_status_requested) ) - { - gorc->phase = GOP_CHECK_LOCAL_TRANSFERS; - return; - } - /* suspend connection, wait for exchange to check wire transfer status there */ - gorc->transfer_status_requested = false; /* only try ONCE */ GNUNET_assert (GNUNET_OK == TALER_amount_set_zero (gorc->contract_amount.currency, &gorc->deposits_total)); @@ -1563,22 +1159,7 @@ phase_check_exchange_transfers (struct GetOrderRequestContext *gorc) gorc->order_serial, &deposit_cb, gorc); - if (NULL == gorc->tq_head) - { - /* No deposits found for paid order. This is strange... */ - GNUNET_break (0); - gorc->phase = GOP_CHECK_LOCAL_TRANSFERS; - return; - } gorc->phase++; - GNUNET_CONTAINER_DLL_insert (gorc_head, - gorc_tail, - gorc); - gorc->suspended = GNUNET_YES; - MHD_suspend_connection (gorc->sc.con); - gorc->tt = GNUNET_SCHEDULER_add_delayed (EXCHANGE_TIMEOUT, - &exchange_timeout_cb, - gorc); } @@ -1784,8 +1365,9 @@ phase_reply_result (struct GetOrderRequestContext *gorc) ret = TALER_MHD_REPLY_JSON_PACK ( gorc->sc.con, MHD_HTTP_OK, + // Deprecated in protocol v6. GNUNET_JSON_pack_array_steal ("wire_reports", - gorc->wire_reports), + json_array ()), GNUNET_JSON_pack_uint64 ("exchange_code", gorc->exchange_ec), GNUNET_JSON_pack_uint64 ("exchange_http_status", @@ -1818,7 +1400,6 @@ phase_reply_result (struct GetOrderRequestContext *gorc) order_status_url)); GNUNET_free (order_status_url); gorc->wire_details = NULL; - gorc->wire_reports = NULL; gorc->refund_details = NULL; phase_end (gorc, ret); @@ -1862,24 +1443,9 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh, GNUNET_assert (NULL != gorc->wire_details); gorc->refund_details = json_array (); GNUNET_assert (NULL != gorc->refund_details); - gorc->wire_reports = json_array (); - GNUNET_assert (NULL != gorc->wire_reports); gorc->session_id = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "session_id"); - /* process 'transfer' argument */ - { - const char *transfer_s; - - transfer_s = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "transfer"); - if ( (NULL != transfer_s) && - (0 == strcasecmp (transfer_s, - "yes")) ) - gorc->transfer_status_requested = true; - } - TALER_MHD_parse_request_timeout (connection, &gorc->sc.long_poll_timeout); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -1919,8 +1485,8 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh, case GOP_CHECK_REFUNDS: phase_check_refunds (gorc); break; - case GOP_CHECK_EXCHANGE_TRANSFERS: - phase_check_exchange_transfers (gorc); + case GOP_CHECK_DEPOSITS: + phase_check_deposits (gorc); break; case GOP_CHECK_LOCAL_TRANSFERS: phase_check_local_transfers (gorc); @@ -1935,10 +1501,6 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh, GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Suspending order request awaiting payment\n"); return MHD_YES; - case GOP_SUSPENDED_ON_EXCHANGE: - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Suspending order request awaiting answer from exchange\n"); - return MHD_YES; case GOP_END_YES: return MHD_YES; case GOP_END_NO: |