diff --git a/user_api/call2api.py b/user_api/call2api.py index 9b7b133..1485f27 100644 --- a/user_api/call2api.py +++ b/user_api/call2api.py @@ -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) \ No newline at end of file + 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) \ No newline at end of file diff --git a/user_api/user_api.py b/user_api/user_api.py index e770ed8..43d0c41 100644 --- a/user_api/user_api.py +++ b/user_api/user_api.py @@ -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 ------------------------------