From 641b179cd0cfbc285eb9c473bbb5330b31763e05 Mon Sep 17 00:00:00 2001 From: justuser-31 Date: Sun, 2 Nov 2025 14:04:51 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20?= =?UTF-8?q?=D1=81=20invoice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- user_api/call2api.py | 16 +++++++++++++++- user_api/user_api.py | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) 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 ------------------------------