diff options
Diffstat (limited to 'src/exchange/taler-exchange-httpd_refund.c')
-rw-r--r-- | src/exchange/taler-exchange-httpd_refund.c | 99 |
1 files changed, 23 insertions, 76 deletions
diff --git a/src/exchange/taler-exchange-httpd_refund.c b/src/exchange/taler-exchange-httpd_refund.c index 7c2b149f2..a6a2c3d6f 100644 --- a/src/exchange/taler-exchange-httpd_refund.c +++ b/src/exchange/taler-exchange-httpd_refund.c | |||
@@ -73,12 +73,13 @@ reply_refund_success (struct MHD_Connection *connection, | |||
73 | TALER_EC_EXCHANGE_BAD_CONFIGURATION, | 73 | TALER_EC_EXCHANGE_BAD_CONFIGURATION, |
74 | "no online signing key"); | 74 | "no online signing key"); |
75 | } | 75 | } |
76 | return TALER_MHD_reply_json_pack (connection, | 76 | return TALER_MHD_reply_json_pack ( |
77 | MHD_HTTP_OK, | 77 | connection, |
78 | "{s:s, s:o, s:o}", | 78 | MHD_HTTP_OK, |
79 | "status", "REFUND_OK", | 79 | "{s:o, s:o, s:o}", |
80 | "sig", GNUNET_JSON_from_data_auto (&sig), | 80 | "refund_fee", TALER_JSON_from_amount (&refund->refund_fee), |
81 | "pub", GNUNET_JSON_from_data_auto (&pub)); | 81 | "exchange_sig", GNUNET_JSON_from_data_auto (&sig), |
82 | "exchange_pub", GNUNET_JSON_from_data_auto (&pub)); | ||
82 | } | 83 | } |
83 | 84 | ||
84 | 85 | ||
@@ -246,18 +247,15 @@ refund_transaction (void *cls, | |||
246 | } | 247 | } |
247 | 248 | ||
248 | /* check currency is compatible */ | 249 | /* check currency is compatible */ |
249 | if ( (GNUNET_YES != | 250 | if (GNUNET_YES != |
250 | TALER_amount_cmp_currency (&refund->details.refund_amount, | 251 | TALER_amount_cmp_currency (&refund->details.refund_amount, |
251 | &dep->amount_with_fee)) || | 252 | &dep->amount_with_fee)) |
252 | (GNUNET_YES != | ||
253 | TALER_amount_cmp_currency (&refund->details.refund_fee, | ||
254 | &dep->deposit_fee)) ) | ||
255 | { | 253 | { |
256 | GNUNET_break_op (0); /* currency mismatch */ | 254 | GNUNET_break_op (0); /* currency mismatch */ |
257 | TEH_plugin->free_coin_transaction_list (TEH_plugin->cls, | 255 | TEH_plugin->free_coin_transaction_list (TEH_plugin->cls, |
258 | tl); | 256 | tl); |
259 | *mhd_ret = TALER_MHD_reply_with_error (connection, | 257 | *mhd_ret = TALER_MHD_reply_with_error (connection, |
260 | MHD_HTTP_PRECONDITION_FAILED, | 258 | MHD_HTTP_BAD_REQUEST, |
261 | TALER_EC_REFUND_CURRENCY_MISMATCH, | 259 | TALER_EC_REFUND_CURRENCY_MISMATCH, |
262 | "currencies involved do not match"); | 260 | "currencies involved do not match"); |
263 | return GNUNET_DB_STATUS_HARD_ERROR; | 261 | return GNUNET_DB_STATUS_HARD_ERROR; |
@@ -339,15 +337,14 @@ refund_transaction (void *cls, | |||
339 | * the fee structure, so this is not done here. | 337 | * the fee structure, so this is not done here. |
340 | * | 338 | * |
341 | * @param connection the MHD connection to handle | 339 | * @param connection the MHD connection to handle |
342 | * @param refund information about the refund | 340 | * @param[in,out] refund information about the refund |
343 | * @return MHD result code | 341 | * @return MHD result code |
344 | */ | 342 | */ |
345 | static MHD_RESULT | 343 | static MHD_RESULT |
346 | verify_and_execute_refund (struct MHD_Connection *connection, | 344 | verify_and_execute_refund (struct MHD_Connection *connection, |
347 | const struct TALER_EXCHANGEDB_Refund *refund) | 345 | struct TALER_EXCHANGEDB_Refund *refund) |
348 | { | 346 | { |
349 | struct GNUNET_HashCode denom_hash; | 347 | struct GNUNET_HashCode denom_hash; |
350 | struct TALER_Amount expect_fee; | ||
351 | 348 | ||
352 | { | 349 | { |
353 | struct TALER_RefundRequestPS rr = { | 350 | struct TALER_RefundRequestPS rr = { |
@@ -361,8 +358,6 @@ verify_and_execute_refund (struct MHD_Connection *connection, | |||
361 | 358 | ||
362 | TALER_amount_hton (&rr.refund_amount, | 359 | TALER_amount_hton (&rr.refund_amount, |
363 | &refund->details.refund_amount); | 360 | &refund->details.refund_amount); |
364 | TALER_amount_hton (&rr.refund_fee, | ||
365 | &refund->details.refund_fee); | ||
366 | if (GNUNET_OK != | 361 | if (GNUNET_OK != |
367 | GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MERCHANT_REFUND, | 362 | GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MERCHANT_REFUND, |
368 | &rr, | 363 | &rr, |
@@ -429,43 +424,12 @@ verify_and_execute_refund (struct MHD_Connection *connection, | |||
429 | ec, | 424 | ec, |
430 | "denomination not found, but coin known"); | 425 | "denomination not found, but coin known"); |
431 | } | 426 | } |
432 | TALER_amount_ntoh (&expect_fee, | 427 | TALER_amount_ntoh (&refund->details.refund_fee, |
433 | &dki->issue.properties.fee_refund); | 428 | &dki->issue.properties.fee_refund); |
434 | } | 429 | } |
435 | TEH_KS_release (key_state); | 430 | TEH_KS_release (key_state); |
436 | } | 431 | } |
437 | 432 | ||
438 | /* Check refund fee matches fee of denomination key! */ | ||
439 | if (GNUNET_YES != | ||
440 | TALER_amount_cmp_currency (&expect_fee, | ||
441 | &refund->details.refund_fee) ) | ||
442 | { | ||
443 | GNUNET_break_op (0); | ||
444 | return TALER_MHD_reply_with_error (connection, | ||
445 | MHD_HTTP_BAD_REQUEST, | ||
446 | TALER_EC_REFUND_FEE_CURRENCY_MISMATCH, | ||
447 | "refund_fee"); | ||
448 | } | ||
449 | { | ||
450 | int fee_cmp; | ||
451 | |||
452 | fee_cmp = TALER_amount_cmp (&refund->details.refund_fee, | ||
453 | &expect_fee); | ||
454 | if (-1 == fee_cmp) | ||
455 | { | ||
456 | return TALER_MHD_reply_with_error (connection, | ||
457 | MHD_HTTP_BAD_REQUEST, | ||
458 | TALER_EC_REFUND_FEE_TOO_LOW, | ||
459 | "refund_fee"); | ||
460 | } | ||
461 | if (1 == fee_cmp) | ||
462 | { | ||
463 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
464 | "Refund fee proposed by merchant is higher than necessary.\n"); | ||
465 | } | ||
466 | } | ||
467 | |||
468 | |||
469 | /* Finally run the actual transaction logic */ | 433 | /* Finally run the actual transaction logic */ |
470 | { | 434 | { |
471 | MHD_RESULT mhd_ret; | 435 | MHD_RESULT mhd_ret; |
@@ -502,16 +466,20 @@ TEH_handler_refund (struct MHD_Connection *connection, | |||
502 | const struct TALER_CoinSpendPublicKeyP *coin_pub, | 466 | const struct TALER_CoinSpendPublicKeyP *coin_pub, |
503 | const json_t *root) | 467 | const json_t *root) |
504 | { | 468 | { |
505 | struct TALER_EXCHANGEDB_Refund refund; | 469 | struct TALER_EXCHANGEDB_Refund refund = { |
470 | .details.refund_fee.currency = {0} /* set to invalid, just to be sure */ | ||
471 | }; | ||
506 | struct GNUNET_JSON_Specification spec[] = { | 472 | struct GNUNET_JSON_Specification spec[] = { |
507 | TALER_JSON_spec_amount ("refund_amount", &refund.details.refund_amount), | 473 | TALER_JSON_spec_amount ("refund_amount", |
508 | TALER_JSON_spec_amount ("refund_fee", &refund.details.refund_fee), | 474 | &refund.details.refund_amount), |
509 | GNUNET_JSON_spec_fixed_auto ("h_contract_terms", | 475 | GNUNET_JSON_spec_fixed_auto ("h_contract_terms", |
510 | &refund.details.h_contract_terms), | 476 | &refund.details.h_contract_terms), |
511 | GNUNET_JSON_spec_fixed_auto ("merchant_pub", &refund.details.merchant_pub), | 477 | GNUNET_JSON_spec_fixed_auto ("merchant_pub", |
478 | &refund.details.merchant_pub), | ||
512 | GNUNET_JSON_spec_uint64 ("rtransaction_id", | 479 | GNUNET_JSON_spec_uint64 ("rtransaction_id", |
513 | &refund.details.rtransaction_id), | 480 | &refund.details.rtransaction_id), |
514 | GNUNET_JSON_spec_fixed_auto ("merchant_sig", &refund.details.merchant_sig), | 481 | GNUNET_JSON_spec_fixed_auto ("merchant_sig", |
482 | &refund.details.merchant_sig), | ||
515 | GNUNET_JSON_spec_end () | 483 | GNUNET_JSON_spec_end () |
516 | }; | 484 | }; |
517 | 485 | ||
@@ -527,27 +495,6 @@ TEH_handler_refund (struct MHD_Connection *connection, | |||
527 | if (GNUNET_NO == res) | 495 | if (GNUNET_NO == res) |
528 | return MHD_YES; /* failure */ | 496 | return MHD_YES; /* failure */ |
529 | } | 497 | } |
530 | if (GNUNET_YES != | ||
531 | TALER_amount_cmp_currency (&refund.details.refund_amount, | ||
532 | &refund.details.refund_fee) ) | ||
533 | { | ||
534 | GNUNET_break_op (0); | ||
535 | GNUNET_JSON_parse_free (spec); | ||
536 | return TALER_MHD_reply_with_error (connection, | ||
537 | MHD_HTTP_BAD_REQUEST, | ||
538 | TALER_EC_REFUND_FEE_CURRENCY_MISMATCH, | ||
539 | "refund_amount or refund_fee"); | ||
540 | } | ||
541 | if (-1 == TALER_amount_cmp (&refund.details.refund_amount, | ||
542 | &refund.details.refund_fee) ) | ||
543 | { | ||
544 | GNUNET_break_op (0); | ||
545 | GNUNET_JSON_parse_free (spec); | ||
546 | return TALER_MHD_reply_with_error (connection, | ||
547 | MHD_HTTP_BAD_REQUEST, | ||
548 | TALER_EC_REFUND_FEE_ABOVE_AMOUNT, | ||
549 | "refund_amount"); | ||
550 | } | ||
551 | { | 498 | { |
552 | MHD_RESULT res; | 499 | MHD_RESULT res; |
553 | 500 | ||