diff options
Diffstat (limited to 'src/lib/merchant_api_wallet_get_order.c')
-rw-r--r-- | src/lib/merchant_api_wallet_get_order.c | 95 |
1 files changed, 35 insertions, 60 deletions
diff --git a/src/lib/merchant_api_wallet_get_order.c b/src/lib/merchant_api_wallet_get_order.c index 4037ea57..9c24204a 100644 --- a/src/lib/merchant_api_wallet_get_order.c +++ b/src/lib/merchant_api_wallet_get_order.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2018, 2020 Taler Systems SA + Copyright (C) 2018, 2020, 2022 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software @@ -79,19 +79,13 @@ cb_failure (struct TALER_MERCHANT_OrderWalletGetHandle *owgh, enum TALER_ErrorCode ec, const json_t *reply) { - struct TALER_MERCHANT_HttpResponse hr = { - .ec = ec, - .reply = reply + struct TALER_MERCHANT_OrderWalletGetResponse owgr = { + .hr.ec = ec, + .hr.reply = reply }; owgh->cb (owgh->cb_cls, - &hr, - GNUNET_SYSERR, - GNUNET_SYSERR, - GNUNET_SYSERR, - NULL, - NULL, - NULL); + &owgr); } @@ -115,22 +109,19 @@ handle_wallet_get_order_finished (void *cls, { case MHD_HTTP_OK: { - struct TALER_Amount refund_amount; - bool refunded; - bool refund_pending; + struct TALER_MERCHANT_OrderWalletGetResponse owgr = { + .hr.reply = json, + .hr.http_status = MHD_HTTP_OK + }; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_bool ("refunded", - &refunded), + &owgr.details.success.refunded), GNUNET_JSON_spec_bool ("refund_pending", - &refund_pending), + &owgr.details.success.refund_pending), TALER_JSON_spec_amount_any ("refund_amount", - &refund_amount), + &owgr.details.success.refund_amount), GNUNET_JSON_spec_end () }; - struct TALER_MERCHANT_HttpResponse hr = { - .reply = json, - .http_status = MHD_HTTP_OK - }; if (GNUNET_OK != GNUNET_JSON_parse (json, @@ -144,70 +135,54 @@ handle_wallet_get_order_finished (void *cls, TALER_MERCHANT_wallet_order_get_cancel (owgh); return; } - owgh->cb (owgh->cb_cls, - &hr, - GNUNET_YES, - refunded ? GNUNET_YES : GNUNET_NO, - refund_pending ? GNUNET_YES : GNUNET_NO, - refunded ? &refund_amount : NULL, - NULL, /* paid! */ - NULL);/* paid! */ + &owgr); GNUNET_JSON_parse_free (spec); break; } case MHD_HTTP_PAYMENT_REQUIRED: { + struct TALER_MERCHANT_OrderWalletGetResponse owgr = { + .hr.reply = json, + .hr.http_status = MHD_HTTP_PAYMENT_REQUIRED + }; + /* Status is: unpaid */ - const char *taler_pay_uri = json_string_value (json_object_get (json, - "taler_pay_uri")); - const char *already_paid = json_string_value (json_object_get (json, - "already_paid_order_id")); - if (NULL == taler_pay_uri) + owgr.details.payment_required.taler_pay_uri + = json_string_value (json_object_get (json, + "taler_pay_uri")); + owgr.details.payment_required.already_paid_order_id + = json_string_value (json_object_get (json, + "already_paid_order_id")); + if (NULL == owgr.details.payment_required.taler_pay_uri) { GNUNET_break_op (0); cb_failure (owgh, TALER_EC_GENERIC_REPLY_MALFORMED, json); + break; } - else - { - struct TALER_MERCHANT_HttpResponse hr = { - .reply = json, - .http_status = MHD_HTTP_OK - }; - - owgh->cb (owgh->cb_cls, - &hr, - GNUNET_NO, - GNUNET_NO, - GNUNET_NO, - NULL, - taler_pay_uri, - already_paid); - } + owgh->cb (owgh->cb_cls, + &owgr); break; } default: { - struct TALER_MERCHANT_HttpResponse hr; + struct TALER_MERCHANT_OrderWalletGetResponse owgr = { + .hr.reply = json, + .hr.http_status = response_code + }; TALER_MERCHANT_parse_error_details_ (response, response_code, - &hr); + &owgr.hr); GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Checking order status failed with HTTP status code %u/%d\n", (unsigned int) response_code, - (int) hr.ec); + (int) owgr.hr.ec); GNUNET_break_op (0); owgh->cb (owgh->cb_cls, - &hr, - GNUNET_SYSERR, - GNUNET_SYSERR, - GNUNET_SYSERR, - NULL, - NULL, - NULL); + &owgr); break; } } |