star invoices

This commit is contained in:
user committed 2025-02-26 19:43:58 +03:00
1 parent d5bb480042
commit d0845a153c
3 files changed
+44 -13

No files matched your search

+29 -12
View File
@@ -3,6 +3,7 @@ from aiogram import Bot, types
from app.core.logger import make_log
from app.core.models.node_storage import StoredContent
from app.core.models.keys import KnownKey
from app.core.models import StarsInvoice
from app.core.models.content.user_content import UserContent
from app.core._config import CLIENT_TELEGRAM_API_KEY
import json
@@ -56,19 +57,35 @@ async def s_api_v1_content_view(request, content_address: str):
content_id=content['encrypted_content'].id).first())
)
if not have_access:
try:
invoice_id = uuid.uuid4().hex
opts['invoice_url'] = (
await Bot(token=CLIENT_TELEGRAM_API_KEY).create_invoice_link(
description='You will receive NFT with lifetime access to content',
payload=f"access_{invoice_id}",
title='Lifetime access to content',
currency='XTR',
prices=[
types.LabeledPrice(label='Lifetime access', amount=1)
]
)
stars_cost = 1
invoice_id = f"access_{uuid.uuid4().hex}"
request.ctx.db_session.add(
StarsInvoice(
external_id=invoice_id,
type='access',
amount=stars_cost,
content_hash=content['encrypted_content'].hash,
)
)
request.ctx.db_session.commit()
try:
opts['invoice'] = {
'url': (
await Bot(token=CLIENT_TELEGRAM_API_KEY).create_invodeice_link(
description='You will receive NFT with lifetime access to content',
payload=f"access_{invoice_id}",
title='Lifetime access to content',
currency='XTR',
prices=[
types.LabeledPrice(label='Lifetime access', amount=stars_cost),
],
provider_token="",
)
),
'amount': stars_cost,
}
except BaseException as e:
make_log("Content", f"Can't create invoice link: {e}", level='warning')