summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-04-10 21:20:46 +0200
committerChristian Grothoff <christian@grothoff.org>2020-04-10 21:20:46 +0200
commit257ee8379ecc4af7ac325aaf868b4e23a9293c14 (patch)
treea22bf720200913b145a2d4abd0e6f446b3a1eee8
parent4f237e8aae9b67a0bdb9363934dcbbb3a7742daa (diff)
downloadmerchant-257ee8379ecc4af7ac325aaf868b4e23a9293c14.tar.gz
merchant-257ee8379ecc4af7ac325aaf868b4e23a9293c14.tar.bz2
merchant-257ee8379ecc4af7ac325aaf868b4e23a9293c14.zip
implement caching/persisting of exchange /refund responses
-rw-r--r--ChangeLog42
-rw-r--r--src/backend/taler-merchant-httpd_refund_lookup.c60
2 files changed, 71 insertions, 31 deletions
diff --git a/ChangeLog b/ChangeLog
index d34b96fb..4a61c55e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Fri 10 Apr 2020 09:01:22 PM CEST
+ Changing refund API to have the merchant backend make the /refund
+ request to the exchange instead of having the wallet do it (#5299). -CG
+
Tue 31 Mar 2020 04:17:58 PM CEST
Releasing taler-merchant 0.7.0. -CG
@@ -30,16 +34,16 @@ Wed Oct 18 15:33:23 CEST 2017
Releasing taler-merchant 0.4.0. -CG
Thu Jun 22 15:12:37 CEST 2017
- Implementing /refund
+ Implementing /refund
Tue Jun 6 14:30:43 CEST 2017
- Abstracting the response gotten from the exchange's tracking
- API and relying it to the frontend.
- A payment generator has been implemented so that the db can
- easily be populated for testing purposes.
- /history API now has the way to query from a starting base date
- ahead into the future.
- Memory leak fixes. -CG/MS
+ Abstracting the response gotten from the exchange's tracking
+ API and relying it to the frontend.
+ A payment generator has been implemented so that the db can
+ easily be populated for testing purposes.
+ /history API now has the way to query from a starting base date
+ ahead into the future.
+ Memory leak fixes. -CG/MS
Releasing taler-merchant 0.3.0. -CG
Mon Mar 6 17:57:51 CET 2017
@@ -52,24 +56,22 @@ Mon Mar 6 00:59:25 CET 2017
IP address (#4752). Enabling use of dual-stack by default. -CG
Thu Dec 15 10:37:08 CET 2016
- Implementing:
- - /map/in, /map/out API, to allow frontends to store
- plain text contracts in database and retrieving them
- by looking for their hashcodes.
-
+ Implementing:
+ - /map/in, /map/out API, to allow frontends to store
+ plain text contracts in database and retrieving them
+ by looking for their hashcodes.
Fri Nov 18 18:54:07 CET 2016
Misc. minor updates to match API changes from exchange 0.2.
Releasing taler-merchant 0.2.0. -CG
Mon Oct 10 16:27:57 CEST 2016
- Implementing:
- - /track API, to map transactions to wire transfers and
- viceversa.
- - /history API, to get the list of transactions in DB.
- - merchant "instances", to run make multiple shops on the
- same backend.
- -MS
+ Implementing:
+ - /track API, to map transactions to wire transfers and
+ viceversa.
+ - /history API, to get the list of transactions in DB.
+ - merchant "instances", to run make multiple shops on the
+ same backend. -MS
Tue Jun 7 15:17:45 CEST 2016
Store signing key used by exchange in DB. Might be useful
diff --git a/src/backend/taler-merchant-httpd_refund_lookup.c b/src/backend/taler-merchant-httpd_refund_lookup.c
index e80241b7..0fd83ad3 100644
--- a/src/backend/taler-merchant-httpd_refund_lookup.c
+++ b/src/backend/taler-merchant-httpd_refund_lookup.c
@@ -64,6 +64,11 @@ struct CoinRefund
struct ProcessRefundData *prd;
/**
+ * URL of the exchange for this @e coin_pub.
+ */
+ char *exchange_url;
+
+ /**
* Coin to refund.
*/
struct TALER_CoinSpendPublicKeyP coin_pub;
@@ -213,6 +218,7 @@ cleanup_prd (struct TM_HandlerContext *cls)
json_decref (cr->exchange_reply);
cr->exchange_reply = NULL;
}
+ GNUNET_free (cr->exchange_url);
GNUNET_free (cr);
}
GNUNET_free (prd);
@@ -295,12 +301,25 @@ refund_cb (void *cls,
}
else
{
+ enum GNUNET_DB_QueryStatus qs;
+
cr->exchange_pub = *exchange_pub;
cr->exchange_sig = *exchange_sig;
- /* FIXME: store in our database,
- 1) as evidence for us that the refund happened, and
- 2) to possibly avoid doing another exchange iteration
- the next time around. */
+ qs = db->put_refund_proof (db->cls,
+ &cr->prd->merchant->pubkey,
+ &cr->prd->h_contract_terms,
+ &cr->coin_pub,
+ cr->rtransaction_id,
+ exchange_pub,
+ exchange_sig);
+ if (0 >= qs)
+ {
+ /* generally, this is relatively harmless for the merchant, but let's at
+ least log this. */
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to persist exchange response to /refund in database: %d\n",
+ qs);
+ }
}
check_resume_prd (cr->prd);
}
@@ -381,6 +400,7 @@ process_refunds_cb (void *cls,
TALER_amount2s (refund_amount),
reason);
cr = GNUNET_new (struct CoinRefund);
+ cr->exchange_url = GNUNET_strdup (exchange_url);
cr->prd = prd;
cr->coin_pub = *coin_pub;
cr->rtransaction_id = rtransaction_id;
@@ -389,13 +409,6 @@ process_refunds_cb (void *cls,
GNUNET_CONTAINER_DLL_insert (prd->cr_head,
prd->cr_tail,
cr);
- /* FIXME: check in database if we already got the
- results from #refund_cb() from an earlier request,
- if so, avoid this step: */
- cr->fo = TMH_EXCHANGES_find_exchange (exchange_url,
- NULL,
- &exchange_found_cb,
- cr);
}
@@ -529,6 +542,31 @@ MH_handler_refund_lookup (struct TMH_RequestHandler *rh,
TALER_EC_REFUND_LOOKUP_DB_ERROR,
"Failed to lookup refunds for contract");
}
+
+ /* Now launch exchange interactions, unless we already have the
+ response in the database! */
+ for (struct CoinRefund *cr = prd->cr_head;
+ NULL != cr;
+ cr = cr->next)
+ {
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = db->get_refund_proof (db->cls,
+ &cr->prd->merchant->pubkey,
+ &cr->prd->h_contract_terms,
+ &cr->coin_pub,
+ cr->rtransaction_id,
+ &cr->exchange_pub,
+ &cr->exchange_sig);
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
+ {
+ /* We need to talk to the exchange */
+ cr->fo = TMH_EXCHANGES_find_exchange (cr->exchange_url,
+ NULL,
+ &exchange_found_cb,
+ cr);
+ }
+ }
}
/* Check if there are still exchange operations pending */