mirror of
https://github.com/Steffo99/greed.git
synced 2024-11-24 14:54:18 +00:00
allow refill on insufficient funds during checkout
This commit is contained in:
parent
5be2f9e762
commit
23f395ee8a
2 changed files with 13 additions and 6 deletions
|
@ -74,7 +74,8 @@ phone_required = yes
|
|||
full_order_info = no
|
||||
; Payment presets would be suggested to the user as buttons, when making credit card transaction
|
||||
payment_presets = 10.00,25.00,50.00,100.00
|
||||
|
||||
; Allow balance refill during the order checkout in case of unsufficient balance
|
||||
refill_on_checkout = yes
|
||||
|
||||
# Exception reporting settings
|
||||
[Error Reporting]
|
||||
|
|
12
worker.py
12
worker.py
|
@ -484,12 +484,18 @@ class ChatWorker(threading.Thread):
|
|||
order_id=order.order_id)
|
||||
self.session.add(order_item)
|
||||
# Ensure the user has enough credit to make the purchase
|
||||
if self.user.credit - self.__get_cart_value(cart) < 0:
|
||||
credit_required = self.__get_cart_value(cart) - self.user.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["Appearance"]["refill_on_checkout"] == 'yes':
|
||||
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):
|
||||
# Rollback all the changes
|
||||
self.session.rollback()
|
||||
return
|
||||
|
||||
else:
|
||||
# User has credit and valid order, perform transaction now
|
||||
self.__order_transaction(order=order, value=-int(self.__get_cart_value(cart)))
|
||||
|
||||
|
|
Loading…
Reference in a new issue