payment/payment_backend/services/payment.py

30 lines
1.2 KiB
Python
Raw Normal View History

from api import Tronscan
2024-11-21 09:34:38 +00:00
from loguru import logger
from custom_decorators import singleton
from utils.datetime import current_timestamp
@singleton
class PaymentService:
def __init__(self, api_key):
self.tronscan = Tronscan(api_key)
def check_payment(self, quant, from_address, to_address, order_create_timestamp, end_timestamp=None):
2024-11-20 17:09:07 +00:00
# # 删除测试代码
# return 1, 1
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:
2024-11-21 09:34:38 +00:00
logger.debug('No payments found')
2024-11-13 09:44:45 +00:00
return 0, 0
token_transfers = result['token_transfers']
token_transfer = token_transfers[-1]
confirmed = token_transfer['confirmed']
correct_quant = int(quant == (token_transfer['quant'] / 6))
2024-11-21 09:34:38 +00:00
logger.debug(f'correct_quant: {correct_quant} confirmed: {confirmed}')
return correct_quant, confirmed