fixes
This commit is contained in:
parent
8f6e60f650
commit
e677a1e6ae
|
|
@ -26,46 +26,61 @@ router = Router()
|
||||||
|
|
||||||
async def t_callback_purchase_node_content(query: types.CallbackQuery, memory=None, user=None, db_session=None, chat_wrap=None, **extra):
|
async def t_callback_purchase_node_content(query: types.CallbackQuery, memory=None, user=None, db_session=None, chat_wrap=None, **extra):
|
||||||
content_oid = int(query.data.split('_')[1])
|
content_oid = int(query.data.split('_')[1])
|
||||||
make_log("OwnedContent", f"{user} Try to purchase content: {content_oid}", level='info')
|
is_cancel_request = query.data.split('_')[2] == 'cancel' if len(query.data.split('_')) > 2 else False
|
||||||
content = db_session.query(StoredContent).filter_by(id=content_oid).first()
|
if not is_cancel_request:
|
||||||
if not content:
|
make_log("OwnedContent", f"{user} Try to purchase content: {content_oid}", level='info')
|
||||||
return await query.answer(user.translated('error_contentNotFound'), show_alert=True)
|
content = db_session.query(StoredContent).filter_by(id=content_oid).first()
|
||||||
|
if not content:
|
||||||
|
return await query.answer(user.translated('error_contentNotFound'), show_alert=True)
|
||||||
|
|
||||||
license_price = content.meta.get('license', {}).get('listen', {}).get('price')
|
license_price = content.meta.get('license', {}).get('listen', {}).get('price')
|
||||||
license_price_num = int(license_price)
|
license_price_num = int(license_price)
|
||||||
if license_price_num < 1:
|
if license_price_num < 1:
|
||||||
return await query.answer(user.translated('error_contentPrice'), show_alert=True)
|
return await query.answer(user.translated('error_contentPrice'), show_alert=True)
|
||||||
|
|
||||||
ton_connect, ton_connection = TonConnect.by_user(db_session, user, callback_fn=())
|
ton_connect, ton_connection = TonConnect.by_user(db_session, user, callback_fn=())
|
||||||
await ton_connect.restore_connection()
|
await ton_connect.restore_connection()
|
||||||
assert ton_connect.connected, "No connected wallet"
|
assert ton_connect.connected, "No connected wallet"
|
||||||
|
|
||||||
user_wallet_address = user.wallet_address(db_session)
|
user_wallet_address = user.wallet_address(db_session)
|
||||||
|
|
||||||
memory._app.add_task(ton_connect._sdk_client.send_transaction({
|
memory._app.add_task(ton_connect._sdk_client.send_transaction({
|
||||||
'valid_until': int(datetime.now().timestamp() + 300),
|
'valid_until': int(datetime.now().timestamp() + 300),
|
||||||
'messages': [
|
'messages': [
|
||||||
{
|
{
|
||||||
'address': content.meta['item_address'],
|
'address': content.meta['item_address'],
|
||||||
'amount': license_price
|
'amount': license_price
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
new_action = UserAction(
|
||||||
|
type='purchase',
|
||||||
|
user_id=user.id,
|
||||||
|
content_id=content.id,
|
||||||
|
telegram_message_id=query.message.message_id,
|
||||||
|
from_address=user_wallet_address,
|
||||||
|
to_address=content.meta['item_address'],
|
||||||
|
status='requested',
|
||||||
|
meta={
|
||||||
|
'confirmation_url': wallet_obj_by_name(ton_connection.wallet_key.split('==')[0])['universal_url']
|
||||||
|
},
|
||||||
|
created=datetime.now()
|
||||||
|
)
|
||||||
|
db_session.add(new_action)
|
||||||
|
else:
|
||||||
|
make_log("OwnedContent", f"{user} Try to cancel purchase: {content_oid}", level='info')
|
||||||
|
action = db_session.query(UserAction).filter_by(
|
||||||
|
type='purchase',
|
||||||
|
content_id=content_oid,
|
||||||
|
user_id=user.id,
|
||||||
|
status='requested'
|
||||||
|
).first()
|
||||||
|
if not action:
|
||||||
|
return await query.answer()
|
||||||
|
|
||||||
|
action.status = 'canceled'
|
||||||
|
|
||||||
new_action = UserAction(
|
|
||||||
type='purchase',
|
|
||||||
user_id=user.id,
|
|
||||||
content_id=content.id,
|
|
||||||
telegram_message_id=query.message.message_id,
|
|
||||||
from_address=user_wallet_address,
|
|
||||||
to_address=content.meta['item_address'],
|
|
||||||
status='requested',
|
|
||||||
meta={
|
|
||||||
'confirmation_url': wallet_obj_by_name(ton_connection.wallet_key.split('==')[0])['universal_url']
|
|
||||||
},
|
|
||||||
created=datetime.now()
|
|
||||||
)
|
|
||||||
db_session.add(new_action)
|
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
await chat_wrap.send_content(db_session, content, message_id=query.message.message_id)
|
await chat_wrap.send_content(db_session, content, message_id=query.message.message_id)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,10 @@ class PlayerTemplates:
|
||||||
'text': self.user.translated('gotoWallet_button'),
|
'text': self.user.translated('gotoWallet_button'),
|
||||||
'url': purchase_action.meta['confirmation_url']
|
'url': purchase_action.meta['confirmation_url']
|
||||||
}])
|
}])
|
||||||
|
inline_keyboard_array.append([{
|
||||||
|
'text': self.user.translated('cancelPurchase_button'),
|
||||||
|
'callback_data': f'PC_{content.id}_cancel'
|
||||||
|
}])
|
||||||
text = self.user.translated('p_playerContext_purchaseRequested')
|
text = self.user.translated('p_playerContext_purchaseRequested')
|
||||||
else:
|
else:
|
||||||
inline_keyboard_array.append([{
|
inline_keyboard_array.append([{
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -150,3 +150,7 @@ msgstr "Error: content price is not set"
|
||||||
#: app/client_bot/routers/content.py:133
|
#: app/client_bot/routers/content.py:133
|
||||||
msgid "viewTrack_button"
|
msgid "viewTrack_button"
|
||||||
msgstr "View track"
|
msgstr "View track"
|
||||||
|
|
||||||
|
#: app/client_bot/routers/content.py:138
|
||||||
|
msgid "cancelPurchase_button"
|
||||||
|
msgstr "Cancel purchase"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue