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.c163
1 files changed, 88 insertions, 75 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 0e033a7f..93835a24 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
@@ -594,14 +594,15 @@ deposit_cb (void *cls,
{
/* internal server error at exchange */
resume_pay_with_response (pc,
- MHD_HTTP_FAILED_DEPENDENCY,
+ MHD_HTTP_BAD_GATEWAY,
TALER_MHD_make_json_pack (
"{s:s, s:I, s:I, s:I}",
"hint",
TALER_ErrorCode_get_hint (
- TALER_EC_PAY_EXCHANGE_FAILED),
+ TALER_EC_MERCHANT_GENERIC_EXCHANGE_UNEXPECTED_STATUS),
"code",
- (json_int_t) TALER_EC_PAY_EXCHANGE_FAILED,
+ (json_int_t)
+ TALER_EC_MERCHANT_GENERIC_EXCHANGE_UNEXPECTED_STATUS,
"exchange_code",
(json_int_t) hr->ec,
"exchange_http_status",
@@ -612,14 +613,14 @@ deposit_cb (void *cls,
/* We can't do anything meaningful here, the exchange did something wrong */
resume_pay_with_response (
pc,
- MHD_HTTP_FAILED_DEPENDENCY,
+ MHD_HTTP_BAD_GATEWAY,
TALER_MHD_make_json_pack (
"{s:s, s:I, s:I, s:I}",
"hint",
TALER_ErrorCode_get_hint (
- TALER_EC_PAY_EXCHANGE_REPLY_MALFORMED),
+ TALER_EC_MERCHANT_GENERIC_EXCHANGE_REPLY_MALFORMED),
"code",
- (json_int_t) TALER_EC_PAY_EXCHANGE_REPLY_MALFORMED,
+ (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_REPLY_MALFORMED,
"exchange_code",
(json_int_t) hr->ec,
"exchange_http_status",
@@ -629,16 +630,17 @@ deposit_cb (void *cls,
{
/* Forward error, adding the "coin_pub" for which the
error was being generated */
- if (TALER_EC_DEPOSIT_INSUFFICIENT_FUNDS == hr->ec)
+ if (TALER_EC_EXCHANGE_DEPOSIT_INSUFFICIENT_FUNDS == hr->ec)
resume_pay_with_response (
pc,
MHD_HTTP_CONFLICT,
TALER_MHD_make_json_pack ("{s:s, s:I, s:I, s:I, s:o, s:O}",
"hint",
TALER_ErrorCode_get_hint (
- TALER_EC_PAY_INSUFFICIENT_FUNDS),
+ TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_INSUFFICIENT_FUNDS),
"code",
- (json_int_t) TALER_EC_PAY_INSUFFICIENT_FUNDS,
+ (json_int_t)
+ TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_INSUFFICIENT_FUNDS,
"exchange_code",
(json_int_t) hr->ec,
"exchange_http_status",
@@ -650,13 +652,14 @@ deposit_cb (void *cls,
else
resume_pay_with_response (
pc,
- MHD_HTTP_FAILED_DEPENDENCY,
+ MHD_HTTP_BAD_GATEWAY,
TALER_MHD_make_json_pack ("{s:s, s:I, s:I, s:I, s:o, s:O}",
"hint",
TALER_ErrorCode_get_hint (
- TALER_EC_PAY_EXCHANGE_FAILED),
+ TALER_EC_MERCHANT_GENERIC_EXCHANGE_UNEXPECTED_STATUS),
"code",
- (json_int_t) TALER_EC_PAY_EXCHANGE_FAILED,
+ (json_int_t)
+ TALER_EC_MERCHANT_GENERIC_EXCHANGE_UNEXPECTED_STATUS,
"exchange_code",
(json_int_t) hr->ec,
"exchange_http_status",
@@ -703,8 +706,8 @@ deposit_cb (void *cls,
/* Forward error including 'proof' for the body */
resume_pay_with_error (pc,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_PAY_DB_STORE_PAY_ERROR,
- "Merchant database error");
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "deposit");
return;
}
dc->found_in_db = true; /* well, at least NOW it'd be true ;-) */
@@ -743,28 +746,34 @@ process_pay_with_exchange (void *cls,
(void) payto_uri;
pc->fo = NULL;
GNUNET_assert (GNUNET_YES == pc->suspended);
- if (MHD_HTTP_OK != hr->http_status)
+ if (NULL == hr)
{
- /* The request failed somehow */
- GNUNET_break_op (0);
resume_pay_with_response (
pc,
- MHD_HTTP_FAILED_DEPENDENCY,
+ MHD_HTTP_GATEWAY_TIMEOUT,
TALER_MHD_make_json_pack (
- (NULL != hr->reply)
- ? "{s:s, s:I, s:I, s:I, s:O}"
- : "{s:s, s:I, s:I, s:I}",
+ "{s:s, s:I}",
"hint",
TALER_ErrorCode_get_hint (
- TALER_EC_PAY_EXCHANGE_KEYS_FAILURE),
+ TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT),
"code",
- (json_int_t) TALER_EC_PAY_EXCHANGE_KEYS_FAILURE,
- "exchange_http_status",
- (json_int_t) hr->http_status,
- "exchange_code",
- (json_int_t) hr->ec,
- "exchange_reply",
- hr->reply));
+ (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT));
+ return;
+ }
+ if (NULL == exchange_handle)
+ {
+ GNUNET_break_op (0);
+ resume_pay_with_response (
+ pc,
+ MHD_HTTP_BAD_GATEWAY,
+ TALER_MHD_make_json_pack (
+ "{s:s, s:I, s:I, s:I, s:O?}",
+ "hint", TALER_ErrorCode_get_hint (
+ TALER_EC_MERCHANT_GENERIC_EXCHANGE_CONNECT_FAILURE),
+ "code", (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_CONNECT_FAILURE,
+ "exchange_http_status", (json_int_t) hr->http_status,
+ "exchange_code", (json_int_t) hr->ec,
+ "exchange_reply", hr->reply));
return;
}
keys = TALER_EXCHANGE_get_keys (exchange_handle);
@@ -772,9 +781,9 @@ process_pay_with_exchange (void *cls,
{
GNUNET_break (0); /* should not be possible if HTTP status is #MHD_HTTP_OK */
resume_pay_with_error (pc,
- MHD_HTTP_FAILED_DEPENDENCY,
- TALER_EC_PAY_EXCHANGE_KEYS_FAILURE,
- "no keys");
+ MHD_HTTP_BAD_GATEWAY,
+ TALER_EC_MERCHANT_GENERIC_EXCHANGE_KEYS_FAILURE,
+ NULL);
return;
}
@@ -822,8 +831,9 @@ process_pay_with_exchange (void *cls,
"{s:s, s:I, s:o, s:o}",
"hint",
TALER_ErrorCode_get_hint (
- TALER_EC_PAY_DENOMINATION_KEY_NOT_FOUND),
- "code", TALER_EC_PAY_DENOMINATION_KEY_NOT_FOUND,
+ TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_DENOMINATION_KEY_NOT_FOUND),
+ "code",
+ TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_DENOMINATION_KEY_NOT_FOUND,
"h_denom_pub", GNUNET_JSON_from_data_auto (&dc->h_denom),
"exchange_keys", TALER_EXCHANGE_get_keys_raw (exchange_handle)));
return;
@@ -881,8 +891,11 @@ process_pay_with_exchange (void *cls,
TALER_MHD_make_json_pack (
"{s:s, s:I, s:i}",
"hint",
- TALER_ErrorCode_get_hint (TALER_EC_PAY_COIN_SIGNATURE_INVALID),
- "code", (json_int_t) TALER_EC_PAY_COIN_SIGNATURE_INVALID,
+ TALER_ErrorCode_get_hint (
+ TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_COIN_SIGNATURE_INVALID),
+ "code",
+ (json_int_t)
+ TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_COIN_SIGNATURE_INVALID,
"coin_idx", i));
return;
}
@@ -920,7 +933,7 @@ find_next_exchange (struct PayContext *pc)
GNUNET_break (0);
resume_pay_with_error (pc,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_PAY_EXCHANGE_LOOKUP_FAILED,
+ TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_EXCHANGE_LOOKUP_FAILED,
"Failed to lookup exchange by URL");
return;
}
@@ -1070,7 +1083,7 @@ check_payment_sufficient (struct PayContext *pc)
/* Overflow in these amounts? Very strange. */
resume_pay_with_error (pc,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_PAY_AMOUNT_OVERFLOW,
+ TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_AMOUNT_OVERFLOW,
"Overflow adding up amounts");
}
if (1 ==
@@ -1080,7 +1093,7 @@ check_payment_sufficient (struct PayContext *pc)
GNUNET_break_op (0);
resume_pay_with_error (pc,
MHD_HTTP_BAD_REQUEST,
- TALER_EC_PAY_FEES_EXCEED_PAYMENT,
+ TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_FEES_EXCEED_PAYMENT,
"Deposit fees exceed coin's contribution");
return false;
}
@@ -1105,8 +1118,8 @@ check_payment_sufficient (struct PayContext *pc)
GNUNET_break_op (0);
resume_pay_with_error (pc,
MHD_HTTP_PRECONDITION_FAILED,
- TALER_EC_PAY_WIRE_FEE_CURRENCY_MISMATCH,
- "exchange wire in different currency");
+ TALER_EC_GENERIC_CURRENCY_MISMATCH,
+ total_wire_fee.currency);
return false;
}
if (0 >
@@ -1117,7 +1130,7 @@ check_payment_sufficient (struct PayContext *pc)
GNUNET_break (0);
resume_pay_with_error (pc,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_PAY_EXCHANGE_WIRE_FEE_ADDITION_FAILED,
+ TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_EXCHANGE_WIRE_FEE_ADDITION_FAILED,
"could not add exchange wire fee to total");
return false;
}
@@ -1152,8 +1165,8 @@ check_payment_sufficient (struct PayContext *pc)
{
resume_pay_with_error (pc,
MHD_HTTP_PRECONDITION_FAILED,
- TALER_EC_PAY_WIRE_FEE_CURRENCY_MISMATCH,
- "exchange wire does not match our currency");
+ TALER_EC_GENERIC_CURRENCY_MISMATCH,
+ total_wire_fee.currency);
return false;
}
@@ -1189,7 +1202,7 @@ check_payment_sufficient (struct PayContext *pc)
GNUNET_break (0);
resume_pay_with_error (pc,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_PAY_AMOUNT_OVERFLOW,
+ TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_AMOUNT_OVERFLOW,
"Overflow adding up amounts");
return false;
}
@@ -1217,7 +1230,7 @@ check_payment_sufficient (struct PayContext *pc)
GNUNET_break (0);
resume_pay_with_error (pc,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_PAY_AMOUNT_OVERFLOW,
+ TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_AMOUNT_OVERFLOW,
"Overflow adding up amounts");
return false;
}
@@ -1241,7 +1254,7 @@ check_payment_sufficient (struct PayContext *pc)
GNUNET_break (0);
resume_pay_with_error (pc,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_PAY_REFUNDS_EXCEED_PAYMENTS,
+ TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_REFUNDS_EXCEED_PAYMENTS,
"refunded amount exceeds total payments");
return false;
}
@@ -1255,7 +1268,7 @@ check_payment_sufficient (struct PayContext *pc)
{
resume_pay_with_error (pc,
MHD_HTTP_PAYMENT_REQUIRED,
- TALER_EC_PAY_REFUNDED,
+ TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_REFUNDED,
"contract not paid up due to refunds");
}
else if (-1 < TALER_amount_cmp (&acc_amount,
@@ -1264,7 +1277,7 @@ check_payment_sufficient (struct PayContext *pc)
GNUNET_break_op (0);
resume_pay_with_error (pc,
MHD_HTTP_NOT_ACCEPTABLE,
- TALER_EC_PAY_PAYMENT_INSUFFICIENT_DUE_TO_FEES,
+ TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_INSUFFICIENT_DUE_TO_FEES,
"contract not paid up due to fees (client may have calculated them badly)");
}
else
@@ -1272,7 +1285,7 @@ check_payment_sufficient (struct PayContext *pc)
GNUNET_break_op (0);
resume_pay_with_error (pc,
MHD_HTTP_NOT_ACCEPTABLE,
- TALER_EC_PAY_PAYMENT_INSUFFICIENT,
+ TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_PAYMENT_INSUFFICIENT,
"payment insufficient");
}
return false;
@@ -1295,8 +1308,8 @@ begin_transaction (struct PayContext *pc)
GNUNET_break (0);
resume_pay_with_error (pc,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_PAY_DB_STORE_TRANSACTION_ERROR,
- "Soft merchant database error: retry counter exceeded");
+ TALER_EC_GENERIC_DB_SOFT_FAILURE,
+ NULL);
return;
}
GNUNET_assert (GNUNET_YES == pc->suspended);
@@ -1326,8 +1339,8 @@ begin_transaction (struct PayContext *pc)
GNUNET_break (0);
resume_pay_with_error (pc,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_PAY_DB_FETCH_TRANSACTION_ERROR,
- "Merchant database error (could not begin transaction)");
+ TALER_EC_GENERIC_DB_START_FAILED,
+ NULL);
return;
}
@@ -1349,8 +1362,8 @@ begin_transaction (struct PayContext *pc)
GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
resume_pay_with_error (pc,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_PAY_DB_FETCH_TRANSACTION_ERROR,
- "Merchant database error");
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "deposits");
return;
}
@@ -1372,8 +1385,8 @@ begin_transaction (struct PayContext *pc)
GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
resume_pay_with_error (pc,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_PAY_DB_FETCH_TRANSACTION_ERROR,
- "Merchant database error checking for refunds");
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "lookup refunds");
return;
}
refunded = (qs > 0);
@@ -1419,8 +1432,8 @@ begin_transaction (struct PayContext *pc)
}
resume_pay_with_error (pc,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_PAY_DB_STORE_PAYMENTS_ERROR,
- "Could not set contract to 'paid' in DB");
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "mark contract paid");
return;
}
@@ -1437,8 +1450,8 @@ begin_transaction (struct PayContext *pc)
}
resume_pay_with_error (pc,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_PAY_DB_STORE_PAYMENTS_ERROR,
- "Database commit mark proposal as 'paid' failed");
+ TALER_EC_GENERIC_DB_COMMIT_FAILED,
+ NULL);
return;
}
@@ -1489,7 +1502,7 @@ begin_transaction (struct PayContext *pc)
GNUNET_break (0);
resume_pay_with_error (pc,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_JSON_ALLOCATION_FAILURE,
+ TALER_EC_GENERIC_JSON_ALLOCATION_FAILURE,
"Could not build final response");
return;
}
@@ -1562,7 +1575,7 @@ parse_pay (struct MHD_Connection *connection,
GNUNET_JSON_parse_free (spec);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_BAD_REQUEST,
- TALER_EC_PAY_COINS_ARRAY_EMPTY,
+ TALER_EC_GENERIC_PARAMETER_MISSING,
"'coins' array is empty or not even an array");
}
@@ -1641,8 +1654,8 @@ parse_pay (struct MHD_Connection *connection,
return (MHD_YES ==
TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_PAY_DB_FETCH_PAY_ERROR,
- NULL))
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "contract terms"))
? GNUNET_NO
: GNUNET_SYSERR;
}
@@ -1651,7 +1664,7 @@ parse_pay (struct MHD_Connection *connection,
return (MHD_YES ==
TALER_MHD_reply_with_error (connection,
MHD_HTTP_NOT_FOUND,
- TALER_EC_PAY_PROPOSAL_NOT_FOUND,
+ TALER_EC_MERCHANT_GENERIC_ORDER_UNKNOWN,
pc->order_id))
? GNUNET_NO
: GNUNET_SYSERR;
@@ -1667,7 +1680,7 @@ parse_pay (struct MHD_Connection *connection,
return (MHD_YES ==
TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_PAY_FAILED_COMPUTE_PROPOSAL_HASH,
+ TALER_EC_GENERIC_FAILED_COMPUTE_JSON_HASH,
NULL))
? GNUNET_NO
: GNUNET_SYSERR;
@@ -1687,7 +1700,7 @@ parse_pay (struct MHD_Connection *connection,
return (MHD_YES ==
TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_PAY_MERCHANT_FIELD_MISSING,
+ TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_MERCHANT_FIELD_MISSING,
NULL))
? GNUNET_NO
: GNUNET_SYSERR;
@@ -1742,7 +1755,7 @@ parse_pay (struct MHD_Connection *connection,
GNUNET_break (0);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_PAY_REFUND_DEADLINE_PAST_WIRE_TRANSFER_DEADLINE,
+ TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_REFUND_DEADLINE_PAST_WIRE_TRANSFER_DEADLINE,
NULL);
}
@@ -1753,7 +1766,7 @@ parse_pay (struct MHD_Connection *connection,
return (MHD_YES ==
TALER_MHD_reply_with_error (connection,
MHD_HTTP_GONE,
- TALER_EC_PAY_OFFER_EXPIRED,
+ TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_OFFER_EXPIRED,
NULL))
? GNUNET_NO
: GNUNET_SYSERR;
@@ -1773,7 +1786,7 @@ parse_pay (struct MHD_Connection *connection,
GNUNET_break (0);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_PAY_WIRE_HASH_UNKNOWN,
+ TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_WIRE_HASH_UNKNOWN,
NULL);
}
pc->wm = wm;
@@ -1803,9 +1816,9 @@ handle_pay_timeout (void *cls)
pc->fo = NULL;
}
resume_pay_with_error (pc,
- MHD_HTTP_REQUEST_TIMEOUT,
- TALER_EC_PAY_EXCHANGE_TIMEOUT,
- "likely the exchange did not reply quickly enough");
+ MHD_HTTP_GATEWAY_TIMEOUT,
+ TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT,
+ NULL);
}