From cf896a8549ca9bdfb64a4823cc1df71b94072ab0 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 7 Jan 2018 23:10:28 +0100 Subject: [PATCH] More work on the invoice payload handling --- core.py | 15 +++++++++++++++ strings.py | 5 ++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/core.py b/core.py index d092f50..5ecbfb9 100644 --- a/core.py +++ b/core.py @@ -111,6 +111,21 @@ def main(): continue # Forward the update to the worker receiving_worker.queue.put(update) + # If the update is a precheckoutquery, ensure it hasn't expired before forwarding it + if update.pre_checkout_query is not None: + # Forward the update to the corresponding worker + receiving_worker = chat_workers.get(update.pre_checkout_query.from_user.id) + # Check if it's the active invoice for this chat + if receiving_worker is None or update.pre_checkout_query.payload != receiving_worker.invoice_payload: + # Notify the user that the invoice has expired + try: + bot.answer_pre_checkout_query(update.pre_checkout_query.id, ok=False, error_message=strings.error_invoice_expired) + except telegram.error.BadRequest: + print(f"ERROR: pre_checkout_query expired before an answer could be sent") + # Go to the next update + continue + # Forward the update to the worker + receiving_worker.queue.put(update) # If there were any updates... if len(updates): # Mark them as read by increasing the update_offset diff --git a/strings.py b/strings.py index 5355522..198fe2d 100644 --- a/strings.py +++ b/strings.py @@ -83,4 +83,7 @@ error_no_worker_for_chat = "⚠️ La conversazione con il bot è interrotta.\n" error_payment_amount_over_max = "⚠️ Il massimo di fondi che possono essere aggiunti in una singola transazione è {max_amount}." # Error: add funds amount under min -error_payment_amount_under_min = "⚠️ Il minimo di fondi che possono essere aggiunti in una singola transazione è {min_amount}." \ No newline at end of file +error_payment_amount_under_min = "⚠️ Il minimo di fondi che possono essere aggiunti in una singola transazione è {min_amount}." + +# Error: the invoice has expired and can't be paid +error_invoice_expired = "⚠️ Questo pagamento è scaduto ed è stato annullato. Se vuoi ancora aggiungere fondi, usa l'opzione Aggiungi fondi del menu." \ No newline at end of file