merchant

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

commit 391f3714767b29f44f7e63c4848444f14f5b201f
parent f864b1d0c9976be36afc8f2bcad7df1d5498c7c6
Author: Florian Dold <florian.dold@gmail.com>
Date:   Fri,  5 Jan 2018 16:10:59 +0100

implement /trigger-pay

Diffstat:
Msrc/backend/taler-merchant-httpd.c | 4++++
Msrc/backend/taler-merchant-httpd_check-payment.c | 22+++++++++++++++++++++-
Msrc/backend/taler-merchant-httpd_trigger-pay.c | 41++++++++++++++++++++++++++++++++++++++++-
3 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c @@ -46,6 +46,7 @@ #include "taler-merchant-httpd_history.h" #include "taler-merchant-httpd_refund.h" #include "taler-merchant-httpd_check-payment.h" +#include "taler-merchant-httpd_trigger-pay.h" /** * Backlog for listen operation on unix-domain sockets. @@ -256,6 +257,9 @@ url_handler (void *cls, { "/check-payment", MHD_HTTP_METHOD_GET, "text/plain", NULL, 0, &MH_handler_check_payment, MHD_HTTP_OK}, + { "/trigger-pay", MHD_HTTP_METHOD_GET, "text/plain", + NULL, 0, + &MH_handler_trigger_pay, MHD_HTTP_OK}, {NULL, NULL, NULL, NULL, 0, 0 } }; static struct TMH_RequestHandler h404 = diff --git a/src/backend/taler-merchant-httpd_check-payment.c b/src/backend/taler-merchant-httpd_check-payment.c @@ -146,6 +146,7 @@ MH_handler_check_payment (struct TMH_RequestHandler *rh, const char *session_id; const char *session_sig_str; const char *instance_str; + const char *confirm_url; order_id = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, @@ -153,6 +154,9 @@ MH_handler_check_payment (struct TMH_RequestHandler *rh, contract_url = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "contract_url"); + confirm_url = MHD_lookup_connection_value (connection, + MHD_GET_ARGUMENT_KIND, + "confirm_url"); session_id = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "session_id"); @@ -166,6 +170,9 @@ MH_handler_check_payment (struct TMH_RequestHandler *rh, if (NULL == instance_str) instance_str = "default"; + // Will only be set if we actually have a contract! + char *h_contract_terms_str = NULL; + struct MerchantInstance *mi = TMH_lookup_instance (instance_str); if (NULL == mi) return TMH_RESPONSE_reply_bad_request (connection, @@ -259,6 +266,10 @@ MH_handler_check_payment (struct TMH_RequestHandler *rh, "Failed to hash proposal"); } + h_contract_terms_str = GNUNET_STRINGS_data_to_string_alloc (&h_contract_terms, + sizeof (struct GNUNET_HashCode)); + + /* Check if transaction is already known, if not store it. */ { struct GNUNET_HashCode h_xwire; @@ -277,6 +288,7 @@ MH_handler_check_payment (struct TMH_RequestHandler *rh, { /* Always report on hard error as well to enable diagnostics */ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + GNUNET_free_non_null (h_contract_terms_str); return TMH_RESPONSE_reply_internal_error (connection, TALER_EC_PAY_DB_FETCH_TRANSACTION_ERROR, "Merchant database error"); @@ -289,6 +301,8 @@ MH_handler_check_payment (struct TMH_RequestHandler *rh, GNUNET_break (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs); } + GNUNET_free_non_null (h_contract_terms_str); + return TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_OK, "{s:b}", @@ -297,12 +311,18 @@ MH_handler_check_payment (struct TMH_RequestHandler *rh, do_pay: { - char *url = make_absolute_backend_url (connection, "trigger-pay", "contract_url", contract_url, "session_id", session_id, NULL); + char *url = make_absolute_backend_url (connection, "trigger-pay", + "contract_url", contract_url, + "session_id", session_id, + "h_contract_terms", h_contract_terms_str, + "confirm_url", confirm_url, + NULL); int ret = TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_OK, "{s:s}", "payment_redirect_url", url); + GNUNET_free_non_null (h_contract_terms_str); GNUNET_free (url); return ret; } diff --git a/src/backend/taler-merchant-httpd_trigger-pay.c b/src/backend/taler-merchant-httpd_trigger-pay.c @@ -51,5 +51,44 @@ MH_handler_trigger_pay (struct TMH_RequestHandler *rh, const char *upload_data, size_t *upload_data_size) { - return 0; + struct MHD_Response *response; + + const char *contract_url; + const char *h_contract_terms_str; + const char *confirm_url; + const char *session_id; + + session_id = MHD_lookup_connection_value (connection, + MHD_GET_ARGUMENT_KIND, + "session_id"); + + confirm_url = MHD_lookup_connection_value (connection, + MHD_GET_ARGUMENT_KIND, + "confirm_url"); + + contract_url = MHD_lookup_connection_value (connection, + MHD_GET_ARGUMENT_KIND, + "contract_url"); + + h_contract_terms_str = MHD_lookup_connection_value (connection, + MHD_GET_ARGUMENT_KIND, + "h_contract_terms"); + + + // FIXME: Taler wallet detection! + char *data = "<html><body><p>Processing payment ...</p></body></html>"; + + response = MHD_create_response_from_buffer (strlen (data), data, MHD_RESPMEM_PERSISTENT); + if (NULL != session_id) + MHD_add_response_header (response, "X-Taler-Session-Id", session_id); + if (NULL != contract_url) + MHD_add_response_header (response, "X-Taler-Contract-Url", contract_url); + if (NULL != h_contract_terms_str) + MHD_add_response_header (response, "X-Taler-Contract-Hash", h_contract_terms_str); + if (NULL != confirm_url) + MHD_add_response_header (response, "X-Taler-Confirm-Url", confirm_url); + MHD_queue_response (connection, 402, response); + MHD_destroy_response (response); + + return MHD_YES; }