merchant

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

commit 22b8ebf3c035be0f741fd25dea9bbef7bb5b785c
parent 4525219b2a67aea4706a08ef6c65bbf51a01ab4e
Author: Christian Grothoff <christian@grothoff.org>
Date:   Mon, 30 Oct 2017 15:37:09 +0100

implement OC_TIP_AUTHORIZE

Diffstat:
Msrc/lib/test_merchant_api.c | 85++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 84 insertions(+), 1 deletion(-)

diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c @@ -21,7 +21,6 @@ * * TODO: * - implement getting reserve_priv from configuration in /admin/add/incoming - * - implement tip_authorize * - implement tip_pickup * - implement spending with coins from tips * - add test logic for tips to main test interpreter @@ -774,6 +773,11 @@ struct Command struct GNUNET_HashCode tip_id; /** + * When does the authorization expire? + */ + struct GNUNET_TIME_Absolute tip_expiration; + + /** * EC expected for the operation. */ enum TALER_ErrorCode expected_ec; @@ -1765,6 +1769,64 @@ tip_enable_cb (void *cls, /** + * Callback for a /tip-authorize request. Returns the result of + * the operation. + * + * @param cls closure + * @param http_status HTTP status returned by the merchant backend + * @param ec taler-specific error code + */ +static void +tip_authorize_cb (void *cls, + unsigned int http_status, + enum TALER_ErrorCode ec, + const struct GNUNET_HashCode *tip_id, + struct GNUNET_TIME_Absolute tip_expiration, + const char *exchange_uri) +{ + struct InterpreterState *is = cls; + struct Command *cmd = &is->commands[is->ip]; + + cmd->details.tip_authorize.tao = NULL; + if (cmd->expected_response_code != http_status) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unexpected response code %u to command %s\n", + http_status, + cmd->label); + fail (is); + return; + } + if (cmd->details.tip_authorize.expected_ec != ec) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unexpected error code %u to command %s\n", + ec, + cmd->label); + fail (is); + return; + } + if ( (MHD_HTTP_OK == http_status) && + (TALER_EC_NONE == ec) ) + { + if (0 != strcmp (exchange_uri, + EXCHANGE_URI)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unexpected exchange URI %s to command %s\n", + exchange_uri, + cmd->label); + fail (is); + return; + } + cmd->details.tip_authorize.tip_id = *tip_id; + cmd->details.tip_authorize.tip_expiration = tip_expiration; + } + next_command (is); +} + + +/** * Find denomination key matching the given amount. * * @param keys array of keys to search @@ -2592,6 +2654,27 @@ interpreter_run (void *cls) } break; } + case OC_TIP_AUTHORIZE: + { + GNUNET_assert (NULL != cmd->details.tip_authorize.amount); + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount (cmd->details.tip_authorize.amount, + &amount)); + if (NULL == (cmd->details.tip_authorize.tao + = TALER_MERCHANT_tip_authorize + (ctx, + MERCHANT_URI, + &amount, + cmd->details.tip_authorize.instance, + cmd->details.tip_authorize.justification, + &tip_authorize_cb, + is))) + { + GNUNET_break (0); + fail (is); + } + break; + } default: GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unknown instruction %d at %u (%s)\n",