From 9b053802d49703fc1918c3621095e369beaaf604 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 3 Aug 2020 12:55:11 +0200 Subject: test for refund available --- src/backend/taler-merchant-httpd_get-orders-ID.c | 18 +++++++++++++++--- .../taler-merchant-httpd_private-get-orders-ID.c | 4 +++- src/backend/taler-merchant-httpd_private-get-orders.c | 4 +++- src/backenddb/plugin_merchantdb_postgres.c | 8 +++++++- src/backenddb/test_merchantdb.c | 8 ++++++-- src/include/taler_merchantdb_plugin.h | 4 +++- 6 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/backend/taler-merchant-httpd_get-orders-ID.c b/src/backend/taler-merchant-httpd_get-orders-ID.c index d587745c..fb189d37 100644 --- a/src/backend/taler-merchant-httpd_get-orders-ID.c +++ b/src/backend/taler-merchant-httpd_get-orders-ID.c @@ -237,6 +237,12 @@ struct GetOrderData */ bool refunded; + /** + * Set to true if a refund is still available for the + * wallet for this payment. + */ + bool refund_available; + /** * Set to true if the client requested HTML, otherwise * we generate JSON. @@ -682,6 +688,7 @@ exchange_found_cb (void *cls, * @param rtransaction_id identificator of the refund * @param reason human-readable explanation of the refund * @param refund_amount refund amount which is being taken from @a coin_pub + * @param pending true if the this refund was not yet processed by the wallet/exchange */ static void process_refunds_cb (void *cls, @@ -691,7 +698,8 @@ process_refunds_cb (void *cls, const char *exchange_url, uint64_t rtransaction_id, const char *reason, - const struct TALER_Amount *refund_amount) + const struct TALER_Amount *refund_amount, + bool pending) { struct GetOrderData *god = cls; struct CoinRefund *cr; @@ -722,6 +730,7 @@ process_refunds_cb (void *cls, } god->refund_amount = *refund_amount; god->refunded = true; + god->refund_available |= pending; } @@ -1307,7 +1316,7 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh, { enum GNUNET_GenericReturnValue res; - if (god->refunded) // FIXME: don't check for refunded, but for PENDING refund! + if (god->refund_available) { char *qr; char *uri; @@ -1320,7 +1329,10 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh, { GNUNET_break (0); GNUNET_free (uri); - return MHD_NO; // FIXME: add nicer error reply... + return TALER_MHD_reply_with_error (god->sc.con, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_ALLOCATION_FAILURE, + "during QR code generation"); } { struct KVC kvc[] = { diff --git a/src/backend/taler-merchant-httpd_private-get-orders-ID.c b/src/backend/taler-merchant-httpd_private-get-orders-ID.c index 7fdeeed6..7823837f 100644 --- a/src/backend/taler-merchant-httpd_private-get-orders-ID.c +++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.c @@ -628,6 +628,7 @@ gorc_cleanup (void *cls) * @param reason human-readable explanation of the refund * @param timestamp when was the refund made * @param refund_amount refund amount which is being taken from @a coin_pub + * @param pending true if the this refund was not yet processed by the wallet/exchange */ static void process_refunds_cb (void *cls, @@ -637,7 +638,8 @@ process_refunds_cb (void *cls, const char *exchange_url, uint64_t rtransaction_id, const char *reason, - const struct TALER_Amount *refund_amount) + const struct TALER_Amount *refund_amount, + bool pending) { struct GetOrderRequestContext *gorc = cls; diff --git a/src/backend/taler-merchant-httpd_private-get-orders.c b/src/backend/taler-merchant-httpd_private-get-orders.c index dc4901c3..41f5be48 100644 --- a/src/backend/taler-merchant-httpd_private-get-orders.c +++ b/src/backend/taler-merchant-httpd_private-get-orders.c @@ -222,6 +222,7 @@ cleanup (void *ctx) * @param reason human-readable explanation of the refund * @param timestamp when was the refund made * @param refund_amount refund amount which is being taken from @a coin_pub + * @param pending true if the this refund was not yet processed by the wallet/exchange */ static void process_refunds_cb (void *cls, @@ -231,7 +232,8 @@ process_refunds_cb (void *cls, const char *exchange_url, uint64_t rtransaction_id, const char *reason, - const struct TALER_Amount *refund_amount) + const struct TALER_Amount *refund_amount, + bool pending) { struct TALER_Amount *total_refund_amount = cls; diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index 52d7b995..dd8f00de 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -3053,6 +3053,7 @@ lookup_refunds_detailed_cb (void *cls, struct TALER_Amount refund_amount; char *reason; char *exchange_url; + uint8_t pending8; struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_uint64 ("refund_serial", &refund_serial), @@ -3068,6 +3069,8 @@ lookup_refunds_detailed_cb (void *cls, &reason), TALER_PQ_RESULT_SPEC_AMOUNT ("refund_amount", &refund_amount), + GNUNET_PQ_result_spec_auto_from_type ("pending", + &pending8), GNUNET_PQ_result_spec_end }; @@ -3088,7 +3091,8 @@ lookup_refunds_detailed_cb (void *cls, exchange_url, rtransaction_id, reason, - &refund_amount); + &refund_amount, + 0 != pending8); GNUNET_PQ_cleanup_result (rs); } } @@ -7473,8 +7477,10 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) ",reason" ",refund_amount_val" ",refund_amount_frac" + ",merchant_refund_proofs.exchange_sig IS NULL AS pending" " FROM merchant_refunds" " JOIN merchant_deposits USING (order_serial, coin_pub)" + " LEFT JOIN merchant_refund_proofs USING (refund_serial)" " WHERE order_serial=" " (SELECT order_serial" " FROM merchant_contract_terms" diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c index f8627260..c3e8d71a 100644 --- a/src/backenddb/test_merchantdb.c +++ b/src/backenddb/test_merchantdb.c @@ -5795,6 +5795,7 @@ struct TestLookupRefundsDetailed_Closure * @param rtransaction_id identificator of the refund * @param reason human-readable explanation of the refund * @param refund_amount refund amount which is being taken from @a coin_pub + * @param pending true if this refund has not been processed by the wallet/exchange */ static void lookup_refunds_detailed_cb (void *cls, @@ -5804,7 +5805,8 @@ lookup_refunds_detailed_cb (void *cls, const char *exchange_url, uint64_t rtransaction_id, const char *reason, - const struct TALER_Amount *refund_amount) + const struct TALER_Amount *refund_amount, + bool pending) { struct TestLookupRefundsDetailed_Closure *cmp = cls; if (NULL == cmp) @@ -5911,6 +5913,7 @@ struct LookupRefundSerial_Closure * @param rtransaction_id identificator of the refund * @param reason human-readable explanation of the refund * @param refund_amount refund amount which is being taken from @a coin_pub + * @param pending true if this refund has not been processed by the wallet/exchange */ static void get_refund_serial_cb (void *cls, @@ -5920,7 +5923,8 @@ get_refund_serial_cb (void *cls, const char *exchange_url, uint64_t rtransaction_id, const char *reason, - const struct TALER_Amount *refund_amount) + const struct TALER_Amount *refund_amount, + bool pending) { struct LookupRefundSerial_Closure *lookup_cls = cls; if (NULL == lookup_cls) diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h index 0ba158b8..a9726ce9 100644 --- a/src/include/taler_merchantdb_plugin.h +++ b/src/include/taler_merchantdb_plugin.h @@ -348,6 +348,7 @@ typedef void * @param rtransaction_id identificator of the refund * @param reason human-readable explanation of the refund * @param refund_amount refund amount which is being taken from @a coin_pub + * @param pending true if the this refund was not yet processed by the wallet/exchange */ typedef void (*TALER_MERCHANTDB_RefundDetailCallback)( @@ -358,7 +359,8 @@ typedef void const char *exchange_url, uint64_t rtransaction_id, const char *reason, - const struct TALER_Amount *refund_amount); + const struct TALER_Amount *refund_amount, + bool pending); /** -- cgit v1.2.3