Реализация работы с invoice

This commit is contained in:
justuser-31 2025-11-02 14:04:51 +03:00
parent 2bb21e4ee4
commit 641b179cd0
2 changed files with 47 additions and 2 deletions

View File

@ -47,4 +47,18 @@ async def transfer_coins(token, src_username, dst_username, amount):
return await call('api/transfer_coins/', data)
async def get_stats(token):
return await call('api/get_stats/', token)
return await call('api/get_stats/', token)
async def create_invoice(token, dst_username, amount=None):
data = {'token': token, 'dst_username': dst_username}
if amount:
data['amount'] = amount
return await call('api/create_invoice/', data)
async def delete_invoice(token, id):
data = {'token': token, 'id': id}
return await call('api/delete_invoice/', data)
async def get_invoice(token, id):
data = {'token': token, 'id': id}
return await call('api/get_invoice/', data)

View File

@ -4,7 +4,8 @@ import asyncio
from statistics import median
from db import *
from call2api import check_user_token, user_in_db, transfer_coins, get_stats
from call2api import check_user_token, user_in_db, transfer_coins, get_stats, create_invoice, delete_invoice, \
get_invoice
#------------------------------------------------------------
@ -117,6 +118,36 @@ async def get_stats_api(
raise HTTPException(status_code=401, detail='Invalid username or token')
return await get_stats(token=SYSTEM_API_TOKEN)
@app.post('/api/create_invoice/')
async def create_invoice_api(
username: str = Body(),
user_token: str = Body(),
amount: float | None = Body(None)
):
if not token_check(username, user_token):
raise HTTPException(status_code=401, detail='Invalid username or token')
return await create_invoice(token=SYSTEM_API_TOKEN, dst_username=username, amount=amount)
@app.post('/api/delete_invoice/')
async def delete_invoice_api(
username: str = Body(),
user_token: str = Body(),
id: str = Body()
):
if not token_check(username, user_token):
raise HTTPException(status_code=401, detail='Invalid username or token')
return await delete_invoice(token=SYSTEM_API_TOKEN, id=id)
@app.post('/api/get_invoice/')
async def get_invoice_api(
username: str = Body(),
user_token: str = Body(),
id: str = Body()
):
if not token_check(username, user_token):
raise HTTPException(status_code=401, detail='Invalid username or token')
return await get_invoice(token=SYSTEM_API_TOKEN, id=id)
#------------------------- END ------------------------------