From 788163458e98e330c5e8c776c66c8413d2ece83a Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 8 Apr 2020 15:02:19 +0200 Subject: [PATCH] Offer refill only if the credit_required is between the min_amount and max_amount range --- worker.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/worker.py b/worker.py index 052e7e4..e9126c4 100644 --- a/worker.py +++ b/worker.py @@ -506,12 +506,14 @@ class ChatWorker(threading.Thread): self.session.add(order_item) # Ensure the user has enough credit to make the purchase credit_required = self.__get_cart_value(cart) - self.user.credit - # Notify user In case of insufficient credit + # Notify user in case of insufficient credit if credit_required > 0: self.bot.send_message(self.chat.id, strings.error_not_enough_credit) # Suggest payment for missing credit value if configuration allows refill if configloader.config["Credit Card"]["credit_card_token"] != "" \ - and configloader.config["Appearance"]["refill_on_checkout"] == 'yes': + and configloader.config["Appearance"]["refill_on_checkout"] == 'yes' \ + and credit_required <= utils.Price(int(configloader.config["Credit Card"]["max_amount"])) \ + and credit_required >= utils.Price(int(configloader.config["Credit Card"]["min_amount"])): self.__make_payment(utils.Price(credit_required)) # If afer requested payment credit is still insufficient (either payment failure or cancel) if self.user.credit < self.__get_cart_value(cart):