summaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd.c
diff options
context:
space:
mode:
authorJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-08-19 03:28:38 -0400
committerJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-08-19 03:28:38 -0400
commitb77ef665b0f3876f2c27db2d5a9b154fa1a9ba0d (patch)
tree37f482c473bf00f78218bdc1305d0980f5486895 /src/backend/taler-merchant-httpd.c
parent807b6e0b125100b1dd8ec56521517522a0cbfd4f (diff)
downloadmerchant-b77ef665b0f3876f2c27db2d5a9b154fa1a9ba0d.tar.gz
merchant-b77ef665b0f3876f2c27db2d5a9b154fa1a9ba0d.tar.bz2
merchant-b77ef665b0f3876f2c27db2d5a9b154fa1a9ba0d.zip
long poll for pending refunds
Diffstat (limited to 'src/backend/taler-merchant-httpd.c')
-rw-r--r--src/backend/taler-merchant-httpd.c55
1 files changed, 49 insertions, 6 deletions
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
@@ -154,6 +154,24 @@ 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.
*
* @param[in,out] mi merchant instance to update and possibly free
@@ -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);