86 lines
2.3 KiB
Python

import httpx
from src.core.api_tips_integrate.schemas import CreateTipSchema, AllDonatesSchema, DonationSchema
from src.core.common.constants import DH_ACCOUNTS_API_URL, DH_WIDGETS_API_URL
from src.core.common.schemas import TokenPayloadSchema, UserInfoSchema, PaymentLinkSchema
async def create_payment_link_for_tip_service(
jwt_data: TokenPayloadSchema,
create_tip_schema: CreateTipSchema,
):
async with httpx.AsyncClient() as client:
headers = {
"accept": "application/json"
}
response = await client.get(
headers=headers,
url=DH_ACCOUNTS_API_URL + f"info/{jwt_data.account_id}"
)
user_data = UserInfoSchema(**response.json())
async with httpx.AsyncClient() as client:
headers = {
"accept": "application/json",
"Content-Type": "application/json"
}
data = {
"amount": create_tip_schema.amount,
}
if create_tip_schema.from_user:
data["donatUser"] = create_tip_schema.from_user
if create_tip_schema.text:
data["text"] = create_tip_schema.text
print(DH_WIDGETS_API_URL + f"donat/{user_data.login}")
response = await client.post(
headers=headers,
json=data,
url=DH_WIDGETS_API_URL + f"donat/{user_data.login}"
)
if response.status_code != 200:
print(response.json())
payment_link_schema = PaymentLinkSchema(**response.json())
return payment_link_schema
async def get_last_donates_by_login():
pass
async def get_summary_donates_for_period():
pass
async def create_payment_link_for_donate_service(
token: str,
page: int = 1,
limit: int = 10,
) -> AllDonatesSchema:
headers = {
"accept": "application/json",
"Authorization": f"Bearer {token}"
}
params = {
"page": page,
"limit": limit
}
async with httpx.AsyncClient() as client:
response = await client.get(
url=DH_WIDGETS_API_URL + "donat",
headers=headers,
params=params
)
response.raise_for_status()
data = response.json()
return AllDonatesSchema(
donates=[DonationSchema(**item) for item in data]
)