star invoices
This commit is contained in:
parent
d5bb480042
commit
d0845a153c
|
|
@ -3,6 +3,7 @@ from aiogram import Bot, types
|
||||||
from app.core.logger import make_log
|
from app.core.logger import make_log
|
||||||
from app.core.models.node_storage import StoredContent
|
from app.core.models.node_storage import StoredContent
|
||||||
from app.core.models.keys import KnownKey
|
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.models.content.user_content import UserContent
|
||||||
from app.core._config import CLIENT_TELEGRAM_API_KEY
|
from app.core._config import CLIENT_TELEGRAM_API_KEY
|
||||||
import json
|
import json
|
||||||
|
|
@ -56,19 +57,35 @@ async def s_api_v1_content_view(request, content_address: str):
|
||||||
content_id=content['encrypted_content'].id).first())
|
content_id=content['encrypted_content'].id).first())
|
||||||
)
|
)
|
||||||
if not have_access:
|
if not have_access:
|
||||||
try:
|
stars_cost = 1
|
||||||
invoice_id = uuid.uuid4().hex
|
invoice_id = f"access_{uuid.uuid4().hex}"
|
||||||
opts['invoice_url'] = (
|
|
||||||
await Bot(token=CLIENT_TELEGRAM_API_KEY).create_invoice_link(
|
request.ctx.db_session.add(
|
||||||
description='You will receive NFT with lifetime access to content',
|
StarsInvoice(
|
||||||
payload=f"access_{invoice_id}",
|
external_id=invoice_id,
|
||||||
title='Lifetime access to content',
|
type='access',
|
||||||
currency='XTR',
|
amount=stars_cost,
|
||||||
prices=[
|
content_hash=content['encrypted_content'].hash,
|
||||||
types.LabeledPrice(label='Lifetime access', amount=1)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
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:
|
except BaseException as e:
|
||||||
make_log("Content", f"Can't create invoice link: {e}", level='warning')
|
make_log("Content", f"Can't create invoice link: {e}", level='warning')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ from app.core.models.base import AlchemyBase
|
||||||
from app.core.models.keys import KnownKey
|
from app.core.models.keys import KnownKey
|
||||||
from app.core.models.memory import Memory
|
from app.core.models.memory import Memory
|
||||||
from app.core.models.node_storage import StoredContent
|
from app.core.models.node_storage import StoredContent
|
||||||
from app.core.models.transaction import UserBalance, InternalTransaction
|
from app.core.models.transaction import UserBalance, InternalTransaction, StarsInvoice
|
||||||
from app.core.models.user import User
|
from app.core.models.user import User
|
||||||
from app.core.models.wallet_connection import WalletConnection
|
from app.core.models.wallet_connection import WalletConnection
|
||||||
from app.core.models.messages import KnownTelegramMessage
|
from app.core.models.messages import KnownTelegramMessage
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, Boolean, Float
|
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, Boolean, Float
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from .base import AlchemyBase
|
from .base import AlchemyBase
|
||||||
|
|
||||||
|
|
@ -36,3 +37,16 @@ class InternalTransaction(AlchemyBase):
|
||||||
user = relationship('User', uselist=False, back_populates='internal_transactions', foreign_keys=[user_id])
|
user = relationship('User', uselist=False, back_populates='internal_transactions', foreign_keys=[user_id])
|
||||||
asset = relationship('Asset', uselist=False, foreign_keys=[asset_id])
|
asset = relationship('Asset', uselist=False, foreign_keys=[asset_id])
|
||||||
spent_transaction = relationship('InternalTransaction', uselist=False, foreign_keys=[spent_transaction_id])
|
spent_transaction = relationship('InternalTransaction', uselist=False, foreign_keys=[spent_transaction_id])
|
||||||
|
|
||||||
|
class StarsInvoice(AlchemyBase):
|
||||||
|
__tablename__ = 'stars_invoices'
|
||||||
|
|
||||||
|
id = Column(Integer, autoincrement=True, primary_key=True)
|
||||||
|
external_id = Column(String(1024), nullable=False)
|
||||||
|
|
||||||
|
type = Column(String(256), nullable=False)
|
||||||
|
amount = Column(Integer, nullable=False)
|
||||||
|
|
||||||
|
content_hash = Column(String(256), nullable=True)
|
||||||
|
|
||||||
|
created = Column(DateTime, nullable=False, default=datetime.utcnow)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue