diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-07-26 13:24:13 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-07-26 13:24:13 +0200 |
commit | 7d2465146e6dd1f50d6a8f5121edfa667f1cae84 (patch) | |
tree | ed1c774cfbcdac77546525c0a6bb30270896bc73 /src | |
parent | 602f5e3e0824d9c2c9dd1fab29342ecbce3b78da (diff) | |
download | merchant-7d2465146e6dd1f50d6a8f5121edfa667f1cae84.tar.gz merchant-7d2465146e6dd1f50d6a8f5121edfa667f1cae84.tar.bz2 merchant-7d2465146e6dd1f50d6a8f5121edfa667f1cae84.zip |
return 402 status code instead of 'unpaid' order status
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/taler-merchant-httpd_get-orders-ID.c | 10 | ||||
-rw-r--r-- | src/lib/merchant_api_wallet_get_order.c | 462 |
2 files changed, 212 insertions, 260 deletions
diff --git a/src/backend/taler-merchant-httpd_get-orders-ID.c b/src/backend/taler-merchant-httpd_get-orders-ID.c index 7310483d..5966f02b 100644 --- a/src/backend/taler-merchant-httpd_get-orders-ID.c +++ b/src/backend/taler-merchant-httpd_get-orders-ID.c @@ -487,17 +487,16 @@ send_pay_request (struct GetOrderData *god, MHD_HTTP_HEADER_CONTENT_TYPE, "text/html")); ret = MHD_queue_response (god->sc.con, - MHD_HTTP_OK, + MHD_HTTP_PAYMENT_REQUIRED, reply); MHD_destroy_response (reply); } else { ret = TALER_MHD_reply_json_pack (god->sc.con, - MHD_HTTP_OK, - "{s:s, s:s, s:s?}", + MHD_HTTP_PAYMENT_REQUIRED, + "{s:s, s:s?}", "taler_pay_uri", taler_pay_uri, - "order_status", "unpaid", "already_paid_order_id", already_paid_order_id); } @@ -1259,8 +1258,7 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh, return TALER_MHD_reply_json_pack ( connection, MHD_HTTP_OK, - "{s:s, s:b, s:o, s:o, s:o}", - "order_status", "paid", + "{s:b, s:o, s:o, s:o}", "refunded", god->refunded, "refund_amount", TALER_JSON_from_amount (&god->refund_amount), diff --git a/src/lib/merchant_api_wallet_get_order.c b/src/lib/merchant_api_wallet_get_order.c index 7b7c86e6..7f6b1edb 100644 --- a/src/lib/merchant_api_wallet_get_order.c +++ b/src/lib/merchant_api_wallet_get_order.c @@ -110,282 +110,212 @@ handle_wallet_get_order_finished (void *cls, { struct TALER_MERCHANT_OrderWalletGetHandle *owgh = cls; const json_t *json = response; - const char *order_status; owgh->job = NULL; - if (MHD_HTTP_OK != response_code) + switch (response_code) { - struct TALER_MERCHANT_HttpResponse hr; - - TALER_MERCHANT_parse_error_details_ (response, - response_code, - &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); - GNUNET_break_op (0); - owgh->cb (owgh->cb_cls, - &hr, - GNUNET_SYSERR, - GNUNET_SYSERR, - NULL, - NULL, - NULL, - NULL, - 0, - NULL); - TALER_MERCHANT_wallet_order_get_cancel (owgh); - return; - } - - order_status = json_string_value (json_object_get (json, "order_status")); - - if (NULL == order_status) - { - struct TALER_MERCHANT_HttpResponse hr = { - .reply = json, - .http_status = 0, - .ec = TALER_EC_MERCHANT_ORDER_GET_REPLY_MALFORMED, - }; - GNUNET_break_op (0); - owgh->cb (owgh->cb_cls, - &hr, - GNUNET_SYSERR, - GNUNET_SYSERR, - NULL, - NULL, - NULL, - NULL, - 0, - NULL); - TALER_MERCHANT_wallet_order_get_cancel (owgh); - return; - } - - if (0 == strcmp (order_status, "unpaid")) - { - /* 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) + case MHD_HTTP_OK: { - GNUNET_break_op (0); - cb_failure (owgh, - TALER_EC_CHECK_PAYMENT_RESPONSE_MALFORMED, - json); - } - else - { - struct TALER_MERCHANT_HttpResponse hr = { - .reply = json, - .http_status = MHD_HTTP_OK + struct TALER_Amount refund_amount; + json_t *refunds; + bool refunded; + struct TALER_MerchantPublicKeyP merchant_pub; + unsigned int refund_len; + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_bool ("refunded", + &refunded), + GNUNET_JSON_spec_fixed_auto ("merchant_pub", + &merchant_pub), + TALER_JSON_spec_amount ("refund_amount", + &refund_amount), + GNUNET_JSON_spec_json ("refunds", + &refunds), + GNUNET_JSON_spec_end () }; - owgh->cb (owgh->cb_cls, - &hr, - GNUNET_NO, - GNUNET_NO, - NULL, - taler_pay_uri, - already_paid, - NULL, - 0, - NULL); - } - TALER_MERCHANT_wallet_order_get_cancel (owgh); - return; - } - - if (0 != strcmp (order_status, "paid")) - { - struct TALER_MERCHANT_HttpResponse hr = { - .reply = json, - .http_status = 0, - .ec = TALER_EC_MERCHANT_ORDER_GET_REPLY_MALFORMED, - }; - GNUNET_break_op (0); - owgh->cb (owgh->cb_cls, - &hr, - GNUNET_SYSERR, - GNUNET_SYSERR, - NULL, - NULL, - NULL, - NULL, - 0, - NULL); - TALER_MERCHANT_wallet_order_get_cancel (owgh); - return; - } - - { - struct TALER_Amount refund_amount; - json_t *refunds; - bool refunded; - struct TALER_MerchantPublicKeyP merchant_pub; - unsigned int refund_len; - struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_bool ("refunded", - &refunded), - GNUNET_JSON_spec_fixed_auto ("merchant_pub", - &merchant_pub), - TALER_JSON_spec_amount ("refund_amount", - &refund_amount), - GNUNET_JSON_spec_json ("refunds", - &refunds), - GNUNET_JSON_spec_end () - }; - - if (GNUNET_OK != - GNUNET_JSON_parse (json, - spec, - NULL, NULL)) - { - GNUNET_break_op (0); - cb_failure (owgh, - TALER_EC_CHECK_PAYMENT_RESPONSE_MALFORMED, - json); - TALER_MERCHANT_wallet_order_get_cancel (owgh); - return; - } - - if (! json_is_array (refunds)) - { - GNUNET_break_op (0); - cb_failure (owgh, - TALER_EC_CHECK_PAYMENT_RESPONSE_MALFORMED, - json); - GNUNET_JSON_parse_free (spec); - TALER_MERCHANT_wallet_order_get_cancel (owgh); - return; - } - - refund_len = json_array_size (refunds); - { - struct TALER_MERCHANT_RefundDetail rds[refund_len]; + if (GNUNET_OK != + GNUNET_JSON_parse (json, + spec, + NULL, NULL)) + { + GNUNET_break_op (0); + cb_failure (owgh, + TALER_EC_CHECK_PAYMENT_RESPONSE_MALFORMED, + json); + TALER_MERCHANT_wallet_order_get_cancel (owgh); + return; + } - memset (rds, - 0, - sizeof (rds)); - for (unsigned int i = 0; i<refund_len; i++) + if (! json_is_array (refunds)) { - struct TALER_MERCHANT_RefundDetail *rd = &rds[i]; - const json_t *jrefund = json_array_get (refunds, - i); - const char *refund_status_type; - uint32_t exchange_status; - int ret; - struct GNUNET_JSON_Specification espec[] = { - GNUNET_JSON_spec_uint32 ("exchange_status", - &exchange_status), - GNUNET_JSON_spec_end () - }; + GNUNET_break_op (0); + cb_failure (owgh, + TALER_EC_CHECK_PAYMENT_RESPONSE_MALFORMED, + json); + GNUNET_JSON_parse_free (spec); + TALER_MERCHANT_wallet_order_get_cancel (owgh); + return; + } - if (GNUNET_OK != - GNUNET_JSON_parse (jrefund, - espec, - NULL, NULL)) - { - GNUNET_break_op (0); - cb_failure (owgh, - TALER_EC_CHECK_PAYMENT_RESPONSE_MALFORMED, - json); - TALER_MERCHANT_wallet_order_get_cancel (owgh); - return; - } + refund_len = json_array_size (refunds); + { + struct TALER_MERCHANT_RefundDetail rds[refund_len]; - if (MHD_HTTP_OK == exchange_status) + memset (rds, + 0, + sizeof (rds)); + for (unsigned int i = 0; i<refund_len; i++) { - struct GNUNET_JSON_Specification rspec[] = { - GNUNET_JSON_spec_string ("type", - &refund_status_type), - GNUNET_JSON_spec_fixed_auto ("exchange_sig", - &rd->exchange_sig), - GNUNET_JSON_spec_fixed_auto ("exchange_pub", - &rd->exchange_pub), - GNUNET_JSON_spec_uint64 ("rtransaction_id", - &rd->rtransaction_id), - GNUNET_JSON_spec_fixed_auto ("coin_pub", - &rd->coin_pub), - TALER_JSON_spec_amount ("refund_amount", - &rd->refund_amount), + struct TALER_MERCHANT_RefundDetail *rd = &rds[i]; + const json_t *jrefund = json_array_get (refunds, + i); + const char *refund_status_type; + uint32_t exchange_status; + int ret; + struct GNUNET_JSON_Specification espec[] = { + GNUNET_JSON_spec_uint32 ("exchange_status", + &exchange_status), GNUNET_JSON_spec_end () }; - ret = GNUNET_JSON_parse (jrefund, - rspec, - NULL, NULL); - if (GNUNET_OK == ret) + if (GNUNET_OK != + GNUNET_JSON_parse (jrefund, + espec, + NULL, NULL)) { - /* check that type field is correct */ - if (0 != strcmp ("success", refund_status_type)) - { - GNUNET_break_op (0); - ret = GNUNET_SYSERR; - } + GNUNET_break_op (0); + cb_failure (owgh, + TALER_EC_CHECK_PAYMENT_RESPONSE_MALFORMED, + json); + TALER_MERCHANT_wallet_order_get_cancel (owgh); + return; } - } - else - { - struct GNUNET_JSON_Specification rspec[] = { - GNUNET_JSON_spec_string ("type", - &refund_status_type), - GNUNET_JSON_spec_fixed_auto ("coin_pub", - &rd->coin_pub), - GNUNET_JSON_spec_uint64 ("rtransaction_id", - &rd->rtransaction_id), - TALER_JSON_spec_amount ("refund_amount", - &rd->refund_amount), - GNUNET_JSON_spec_end () - }; - ret = GNUNET_JSON_parse (jrefund, - rspec, - NULL, NULL); - if (GNUNET_OK == ret) + if (MHD_HTTP_OK == exchange_status) { - /* parse optional arguments */ - json_t *jec; - - jec = json_object_get (jrefund, - "exchange_code"); - if (NULL != jec) + struct GNUNET_JSON_Specification rspec[] = { + GNUNET_JSON_spec_string ("type", + &refund_status_type), + GNUNET_JSON_spec_fixed_auto ("exchange_sig", + &rd->exchange_sig), + GNUNET_JSON_spec_fixed_auto ("exchange_pub", + &rd->exchange_pub), + GNUNET_JSON_spec_uint64 ("rtransaction_id", + &rd->rtransaction_id), + GNUNET_JSON_spec_fixed_auto ("coin_pub", + &rd->coin_pub), + TALER_JSON_spec_amount ("refund_amount", + &rd->refund_amount), + GNUNET_JSON_spec_end () + }; + + ret = GNUNET_JSON_parse (jrefund, + rspec, + NULL, NULL); + if (GNUNET_OK == ret) { - if (! json_is_integer (jec)) + /* check that type field is correct */ + if (0 != strcmp ("success", refund_status_type)) { GNUNET_break_op (0); ret = GNUNET_SYSERR; } - else - { - rd->hr.ec = (enum TALER_ErrorCode) json_integer_value (jec); - } } - rd->hr.reply = json_object_get (jrefund, - "exchange_reply"); - /* check that type field is correct */ - if (0 != strcmp ("failure", refund_status_type)) + } + else + { + struct GNUNET_JSON_Specification rspec[] = { + GNUNET_JSON_spec_string ("type", + &refund_status_type), + GNUNET_JSON_spec_fixed_auto ("coin_pub", + &rd->coin_pub), + GNUNET_JSON_spec_uint64 ("rtransaction_id", + &rd->rtransaction_id), + TALER_JSON_spec_amount ("refund_amount", + &rd->refund_amount), + GNUNET_JSON_spec_end () + }; + + ret = GNUNET_JSON_parse (jrefund, + rspec, + NULL, NULL); + if (GNUNET_OK == ret) { - GNUNET_break_op (0); - ret = GNUNET_SYSERR; + /* parse optional arguments */ + json_t *jec; + + jec = json_object_get (jrefund, + "exchange_code"); + if (NULL != jec) + { + if (! json_is_integer (jec)) + { + GNUNET_break_op (0); + ret = GNUNET_SYSERR; + } + else + { + rd->hr.ec = (enum TALER_ErrorCode) json_integer_value (jec); + } + } + rd->hr.reply = json_object_get (jrefund, + "exchange_reply"); + /* check that type field is correct */ + if (0 != strcmp ("failure", refund_status_type)) + { + GNUNET_break_op (0); + ret = GNUNET_SYSERR; + } } } + if (GNUNET_OK != ret) + { + GNUNET_break_op (0); + cb_failure (owgh, + TALER_EC_CHECK_PAYMENT_RESPONSE_MALFORMED, + json); + TALER_MERCHANT_wallet_order_get_cancel (owgh); + return; + } + rd->hr.http_status = exchange_status; } - if (GNUNET_OK != ret) + { - GNUNET_break_op (0); - cb_failure (owgh, - TALER_EC_CHECK_PAYMENT_RESPONSE_MALFORMED, - json); - TALER_MERCHANT_wallet_order_get_cancel (owgh); - return; + struct TALER_MERCHANT_HttpResponse hr = { + .reply = json, + .http_status = MHD_HTTP_OK + }; + + owgh->cb (owgh->cb_cls, + &hr, + GNUNET_YES, + refunded ? GNUNET_YES : GNUNET_NO, + refunded ? &refund_amount : NULL, + NULL, /* paid! */ + NULL, /* paid! */ + &merchant_pub, + refund_len, + rds); } - rd->hr.http_status = exchange_status; } - + GNUNET_JSON_parse_free (spec); + break; + } + case 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) + { + GNUNET_break_op (0); + cb_failure (owgh, + TALER_EC_CHECK_PAYMENT_RESPONSE_MALFORMED, + json); + } + else { struct TALER_MERCHANT_HttpResponse hr = { .reply = json, @@ -394,17 +324,41 @@ handle_wallet_get_order_finished (void *cls, owgh->cb (owgh->cb_cls, &hr, - GNUNET_YES, - refunded ? GNUNET_YES : GNUNET_NO, - refunded ? &refund_amount : NULL, - NULL, /* paid! */ - NULL, /* paid! */ - &merchant_pub, - refund_len, - rds); + GNUNET_NO, + GNUNET_NO, + NULL, + taler_pay_uri, + already_paid, + NULL, + 0, + NULL); } + break; + } + default: + { + struct TALER_MERCHANT_HttpResponse hr; + + TALER_MERCHANT_parse_error_details_ (response, + response_code, + &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); + GNUNET_break_op (0); + owgh->cb (owgh->cb_cls, + &hr, + GNUNET_SYSERR, + GNUNET_SYSERR, + NULL, + NULL, + NULL, + NULL, + 0, + NULL); + break; } - GNUNET_JSON_parse_free (spec); } TALER_MERCHANT_wallet_order_get_cancel (owgh); } |