diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-06-03 20:39:11 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-06-03 20:39:11 +0200 |
commit | 24a2a3f887ce34d42dc20dc7952b8edeb4a21bd4 (patch) | |
tree | d08dd484947496b178a1017f7ebc6e3a46be648c /src/backenddb/plugin_merchantdb_postgres.c | |
parent | 2789caa9b8658e88eebf3333475f989e7cd2fd37 (diff) | |
download | merchant-24a2a3f887ce34d42dc20dc7952b8edeb4a21bd4.tar.gz merchant-24a2a3f887ce34d42dc20dc7952b8edeb4a21bd4.tar.bz2 merchant-24a2a3f887ce34d42dc20dc7952b8edeb4a21bd4.zip |
new backenddb APIs for GET /private/orders/ID
Diffstat (limited to 'src/backenddb/plugin_merchantdb_postgres.c')
-rw-r--r-- | src/backenddb/plugin_merchantdb_postgres.c | 73 |
1 files changed, 71 insertions, 2 deletions
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index a5f6818b..66d85b56 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -1359,13 +1359,15 @@ postgres_insert_order_lock (void *cls, * @param instance_id instance's identifier * @param order_id order_id used to lookup. * @param[out] contract_terms where to store the result, NULL to only check for existence + * @param[out] order_serial set to the order's serial number * @return transaction status */ static enum GNUNET_DB_QueryStatus postgres_lookup_contract_terms (void *cls, const char *instance_id, const char *order_id, - json_t **contract_terms) + json_t **contract_terms, + uint64_t *order_serial) { struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { @@ -1376,6 +1378,8 @@ postgres_lookup_contract_terms (void *cls, struct GNUNET_PQ_ResultSpec rs[] = { TALER_PQ_result_spec_json ("contract_terms", contract_terms), + GNUNET_PQ_result_spec_uint64 ("order_serial", + order_serial), GNUNET_PQ_result_spec_end }; @@ -2000,6 +2004,59 @@ postgres_lookup_order_status (void *cls, /** + * Retrieve payment and wire status for a given @a order_serial and session ID. + * + * @param cls closure + * @param order_serial identifies the order + * @param session_id session for which to check the payment status, NULL for any + * @param[out] paid set to the payment status of the contract + * @param[out] wired set to the wire transfer status of the exchange payment + * @return transaction status + */ +static enum GNUNET_DB_QueryStatus +postgres_lookup_payment_status (void *cls, + uint64_t order_serial, + const char *session_id, + bool *paid, + bool *wired) +{ + struct PostgresClosure *pg = cls; + uint8_t paid8; + uint8_t wired8; + enum GNUNET_DB_QueryStatus qs; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&order_serial), + GNUNET_PQ_query_param_string (session_id), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("paid", + &paid8), + GNUNET_PQ_result_spec_auto_from_type ("wired", + &wired8), + GNUNET_PQ_result_spec_end + }; + + check_connection (pg); + qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "lookup_payment_status", + params, + rs); + if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) + { + *paid = (0 != paid8); + *wired = (0 != wired8); + } + else + { + *paid = false; /* just to be safe(r) */ + *wired = false; /* just to be safe(r) */ + } + return qs; +} + + +/** * Closure for #process_refund_cb(). */ struct FindRefundContext @@ -6162,7 +6219,9 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) 4), /* for postgres_lookup_contract_terms() */ GNUNET_PQ_make_prepare ("lookup_contract_terms", - "SELECT contract_terms" + "SELECT" + " contract_terms" + ",order_serial" " FROM merchant_contract_terms" " WHERE order_id=$2" " AND merchant_serial=" @@ -6390,6 +6449,15 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) " WHERE merchant_id=$1)" " AND order_id=$2", 2), + /* for postgres_lookup_payment_status() */ + GNUNET_PQ_make_prepare ("lookup_payment_status", + "SELECT" + " wired" + ",paid" + " FROM merchant_contract_terms" + " WHERE order_serial=$1" + " AND session_id=$2", + 2), /* for process_refund_cb() used in postgres_increase_refund() */ GNUNET_PQ_make_prepare ("find_refunds_by_coin", "SELECT" @@ -7287,6 +7355,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) plugin->mark_contract_paid = &postgres_mark_contract_paid; plugin->refund_coin = &postgres_refund_coin; plugin->lookup_order_status = &postgres_lookup_order_status; + plugin->lookup_payment_status = &postgres_lookup_payment_status; plugin->increase_refund = &postgres_increase_refund; plugin->lookup_refunds_detailed = &postgres_lookup_refunds_detailed; plugin->insert_refund_proof = &postgres_insert_refund_proof; |