summaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/taler-merchant-httpd_post-orders-ID-pay.c')
-rw-r--r--src/backend/taler-merchant-httpd_post-orders-ID-pay.c127
1 files changed, 51 insertions, 76 deletions
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 3a051a3c..75bc4345 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
@@ -173,7 +173,7 @@ struct ExchangeGroup
* the exchange used for this transaction; NULL if no operation is
* pending.
*/
- struct TMH_EXCHANGES_Find2Operation *fo;
+ struct TMH_EXCHANGES_KeysOperation *fo;
/**
* Handle for operation to lookup /wire from
@@ -189,6 +189,12 @@ struct ExchangeGroup
const char *exchange_url;
/**
+ * Wire fee that applies to this exchange for the
+ * given payment context's wire method.
+ */
+ struct TALER_Amount wire_fee;
+
+ /**
* true if we already tried a forced /keys download.
*/
bool tried_force_keys;
@@ -454,7 +460,7 @@ struct KycContext
/**
* Looking for the exchange.
*/
- struct TMH_EXCHANGES_Find2Operation *fo;
+ struct TMH_EXCHANGES_KeysOperation *fo;
/**
* Exchange this is about.
@@ -636,20 +642,19 @@ resume_pay_with_response (struct PayContext *pc,
* Resume payment processing with an error.
*
* @param pc operation to resume
- * @param http_status http status code to return
* @param ec taler error code to return
* @param msg human readable error message
*/
static void
resume_pay_with_error (struct PayContext *pc,
- unsigned int http_status,
enum TALER_ErrorCode ec,
const char *msg)
{
- resume_pay_with_response (pc,
- http_status,
- TALER_MHD_make_error (ec,
- msg));
+ resume_pay_with_response (
+ pc,
+ TALER_ErrorCode_get_http_status_safe (ec),
+ TALER_MHD_make_error (ec,
+ msg));
}
@@ -795,7 +800,7 @@ process_kyc_with_exchange (
return;
}
kc->dg = TALER_EXCHANGE_deposits_get (
- merchant_curl_ctx,
+ TMH_curl_ctx,
kc->exchange_url,
keys,
&kc->mi->merchant_priv,
@@ -1007,7 +1012,6 @@ handle_batch_deposit_ok (struct ExchangeGroup *eg,
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,
"insert_deposit");
return;
@@ -1023,7 +1027,6 @@ handle_batch_deposit_ok (struct ExchangeGroup *eg,
{
GNUNET_break (0);
resume_pay_with_error (pc,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_DB_COMMIT_FAILED,
"insert_deposit");
}
@@ -1032,7 +1035,6 @@ handle_batch_deposit_ok (struct ExchangeGroup *eg,
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
{
resume_pay_with_error (pc,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_DB_SOFT_FAILURE,
"insert_deposit");
return;
@@ -1160,6 +1162,7 @@ process_pay_with_keys (
unsigned int group_size;
eg->fo = NULL;
+ GNUNET_SCHEDULER_begin_async_scope (&hc->async_scope_id);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Processing payment with exchange %s\n",
eg->exchange_url);
@@ -1168,11 +1171,10 @@ process_pay_with_keys (
{
GNUNET_break_op (0);
pc->pending_at_eg--;
- resume_pay_with_response (
+ resume_pay_with_error (
pc,
- MHD_HTTP_GATEWAY_TIMEOUT,
- TALER_MHD_MAKE_JSON_PACK (
- TALER_JSON_pack_ec (TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT)));
+ TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT,
+ NULL);
return;
}
@@ -1286,7 +1288,8 @@ AGE_FAIL:
&dc->cdd.h_age_commitment);
GNUNET_free (dc->age_commitment.keys);
}
- else if (is_age_restricted_denom && dc->no_h_age_commitment)
+ else if (is_age_restricted_denom &&
+ dc->no_h_age_commitment)
{
/* The contract did not ask for a minimum_age but the client paid
* with a coin that has age restriction enabled. We lack the hash
@@ -1336,7 +1339,6 @@ AGE_FAIL:
for (unsigned int i = 0; i<pc->coins_cnt; i++)
{
struct DepositConfirmation *dc = &pc->dc[i];
- enum GNUNET_GenericReturnValue ret;
if (dc->found_in_db)
continue;
@@ -1344,36 +1346,13 @@ AGE_FAIL:
eg->exchange_url))
continue;
cdds[i] = dc->cdd;
- ret = TMH_EXCHANGES_lookup_wire_fee (dc->exchange_url,
- pc->wm->wire_method,
- &dc->wire_fee);
- if (GNUNET_OK != ret)
- {
- enum TALER_ErrorCode ec;
-
- fprintf (stderr,
- "%d\n",
- ret);
- ec = (GNUNET_NO == ret)
- ? TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_WIRE_METHOD_UNSUPPORTED
- : TALER_EC_MERCHANT_GENERIC_EXCHANGE_WIRE_REQUEST_FAILED;
- pc->pending_at_eg--;
- GNUNET_break_op (0);
- resume_pay_with_response (
- pc,
- TALER_ErrorCode_get_http_status_safe (ec),
- TALER_MHD_MAKE_JSON_PACK (
- TALER_JSON_pack_ec (ec),
- GNUNET_JSON_pack_string ("wire_method",
- pc->wm->wire_method)));
- return;
- }
+ dc->wire_fee = eg->wire_fee;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Initiating batch deposit with %u coins\n",
group_size);
eg->bdh = TALER_EXCHANGE_batch_deposit (
- merchant_curl_ctx,
+ TMH_curl_ctx,
eg->exchange_url,
keys,
&dcd,
@@ -1413,23 +1392,24 @@ AGE_FAIL:
static void
process_pay_with_wire (
void *cls,
- struct TMH_Exchange *wire)
+ const struct TMH_ExchangeWireDetails *wire)
{
struct ExchangeGroup *eg = cls;
struct PayContext *pc = eg->pc;
+ struct TMH_HandlerContext *hc = pc->hc;
+ enum GNUNET_GenericReturnValue ret;
eg->gwo = NULL;
+ GNUNET_SCHEDULER_begin_async_scope (&hc->async_scope_id);
if (NULL == wire)
{
GNUNET_break_op (0);
pc->pending_at_eg--;
/* FIXME: define more specific error code... */
- resume_pay_with_response (
+ resume_pay_with_error (
pc,
- MHD_HTTP_BAD_GATEWAY,
- TALER_MHD_MAKE_JSON_PACK (
- TALER_JSON_pack_ec (
- TALER_EC_MERCHANT_GENERIC_EXCHANGE_CONNECT_FAILURE)));
+ TALER_EC_MERCHANT_GENERIC_EXCHANGE_CONNECT_FAILURE,
+ NULL);
return;
}
if (GNUNET_OK !=
@@ -1438,16 +1418,32 @@ process_pay_with_wire (
{
GNUNET_break_op (0);
pc->pending_at_eg--;
- resume_pay_with_response (
+ resume_pay_with_error (
pc,
- MHD_HTTP_CONFLICT,
- TALER_MHD_MAKE_JSON_PACK (
- TALER_JSON_pack_ec (
- TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_WIRE_METHOD_UNSUPPORTED)));
+ TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_WIRE_METHOD_UNSUPPORTED,
+ NULL);
+ return;
+ }
+ ret = TMH_EXCHANGES_lookup_wire_fee (wire,
+ pc->wm->wire_method,
+ &eg->wire_fee);
+ if (GNUNET_OK != ret)
+ {
+ enum TALER_ErrorCode ec;
+
+ ec = (GNUNET_NO == ret)
+ ? TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_WIRE_METHOD_UNSUPPORTED
+ : TALER_EC_MERCHANT_GENERIC_EXCHANGE_WIRE_REQUEST_FAILED;
+ pc->pending_at_eg--;
+ GNUNET_break_op (0);
+ resume_pay_with_error (
+ pc,
+ ec,
+ pc->wm->wire_method);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Fetching /keys for %s\n",
+ "Got /wire for %s, now going for /keys\n",
eg->exchange_url);
eg->fo = TMH_EXCHANGES_keys4exchange (eg->exchange_url,
&process_pay_with_keys,
@@ -1457,7 +1453,6 @@ process_pay_with_wire (
GNUNET_break (0);
pc->pending_at_eg--;
resume_pay_with_error (pc,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_EXCHANGE_LOOKUP_FAILED,
"Failed to lookup exchange by URL");
return;
@@ -1503,7 +1498,6 @@ start_batch_deposits (struct PayContext *pc)
{
GNUNET_break (0);
resume_pay_with_error (pc,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_EXCHANGE_LOOKUP_FAILED,
"Failed to lookup exchange by URL");
return;
@@ -1665,7 +1659,6 @@ check_payment_sufficient (struct PayContext *pc)
GNUNET_break (0);
/* Overflow in these amounts? Very strange. */
resume_pay_with_error (pc,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_AMOUNT_OVERFLOW,
"Overflow adding up amounts");
return false;
@@ -1676,7 +1669,6 @@ check_payment_sufficient (struct PayContext *pc)
{
GNUNET_break_op (0);
resume_pay_with_error (pc,
- MHD_HTTP_BAD_REQUEST,
TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_FEES_EXCEED_PAYMENT,
"Deposit fees exceed coin's contribution");
return false;
@@ -1703,7 +1695,6 @@ check_payment_sufficient (struct PayContext *pc)
{
GNUNET_break_op (0);
resume_pay_with_error (pc,
- MHD_HTTP_CONFLICT,
TALER_EC_GENERIC_CURRENCY_MISMATCH,
total_wire_fee.currency);
return false;
@@ -1715,7 +1706,6 @@ check_payment_sufficient (struct PayContext *pc)
{
GNUNET_break (0);
resume_pay_with_error (pc,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_EXCHANGE_WIRE_FEE_ADDITION_FAILED,
"could not add exchange wire fee to total");
return false;
@@ -1750,7 +1740,6 @@ check_payment_sufficient (struct PayContext *pc)
{
GNUNET_break (0);
resume_pay_with_error (pc,
- MHD_HTTP_CONFLICT,
TALER_EC_GENERIC_CURRENCY_MISMATCH,
total_wire_fee.currency);
return false;
@@ -1787,7 +1776,6 @@ check_payment_sufficient (struct PayContext *pc)
{
GNUNET_break (0);
resume_pay_with_error (pc,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_AMOUNT_OVERFLOW,
"Overflow adding up amounts");
return false;
@@ -1815,7 +1803,6 @@ check_payment_sufficient (struct PayContext *pc)
{
GNUNET_break (0);
resume_pay_with_error (pc,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_AMOUNT_OVERFLOW,
"Overflow adding up amounts");
return false;
@@ -1839,7 +1826,6 @@ check_payment_sufficient (struct PayContext *pc)
{
GNUNET_break (0);
resume_pay_with_error (pc,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_REFUNDS_EXCEED_PAYMENTS,
"refunded amount exceeds total payments");
return false;
@@ -1854,7 +1840,6 @@ check_payment_sufficient (struct PayContext *pc)
{
GNUNET_break_op (0);
resume_pay_with_error (pc,
- MHD_HTTP_PAYMENT_REQUIRED,
TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_REFUNDED,
"contract not paid up due to refunds");
}
@@ -1863,7 +1848,6 @@ check_payment_sufficient (struct PayContext *pc)
{
GNUNET_break_op (0);
resume_pay_with_error (pc,
- MHD_HTTP_NOT_ACCEPTABLE,
TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_INSUFFICIENT_DUE_TO_FEES,
"contract not paid up due to fees (client may have calculated them badly)");
}
@@ -1871,7 +1855,6 @@ check_payment_sufficient (struct PayContext *pc)
{
GNUNET_break_op (0);
resume_pay_with_error (pc,
- MHD_HTTP_NOT_ACCEPTABLE,
TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_PAYMENT_INSUFFICIENT,
"payment insufficient");
}
@@ -1982,7 +1965,6 @@ execute_pay_transaction (struct PayContext *pc)
{
GNUNET_break (0);
resume_pay_with_error (pc,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_DB_SOFT_FAILURE,
NULL);
return;
@@ -2013,7 +1995,6 @@ execute_pay_transaction (struct PayContext *pc)
{
GNUNET_break (0);
resume_pay_with_error (pc,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_DB_START_FAILED,
NULL);
return;
@@ -2039,7 +2020,6 @@ execute_pay_transaction (struct PayContext *pc)
/* Always report on hard error as well to enable diagnostics */
GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
resume_pay_with_error (pc,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_DB_FETCH_FAILED,
"lookup deposits");
return;
@@ -2067,7 +2047,6 @@ execute_pay_transaction (struct PayContext *pc)
/* Always report on hard error as well to enable diagnostics */
GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
resume_pay_with_error (pc,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_DB_FETCH_FAILED,
"lookup refunds");
return;
@@ -2117,7 +2096,6 @@ execute_pay_transaction (struct PayContext *pc)
}
GNUNET_break (0);
resume_pay_with_error (pc,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_DB_STORE_FAILED,
"mark contract paid");
return;
@@ -2153,7 +2131,6 @@ execute_pay_transaction (struct PayContext *pc)
}
GNUNET_break (0);
resume_pay_with_error (pc,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_DB_STORE_FAILED,
"failed to trigger webhooks");
return;
@@ -2175,7 +2152,6 @@ execute_pay_transaction (struct PayContext *pc)
}
GNUNET_break (0);
resume_pay_with_error (pc,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_DB_COMMIT_FAILED,
NULL);
return;
@@ -2740,7 +2716,6 @@ handle_pay_timeout (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Resuming pay with error after timeout\n");
resume_pay_with_error (pc,
- MHD_HTTP_GATEWAY_TIMEOUT,
TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT,
NULL);
}