diff options
Diffstat (limited to 'src/backenddb/pg_lookup_order_by_fulfillment.c')
-rw-r--r-- | src/backenddb/pg_lookup_order_by_fulfillment.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/backenddb/pg_lookup_order_by_fulfillment.c b/src/backenddb/pg_lookup_order_by_fulfillment.c index 291bd857..e600df32 100644 --- a/src/backenddb/pg_lookup_order_by_fulfillment.c +++ b/src/backenddb/pg_lookup_order_by_fulfillment.c @@ -25,13 +25,15 @@ #include "pg_lookup_order_by_fulfillment.h" #include "pg_helper.h" + enum GNUNET_DB_QueryStatus -TMH_PG_lookup_order_by_fulfillment (void *cls, - const char *instance_id, - const char *fulfillment_url, - const char *session_id, - bool allow_refunded_for_repurchase, - char **order_id) +TMH_PG_lookup_order_by_fulfillment ( + void *cls, + const char *instance_id, + const char *fulfillment_url, + const char *session_id, + bool allow_refunded_for_repurchase, + char **order_id) { struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { @@ -51,7 +53,7 @@ TMH_PG_lookup_order_by_fulfillment (void *cls, PREPARE (pg, "lookup_order_by_fulfillment", "SELECT" - " mct.order_id" + " mct.order_id" " FROM merchant_contract_terms mct" " LEFT JOIN merchant_refunds mref" " USING (order_serial)" @@ -62,8 +64,15 @@ TMH_PG_lookup_order_by_fulfillment (void *cls, " FROM merchant_instances" " WHERE merchant_id=$1)" " AND ((CAST($4 AS BOOL)) OR" - " mref.refund_serial IS NULL)"); - + " mref.refund_serial IS NULL)" + /* Theoretically, multiple paid orders + for the same fulfillment URL could + exist for this session_id -- if a + wallet was broken and did multiple + payments without repurchase detection. + So we need to limit to 1 when returning! */ + " ORDER BY order_id DESC" + " LIMIT 1;"); return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, "lookup_order_by_fulfillment", params, |