Files
FragmentAPI/app/utils/api_client.py
T
bohd4nx 760c853acd feat: Add Fragment API for TON topups, Telegram Premium purchases, and Stars transactions
- Implemented Fragment API with methods for TON topups, Premium gifts, and Stars purchases.
- Created configuration management using environment variables.
- Added detailed README documentation for installation, configuration, and usage.
- Developed utility classes for API client, wallet linking, and transaction processing.
- Included example usage in main.py for easy demonstration of API functionalities.
- Updated requirements.txt with necessary dependencies.
2025-11-03 05:58:34 +08:00

28 lines
1.1 KiB
Python

from typing import Dict, Any, Tuple
import httpx
class ApiClient:
def __init__(self, config: dict, headers: dict, wallet_linker):
self.config = config
self.headers = headers
self.wallet_linker = wallet_linker
async def execute_transaction_request(self, tx_data: Dict[str, Any], account: Dict[str, Any]) -> Tuple[
bool, Dict[str, Any]]:
async with httpx.AsyncClient() as client:
tx_resp = await client.post(f"https://fragment.com/api?hash={self.config['hash']}",
headers=self.headers, data=tx_data)
transaction = tx_resp.json()
if transaction.get("need_verify"):
if not await self.wallet_linker.link_wallet(account):
return False, {"success": False, "error": "Failed to link wallet"}
tx_resp = await client.post(f"https://fragment.com/api?hash={self.config['hash']}",
headers=self.headers, data=tx_data)
transaction = tx_resp.json()
return True, transaction