From b77ef665b0f3876f2c27db2d5a9b154fa1a9ba0d Mon Sep 17 00:00:00 2001 From: Jonathan Buchanan Date: Wed, 19 Aug 2020 03:28:38 -0400 Subject: long poll for pending refunds --- src/backend/taler-merchant-httpd.c | 55 +++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 6 deletions(-) (limited to 'src/backend/taler-merchant-httpd.c') diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c index f65b4292..54b8d163 100644 --- a/src/backend/taler-merchant-httpd.c +++ b/src/backend/taler-merchant-httpd.c @@ -153,6 +153,24 @@ static struct GNUNET_SCHEDULER_Task *resume_timeout_task; static const struct GNUNET_CONFIGURATION_Handle *cfg; +/** + * Holds data needed to determine when to resume a connection for + * GET /orders/$ORDER_ID + */ +struct ResumeData +{ + /** + * How much of the order has been refunded. + */ + const struct TALER_Amount *refund_amount; + + /** + * Whether the refunds for the order were obtained. + */ + bool obtained; +}; + + /** * Decrement reference counter of @a mi, and free if it hits zero. * @@ -370,12 +388,30 @@ resume_operation (void *cls, const struct GNUNET_HashCode *key, void *value) { - const struct TALER_Amount *have_refund = cls; + const struct ResumeData *rd = cls; struct TMH_SuspendedConnection *sc = value; + /* If the conditions are satisfied partially, turn them off for future + calls. */ + if ( (sc->awaiting_refund_obtained) && + (rd->obtained)) + sc->awaiting_refund_obtained = false; if ( (sc->awaiting_refund) && - ( (NULL == have_refund) || - (1 != TALER_amount_cmp (have_refund, + ( (NULL != rd->refund_amount) && + (1 == TALER_amount_cmp (rd->refund_amount, + &sc->refund_expected)) ) ) + sc->awaiting_refund = false; + + if ( (sc->awaiting_refund_obtained) && + (! rd->obtained)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Not awaking client, refunds not yet obtained\n"); + return GNUNET_OK; + } + if ( (sc->awaiting_refund) && + ( (NULL == rd->refund_amount) || + (1 != TALER_amount_cmp (rd->refund_amount, &sc->refund_expected)) ) ) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -405,14 +441,20 @@ resume_operation (void *cls, * * @param order_id the order that was paid or refunded * @param mi the merchant instance where the payment or refund happened - * @param have_refund refunded amount, NULL if there was no refund + * @param refund_amount refunded amount, if the trigger was a refund, otherwise NULL + * @param obtained if true, the wallet has obtained the refunds for the order */ void TMH_long_poll_resume (const char *order_id, const struct TMH_MerchantInstance *mi, - const struct TALER_Amount *have_refund) + const struct TALER_Amount *refund_amount, + bool obtained) { struct GNUNET_HashCode key; + struct ResumeData rd = { + .refund_amount = refund_amount, + .obtained = obtained + }; compute_pay_key (order_id, &mi->merchant_pub, @@ -423,7 +465,7 @@ TMH_long_poll_resume (const char *order_id, GNUNET_CONTAINER_multihashmap_get_multiple (payment_trigger_map, &key, &resume_operation, - (void *) have_refund); + (void *) &rd); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u operations remain suspended pending payment\n", GNUNET_CONTAINER_multihashmap_size (payment_trigger_map)); @@ -447,6 +489,7 @@ do_shutdown (void *cls) TMH_force_rc_resume (); TMH_force_post_transfers_resume (); TMH_force_tip_pickup_resume (); + TMH_force_wallet_refund_order_resume (); if (NULL != mhd_task) { GNUNET_SCHEDULER_cancel (mhd_task); -- cgit v1.2.3