merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 07f3974c54b8bf4084ddc452cf1f10263c20050d
parent 2f6093eef65d4f0dded4ce5af40cb32eeff0a456
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date:   Mon, 21 May 2018 14:44:10 +0200

Increase refund on a unpaid contract.

Diffstat:
Msrc/lib/merchant_api_refund.c | 27++++++++++++++++++++-------
Msrc/lib/test_merchant_api_new.c | 34++++++++++++++++++++++++++++++++++
Msrc/lib/testing_api_cmd_refund.c | 2+-
3 files changed, 55 insertions(+), 8 deletions(-)

diff --git a/src/lib/merchant_api_refund.c b/src/lib/merchant_api_refund.c @@ -121,9 +121,13 @@ handle_refund_increase_finished (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Backend didn't even return from POST /refund\n"); return; + + /* Tolerate Bad Request here in order to let + * test cases move along. */ case MHD_HTTP_OK: + case MHD_HTTP_BAD_REQUEST: rio->cb (rio->cb_cls, - MHD_HTTP_OK, + response_code, TALER_EC_NONE, json); break; @@ -133,13 +137,22 @@ handle_refund_increase_finished (void *cls, * NOTE that json must be a Taler-specific error object (FIXME, * need a link to error objects at docs) */ - json_unpack ((json_t *) json, - "{s:s, s:I, s:s}", - "error", &error, - "code", &code, - "hint", &hint); + if (-1 == json_unpack + ((json_t *) json, + "{s:s, s:I, s:s}", + "error", &error, + "code", &code, + "hint", &hint)) + + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "/refund failed (HTTP code: %lu), backend did " + "not give a valid error object\n", response_code); + break; + } + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed POST /refund, error: %s, code: %d, hint: %s\n", + "/refund, error: %s, code: %d, hint: %s\n", error, code, hint); diff --git a/src/lib/test_merchant_api_new.c b/src/lib/test_merchant_api_new.c @@ -472,6 +472,40 @@ run (void *cls, "deposit-simple", "1"), + /* Test /refund on a contract that was never paid. */ + + TALER_TESTING_cmd_proposal + ("create-proposal-not-to-be-paid", + merchant_url, + is->ctx, + MHD_HTTP_OK, + "{\"max_fee\":\ + {\"currency\":\"EUR\",\ + \"value\":0,\ + \"fraction\":50000000},\ + \"order_id\":\"1-unpaid\",\ + \"refund_deadline\":\"\\/Date(0)\\/\",\ + \"pay_deadline\":\"\\/Date(99999999999)\\/\",\ + \"amount\":\ + {\"currency\":\"EUR\",\ + \"value\":5,\ + \"fraction\":0},\ + \"summary\": \"useful product\",\ + \"fulfillment_url\": \"https://example.com/\",\ + \"products\": [ {\"description\":\"ice cream\",\ + \"value\":\"{EUR:5}\"} ] }", + NULL), + + TALER_TESTING_cmd_refund_increase + ("refund-increase-unpaid-proposal", + merchant_url, + is->ctx, + "refund test", + "1-unpaid", + "EUR:0.1", + "EUR:0.01", + MHD_HTTP_BAD_REQUEST), + /* Test tipping. */ TALER_TESTING_cmd_fakebank_transfer_with_instance ("create-reserve-tip-1", diff --git a/src/lib/testing_api_cmd_refund.c b/src/lib/testing_api_cmd_refund.c @@ -129,7 +129,7 @@ refund_increase_cb (void *cls, struct RefundIncreaseState *ris = cls; ris->rio = NULL; - if (MHD_HTTP_OK != http_status) + if (ris->http_code != http_status) TALER_TESTING_FAIL (ris->is); TALER_TESTING_interpreter_next (ris->is);