summaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2023-10-13 14:43:50 +0200
committerChristian Grothoff <grothoff@gnunet.org>2023-10-13 21:16:50 +0200
commita5f50083e65a3e9a0945b150701349afa81a0e9e (patch)
treea6a89fa83c78d812a7f6a38e851659cf443269dd /src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c
parenta8b2456ecf47e2650f8bac1da3cc25b4ace54d24 (diff)
downloadmerchant-a5f50083e65a3e9a0945b150701349afa81a0e9e.tar.gz
merchant-a5f50083e65a3e9a0945b150701349afa81a0e9e.tar.bz2
merchant-a5f50083e65a3e9a0945b150701349afa81a0e9e.zip
work towards multi-currency support
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c')
-rw-r--r--src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c112
1 files changed, 52 insertions, 60 deletions
diff --git a/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c b/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c
index 1b2aa460..58fa96f4 100644
--- a/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c
+++ b/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c
@@ -133,6 +133,20 @@ TMH_private_post_orders_ID_refund (const struct TMH_RequestHandler *rh,
struct GNUNET_TIME_Timestamp timestamp;
{
+ enum GNUNET_GenericReturnValue res;
+
+ res = TALER_MHD_parse_json_data (connection,
+ hc->request_body,
+ spec);
+ if (GNUNET_OK != res)
+ {
+ return (GNUNET_NO == res)
+ ? MHD_YES
+ : MHD_NO;
+ }
+ }
+
+ {
enum GNUNET_DB_QueryStatus qs;
uint64_t order_serial;
struct GNUNET_TIME_Timestamp refund_deadline;
@@ -145,9 +159,34 @@ TMH_private_post_orders_ID_refund (const struct TMH_RequestHandler *rh,
&order_serial,
&paid,
NULL);
- if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
+ {
+ if (qs < 0)
+ {
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "lookup_contract_terms");
+ }
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_MERCHANT_GENERIC_ORDER_UNKNOWN,
+ hc->infix);
+ }
+ if (GNUNET_OK !=
+ TALER_JSON_contract_hash (contract_terms,
+ &h_contract))
+ {
+ GNUNET_break (0);
+ json_decref (contract_terms);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_FAILED_COMPUTE_JSON_HASH,
+ "Could not hash contract terms");
+ }
{
- struct GNUNET_JSON_Specification spec[] = {
+ struct GNUNET_JSON_Specification cspec[] = {
GNUNET_JSON_spec_timestamp ("refund_deadline",
&refund_deadline),
GNUNET_JSON_spec_timestamp ("timestamp",
@@ -157,11 +196,10 @@ TMH_private_post_orders_ID_refund (const struct TMH_RequestHandler *rh,
if (GNUNET_YES !=
GNUNET_JSON_parse (contract_terms,
- spec,
+ cspec,
NULL, NULL))
{
GNUNET_break (0);
- GNUNET_JSON_parse_free (spec);
json_decref (contract_terms);
return TALER_MHD_reply_with_error (
connection,
@@ -188,28 +226,6 @@ TMH_private_post_orders_ID_refund (const struct TMH_RequestHandler *rh,
wire the funds, so we will try to give the refund anyway */
}
}
- else
- {
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_NOT_FOUND,
- TALER_EC_MERCHANT_GENERIC_ORDER_UNKNOWN,
- hc->infix);
- }
- }
-
- {
- enum GNUNET_GenericReturnValue res;
-
- res = TALER_MHD_parse_json_data (connection,
- hc->request_body,
- spec);
- if (GNUNET_OK != res)
- {
- json_decref (contract_terms);
- return (GNUNET_NO == res)
- ? MHD_YES
- : MHD_NO;
- }
}
TMH_db->preflight (TMH_db->cls);
@@ -293,6 +309,14 @@ TMH_private_post_orders_ID_refund (const struct TMH_RequestHandler *rh,
switch (rs)
{
+ case TALER_MERCHANTDB_RS_BAD_CURRENCY:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Refund amount %s is not in the currency of the original payment\n",
+ TALER_amount2s (&refund));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_CONFLICT,
+ TALER_EC_MERCHANT_GENERIC_CURRENCY_MISMATCH,
+ "Order was paid in a different currency");
case TALER_MERCHANTDB_RS_TOO_HIGH:
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Refusing refund amount %s that is larger than original payment\n",
@@ -318,41 +342,9 @@ TMH_private_post_orders_ID_refund (const struct TMH_RequestHandler *rh,
TALER_EC_MERCHANT_PRIVATE_POST_ORDERS_ID_REFUND_ORDER_UNPAID,
hc->infix);
case TALER_MERCHANTDB_RS_SUCCESS:
- {
- enum GNUNET_DB_QueryStatus qs;
- json_t *contract_terms;
- uint64_t order_serial;
- bool paid;
-
- qs = TMH_db->lookup_contract_terms (TMH_db->cls,
- hc->instance->settings.id,
- hc->infix,
- &contract_terms,
- &order_serial,
- &paid,
- NULL);
- if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
- {
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_NOT_FOUND,
- TALER_EC_MERCHANT_GENERIC_ORDER_UNKNOWN,
- hc->infix);
- }
- if (GNUNET_OK !=
- TALER_JSON_contract_hash (contract_terms,
- &h_contract))
- {
- GNUNET_break (0);
- json_decref (contract_terms);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_FAILED_COMPUTE_JSON_HASH,
- "Could not hash contract terms");
- }
- json_decref (contract_terms);
- }
+ /* continued below */
break;
- }
+ } /* end switch */
{
struct GNUNET_TIME_Timestamp timestamp;