diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-10-13 18:53:16 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-10-13 18:53:16 +0200 |
commit | f02a3a2055fc27a6a570d5d21af434b914881e01 (patch) | |
tree | 949d7f46d49b16ca367534059415daf8144178d5 | |
parent | 9d7abac6af174ac232096b63caa167df4fe348d2 (diff) | |
download | merchant-f02a3a2055fc27a6a570d5d21af434b914881e01.tar.gz merchant-f02a3a2055fc27a6a570d5d21af434b914881e01.tar.bz2 merchant-f02a3a2055fc27a6a570d5d21af434b914881e01.zip |
-migrate logic to match latest C API changes from the exchange
-rw-r--r-- | src/backend/taler-merchant-httpd_helper.h | 10 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_post-orders-ID-pay.c | 172 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-get-orders-ID.c | 129 |
3 files changed, 155 insertions, 156 deletions
diff --git a/src/backend/taler-merchant-httpd_helper.h b/src/backend/taler-merchant-httpd_helper.h index dc7c08b1..659bddc2 100644 --- a/src/backend/taler-merchant-httpd_helper.h +++ b/src/backend/taler-merchant-httpd_helper.h @@ -123,11 +123,11 @@ TMH_uuid_from_string (const char *uuids, * @param hr a `TALER_EXCHANGE_HttpResponse` */ #define TMH_pack_exchange_reply(hr) \ - GNUNET_JSON_pack_uint64 ("exchange_code", hr->ec), \ - GNUNET_JSON_pack_uint64 ("exchange_http_status", hr->http_status), \ - GNUNET_JSON_pack_uint64 ("exchange_ec", hr->ec), /* LEGACY */ \ - GNUNET_JSON_pack_uint64 ("exchange_hc", hr->http_status), /* LEGACY */ \ + GNUNET_JSON_pack_uint64 ("exchange_code", (hr)->ec), \ + GNUNET_JSON_pack_uint64 ("exchange_http_status", (hr)->http_status), \ + GNUNET_JSON_pack_uint64 ("exchange_ec", (hr)->ec), /* LEGACY */ \ + GNUNET_JSON_pack_uint64 ("exchange_hc", (hr)->http_status), /* LEGACY */ \ GNUNET_JSON_pack_allow_null ( \ - GNUNET_JSON_pack_object_incref ("exchange_reply", (json_t *) hr->reply)) + GNUNET_JSON_pack_object_incref ("exchange_reply", (json_t *) (hr)->reply)) #endif 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 72abde23..88309f06 100644 --- a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c +++ b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c @@ -574,10 +574,7 @@ execute_pay_transaction (struct PayContext *pc); */ static void deposit_cb (void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr, - struct GNUNET_TIME_Absolute deposit_timestamp, - const struct TALER_ExchangeSignatureP *exchange_sig, - const struct TALER_ExchangePublicKeyP *exchange_pub) + const struct TALER_EXCHANGE_DepositResult *dr) { struct DepositConfirmation *dc = cls; struct PayContext *pc = dc->pc; @@ -585,14 +582,66 @@ deposit_cb (void *cls, dc->dh = NULL; GNUNET_assert (GNUNET_YES == pc->suspended); pc->pending_at_ce--; - if (MHD_HTTP_OK != hr->http_status) + switch (dr->hr.http_status) { + case MHD_HTTP_OK: + { + /* store result to DB */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Storing successful payment %s (%s) at instance `%s'\n", + pc->hc->infix, + GNUNET_h2s (&pc->h_contract_terms), + pc->hc->instance->settings.id); + TMH_db->preflight (TMH_db->cls); + { + enum GNUNET_DB_QueryStatus qs; + + qs = TMH_db->insert_deposit (TMH_db->cls, + pc->hc->instance->settings.id, + dr->details.success.deposit_timestamp, + &pc->h_contract_terms, + &dc->coin_pub, + dc->exchange_url, + &dc->amount_with_fee, + &dc->deposit_fee, + &dc->refund_fee, + &dc->wire_fee, + &pc->wm->h_wire, + dr->details.success.exchange_sig, + dr->details.success.exchange_pub); + if (0 > qs) + { + /* Special report if retries insufficient */ + if (GNUNET_DB_STATUS_SOFT_ERROR == qs) + { + execute_pay_transaction (pc); + return; + } + /* Always report on hard error as well to enable diagnostics */ + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + /* Forward error including 'proof' for the body */ + resume_pay_with_error (pc, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "deposit"); + return; + } + } + + dc->found_in_db = true; /* well, at least NOW it'd be true ;-) */ + pc->pending--; + + if (0 != pc->pending_at_ce) + return; /* still more to do with current exchange */ + find_next_exchange (pc); + } + default: GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deposit operation failed with HTTP code %u/%d\n", - hr->http_status, - (int) hr->ec); + dr->hr.http_status, + (int) dr->hr.ec); /* Transaction failed */ - if (5 == hr->http_status / 100) + if (5 == dr->hr.http_status / 100) { /* internal server error at exchange */ resume_pay_with_response (pc, @@ -600,9 +649,10 @@ deposit_cb (void *cls, TALER_MHD_MAKE_JSON_PACK ( TALER_JSON_pack_ec ( TALER_EC_MERCHANT_GENERIC_EXCHANGE_UNEXPECTED_STATUS), - TMH_pack_exchange_reply (hr))); + TMH_pack_exchange_reply (&dr->hr))); + return; } - else if (NULL == hr->reply) + if (NULL == dr->hr.reply) { /* We can't do anything meaningful here, the exchange did something wrong */ resume_pay_with_response ( @@ -611,88 +661,36 @@ deposit_cb (void *cls, TALER_MHD_MAKE_JSON_PACK ( TALER_JSON_pack_ec ( TALER_EC_MERCHANT_GENERIC_EXCHANGE_REPLY_MALFORMED), - TMH_pack_exchange_reply (hr))); - } - else - { - /* Forward error, adding the "coin_pub" for which the - error was being generated */ - if (TALER_EC_EXCHANGE_DEPOSIT_INSUFFICIENT_FUNDS == hr->ec) - { - resume_pay_with_response ( - pc, - MHD_HTTP_CONFLICT, - 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 ( - 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))); - } + TMH_pack_exchange_reply (&dr->hr))); + return; } - return; - } - /* store result to DB */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Storing successful payment %s (%s) at instance `%s'\n", - pc->hc->infix, - GNUNET_h2s (&pc->h_contract_terms), - pc->hc->instance->settings.id); - TMH_db->preflight (TMH_db->cls); - { - enum GNUNET_DB_QueryStatus qs; - - qs = TMH_db->insert_deposit (TMH_db->cls, - pc->hc->instance->settings.id, - deposit_timestamp, - &pc->h_contract_terms, - &dc->coin_pub, - dc->exchange_url, - &dc->amount_with_fee, - &dc->deposit_fee, - &dc->refund_fee, - &dc->wire_fee, - &pc->wm->h_wire, - exchange_sig, - exchange_pub); - if (0 > qs) + /* Forward error, adding the "coin_pub" for which the + error was being generated */ + if (TALER_EC_EXCHANGE_DEPOSIT_INSUFFICIENT_FUNDS == dr->hr.ec) { - /* Special report if retries insufficient */ - if (GNUNET_DB_STATUS_SOFT_ERROR == qs) - { - execute_pay_transaction (pc); - return; - } - /* Always report on hard error as well to enable diagnostics */ - GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); - /* Forward error including 'proof' for the body */ - resume_pay_with_error (pc, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_STORE_FAILED, - "deposit"); + resume_pay_with_response ( + pc, + MHD_HTTP_CONFLICT, + TALER_MHD_MAKE_JSON_PACK ( + TALER_JSON_pack_ec ( + TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_INSUFFICIENT_FUNDS), + TMH_pack_exchange_reply (&dr->hr), + GNUNET_JSON_pack_data_auto ("coin_pub", + &dc->coin_pub))); return; } - } - - dc->found_in_db = true; /* well, at least NOW it'd be true ;-) */ - pc->pending--; - - if (0 != pc->pending_at_ce) - return; /* still more to do with current exchange */ - find_next_exchange (pc); + resume_pay_with_response ( + pc, + MHD_HTTP_BAD_GATEWAY, + TALER_MHD_MAKE_JSON_PACK ( + TALER_JSON_pack_ec ( + TALER_EC_MERCHANT_GENERIC_EXCHANGE_UNEXPECTED_STATUS), + TMH_pack_exchange_reply (&dr->hr), + GNUNET_JSON_pack_data_auto ("coin_pub", + &dc->coin_pub))); + return; + } /* end switch */ } 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 b272e4c0..a981a7cf 100644 --- a/src/backend/taler-merchant-httpd_private-get-orders-ID.c +++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.c @@ -424,8 +424,7 @@ exchange_timeout_cb (void *cls) */ static void deposit_get_cb (void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr, - const struct TALER_EXCHANGE_DepositData *dd) + const struct TALER_EXCHANGE_GetDepositResponse *dr) { struct TransferQuery *tq = cls; struct GetOrderRequestContext *gorc = tq->gorc; @@ -433,65 +432,75 @@ deposit_get_cb (void *cls, GNUNET_CONTAINER_DLL_remove (gorc->tq_head, gorc->tq_tail, tq); - if (NULL == dd) + switch (dr->hr.http_status) { - gorc_report (gorc, - TALER_EC_MERCHANT_GET_ORDERS_EXCHANGE_TRACKING_FAILURE, - &tq->coin_pub, - hr); - GNUNET_free (tq); - if (NULL == gorc->tq_head) - gorc_resume (gorc, - 0, - TALER_EC_NONE); - return; - } - else if (MHD_HTTP_OK == hr->http_status) - { - enum GNUNET_DB_QueryStatus qs; - - qs = TMH_db->insert_deposit_to_transfer (TMH_db->cls, - tq->deposit_serial, - dd); - if (qs < 0) + case MHD_HTTP_OK: { - gorc_report (gorc, - TALER_EC_GENERIC_DB_STORE_FAILED, - &tq->coin_pub, - NULL); - GNUNET_free (tq); - if (NULL == gorc->tq_head) - gorc_resume (gorc, - 0, - TALER_EC_NONE); - return; - } - /* Compute total amount *wired* */ - if (0 > - TALER_amount_add (&gorc->deposits_total, - &gorc->deposits_total, - &dd->coin_contribution)) - { - gorc_report (gorc, - TALER_EC_MERCHANT_PRIVATE_GET_ORDERS_ID_AMOUNT_ARITHMETIC_FAILURE, - &tq->coin_pub, - NULL); - GNUNET_free (tq); - if (NULL == gorc->tq_head) - gorc_resume (gorc, - 0, - TALER_EC_NONE); - return; + enum GNUNET_DB_QueryStatus qs; + + qs = TMH_db->insert_deposit_to_transfer (TMH_db->cls, + tq->deposit_serial, + &dr->details.success); + if (qs < 0) + { + gorc_report (gorc, + TALER_EC_GENERIC_DB_STORE_FAILED, + &tq->coin_pub, + NULL); + GNUNET_free (tq); + if (NULL == gorc->tq_head) + gorc_resume (gorc, + 0, + TALER_EC_NONE); + return; + } + /* Compute total amount *wired* */ + if (0 > + TALER_amount_add (&gorc->deposits_total, + &gorc->deposits_total, + &dr->details.success.coin_contribution)) + { + gorc_report (gorc, + TALER_EC_MERCHANT_PRIVATE_GET_ORDERS_ID_AMOUNT_ARITHMETIC_FAILURE, + &tq->coin_pub, + NULL); + GNUNET_free (tq); + if (NULL == gorc->tq_head) + gorc_resume (gorc, + 0, + TALER_EC_NONE); + 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); + if (NULL == gorc->tq_head) + gorc_resume (gorc, + 0, + TALER_EC_NONE); + return; + } } - if (0 > - TALER_amount_add (&gorc->deposit_fees_total, - &gorc->deposit_fees_total, - &tq->deposit_fee)) + case MHD_HTTP_ACCEPTED: + /* got a 'preliminary' reply from the exchange, simply skip */ + // FIXME: store dr->details.accepted.payment_target_uuid! + gorc_report (gorc, + TALER_EC_NONE, + &tq->coin_pub, + &dr->hr); + default: { gorc_report (gorc, - TALER_EC_MERCHANT_PRIVATE_GET_ORDERS_ID_AMOUNT_ARITHMETIC_FAILURE, + TALER_EC_MERCHANT_GET_ORDERS_EXCHANGE_TRACKING_FAILURE, &tq->coin_pub, - NULL); + &dr->hr); GNUNET_free (tq); if (NULL == gorc->tq_head) gorc_resume (gorc, @@ -499,15 +508,7 @@ deposit_get_cb (void *cls, TALER_EC_NONE); return; } - } - else - { - /* got a 'preliminary' reply from the exchange, simply skip */ - gorc_report (gorc, - TALER_EC_NONE, - &tq->coin_pub, - hr); - } + } /* end switch */ GNUNET_free (tq); if (NULL != gorc->tq_head) return; |