1
Fork 0
mirror of https://github.com/Steffo99/greed.git synced 2024-11-22 05:54:18 +00:00
This commit is contained in:
Steffo 2020-07-07 00:07:20 +02:00
parent bd1b98437d
commit c9f220ace4
Signed by: steffo
GPG key ID: 896A80F55F7C97F0

View file

@ -246,12 +246,22 @@ class Worker(threading.Thread):
# Return the precheckoutquery # Return the precheckoutquery
return update.pre_checkout_query return update.pre_checkout_query
def __wait_for_successfulpayment(self) -> telegram.SuccessfulPayment: def __wait_for_successfulpayment(self,
cancellable: bool = False) -> Union[telegram.SuccessfulPayment, CancelSignal]:
"""Continue getting updates until a successfulpayment is received.""" """Continue getting updates until a successfulpayment is received."""
log.debug("Waiting for a SuccessfulPayment...") log.debug("Waiting for a SuccessfulPayment...")
while True: while True:
# Get the next update # Get the next update
update = self.__receive_next_update() update = self.__receive_next_update()
# If a CancelSignal is received...
if isinstance(update, CancelSignal):
# And the wait is cancellable...
if cancellable:
# Return the CancelSignal
return update
else:
# Ignore the signal
continue
# Ensure the update contains a message # Ensure the update contains a message
if update.message is None: if update.message is None:
continue continue
@ -754,7 +764,7 @@ class Worker(threading.Thread):
# Accept the checkout # Accept the checkout
self.bot.answer_pre_checkout_query(precheckoutquery.id, ok=True) self.bot.answer_pre_checkout_query(precheckoutquery.id, ok=True)
# Wait for the payment # Wait for the payment
successfulpayment = self.__wait_for_successfulpayment() successfulpayment = self.__wait_for_successfulpayment(cancellable=False)
# Create a new database transaction # Create a new database transaction
transaction = db.Transaction(user=self.user, transaction = db.Transaction(user=self.user,
value=int(successfulpayment.total_amount) - fee, value=int(successfulpayment.total_amount) - fee,