taler-mdb

GNU Taler Extensions and Integrations
Log | Files | Refs | Submodules | README | LICENSE

commit dc35388eaf7b09f3eb069036212137ce70a195d2
parent 12afb98a2f3c2010f482a7abf055280968046551
Author: Christian Grothoff <christian@grothoff.org>
Date:   Wed, 18 May 2022 18:28:50 +0200

enforce payment deadline to be applicable

Diffstat:
Msrc/main.c | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 67 insertions(+), 2 deletions(-)

diff --git a/src/main.c b/src/main.c @@ -79,6 +79,12 @@ along with GNUNET_TIME_UNIT_MINUTES, 5) /** + * Set payment deadline below what will work with the snack machine. + */ +#define PAY_TIMEOUT GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_MINUTES, 1) + +/** * How long could it take at most for us to notify the Taler merchant * backend to grant a refund to a user if dispensing the product * failed? (Very conservative value here, for vending machines brewing @@ -411,6 +417,11 @@ struct PaymentActivity struct TALER_Amount amount; /** + * Handle for our attempt to delete an ongoing order. + */ + struct TALER_MERCHANT_OrderDeleteHandle *odh; + + /** * Member to see if the wallet already received a uri * If true, tunneling can be offered to the wallet. */ @@ -955,8 +966,56 @@ async_pa_cleanup_job (void *cls) * @param pa the payment activity to clean up */ static void +cleanup_payment (struct PaymentActivity *pa); + + +/** + * Function called with the result of the DELETE /orders/$ID operation. + * + * @param cls closure with the `struct PaymentActivity *` + * @param hr HTTP response details + */ +static void +order_delete_cb ( + void *cls, + const struct TALER_MERCHANT_HttpResponse *hr) +{ + struct PaymentActivity *pa = cls; + + pa->odh = NULL; + if ( (MHD_HTTP_OK != hr->http_status) && + (MHD_HTTP_NO_CONTENT != hr->http_status) ) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to delete incomplete order from backend: %d/%u\n", + (int) hr->http_status, + (unsigned int) hr->ec); + } + cleanup_payment (pa); +} + + +static void cleanup_payment (struct PaymentActivity *pa) { + if ( (! pa->paid) && + (NULL != pa->order_id) ) + { + char *oid; + + oid = pa->order_id; + pa->order_id = NULL; + pa->odh = TALER_MERCHANT_order_delete ( + pa->ctx, + pa->base_url, + oid, + &order_delete_cb, + pa); + GNUNET_free (oid); + return; + } + if (NULL != pa->odh) + TALER_MERCHANT_order_delete_cancel (pa->odh); if (NULL != pa->pnd) { nfc_abort_command (pa->pnd); @@ -1589,6 +1648,9 @@ launch_payment (struct Product *product) orderReq = GNUNET_JSON_PACK ( GNUNET_JSON_pack_string ("summary", product->description), + GNUNET_JSON_pack_timestamp ("pay_deadline", + GNUNET_TIME_relative_to_timestamp ( + PAY_TIMEOUT)), GNUNET_JSON_pack_object_steal ( "products", GNUNET_JSON_PACK ( @@ -1612,6 +1674,9 @@ launch_payment (struct Product *product) orderReq = GNUNET_JSON_PACK ( GNUNET_JSON_pack_string ("summary", product->description), + GNUNET_JSON_pack_timestamp ("pay_deadline", + GNUNET_TIME_relative_to_timestamp ( + PAY_TIMEOUT)), TALER_JSON_pack_amount ("amount", &product->price), GNUNET_JSON_pack_string ("fulfillment_message", @@ -2616,7 +2681,7 @@ read_mdb_command (void *cls) * @brief Mdb event loop to start read and write tasks */ static void -run_mdb_event_loop () +run_mdb_event_loop (void) { struct GNUNET_DISK_FileHandle fh = { mdb.uartfd }; @@ -2890,7 +2955,7 @@ read_products (void *cls, * @return #GNUNET_OK on success */ static enum GNUNET_GenericReturnValue -mdb_init () +mdb_init (void) { struct termios uart_opts_raw;