payment/payment_backend/services/payment.py

24 lines
1014 B
Python
Raw Normal View History

2024-11-10 10:00:58 +00:00
from api import Tronscan
from custom_decorators import singleton
from utils.datetime import current_timestamp
@singleton
2024-11-11 07:32:36 +00:00
class PaymentService:
2024-11-10 10:00:58 +00:00
def __init__(self, api_key):
self.tronscan = Tronscan(api_key)
2024-11-11 07:32:36 +00:00
def check_payment(self, quant, from_address, to_address, order_create_timestamp, end_timestamp=None):
if end_timestamp is None:
end_timestamp = current_timestamp()
result = self.tronscan.token_trc20_transfers(limit=100,
from_address=from_address, to_address=to_address,
start_timestamp=order_create_timestamp, end_timestamp=end_timestamp)
if result['rangeTotal'] == 0:
return -1, 0
2024-11-10 10:00:58 +00:00
token_transfers = result['token_transfers']
token_transfer = token_transfers[-1]
confirmed = token_transfer['confirmed']
2024-11-11 07:32:36 +00:00
correct_quant = int(quant == (token_transfer['quant'] / 6))
return correct_quant, confirmed