diff --git a/handlers/__init__.py b/handlers/__init__.py index 2db2f71..994b447 100644 --- a/handlers/__init__.py +++ b/handlers/__init__.py @@ -2,3 +2,4 @@ from . import users from . import groups from . import channels +from . import payments diff --git a/handlers/payments/__init__.py b/handlers/payments/__init__.py new file mode 100644 index 0000000..f88da4c --- /dev/null +++ b/handlers/payments/__init__.py @@ -0,0 +1 @@ +from . import payme \ No newline at end of file diff --git a/handlers/payments/payme.py b/handlers/payments/payme.py new file mode 100644 index 0000000..ef47dd1 --- /dev/null +++ b/handlers/payments/payme.py @@ -0,0 +1,76 @@ +import requests +import uuid + +def create_transactions(): + charge_id = str(uuid.uuid4()) + + url = "https://checkout.paycom.uz" + + # Data to be sent in the POST request + data = { + 'merchant': '672b8224c628bf0c13f3c4ef', + 'amount': '500000', + 'account[charge_id]': charge_id + } + # Sending POST request + response = requests.post(url, data=data) + # Check the response + if response.status_code == 200: + # Extract and print the form name="redirect" + if '
', start_index) + 1 + html_content = response.text + start = html_content.find('property="og:description" content="') + len( + 'property="og:description" content="') + end = html_content.find('"', start_index) + meta_description = html_content[start:end] + + # Split the content to find 'Номер чека' + parts = meta_description.split(',') + check_id = parts[1].split(':')[1] + a = 'https://checkout.paycom.uz/' + response.text[start_index:end_index].split('/')[5] + return [check_id, a] + + else: + print("Redirect form not found in the response.") + else: + print(f"Failed to send request. Status code: {response.status_code}") + +print(create_transactions()) + + +def check_transactions(check_id): + a = "SmchgGopUu5rAxpCsjOpr64ridAP3VrrDutv" + b = "672b8224c628bf0c13f3c4ef" + url = "https://checkout.paycom.uz/api" + headers = { + "X-auth": f"{b}:{a}", + "Content-Type": "application/json" + } + payload = { + "id": check_id, # This is a random ID for your request + "method": "receipts.check", + "params": { + "id": f"{check_id}" # Your transaction ID + } + } + + try: + response = requests.post(url, json=payload, headers=headers) + response_data = response.json() + + # Check if the request was successful + if 'result' in response_data: + transaction_state = response_data['result'].get('state') + # If the payment was successful + if transaction_state != 0: + return True # Payment successful + else: + return False # Payment not successful or in another state + else: + # Handle errors + error_message = response_data.get('error', {}).get('message', 'Unknown error') + print(f"Error: {error_message}") + except Exception as e: + print(f"An error occurred while checking transaction status: {e}") diff --git a/handlers/users/start.py b/handlers/users/start.py index 8be277f..4babb19 100644 --- a/handlers/users/start.py +++ b/handlers/users/start.py @@ -27,7 +27,7 @@ async def check_subscription(user_id): return False -@dp.message_handler(commands='start') +@dp.message_handler(commands='start',state='*') async def start_bosganda(message: types.Message, state: FSMContext): if " " in message.text: param = message.text.split(" ", 1)[1] @@ -44,11 +44,10 @@ async def start_bosganda(message: types.Message, state: FSMContext): Agar siz shaxsiy hayotingizda extiros va baxtli munosabatlarni, energiyanga boy bolishni istasangiz, sizni….. dekabr kuni Vebinarga ishtirok etishingiz uchun ishonch hosil qiling! 🔥 -Sizning bonusingiz sizni bu erda kutmoqda 👇""" , reply_markup=bonus_2) +Sizning bonusingiz sizni bu erda kutmoqda 👇""", reply_markup=bonus_2) await message.answer(f"Assalomu Aleykum {message.from_user.first_name}") # await message.answer_video_note(video_note=open('media/start_reklama.mp4', "rb")) - is_subscribed = await check_subscription(message.from_user.id) if not is_subscribed: @@ -77,6 +76,8 @@ async def process_user_registration(message: types.Message): await message.delete() await message.answer("Botda foydalanish uchun ismingizni kiriting", reply_markup=ReplyKeyboardRemove()) await BotStates.name_state.set() + + @dp.callback_query_handler(text="bonus_2") async def bonus_22(call: types.CallbackQuery): await call.message.answer_document(open('media/Intim-xavfsizlik-qoidalari.pdf', 'rb')) @@ -157,7 +158,8 @@ async def reklama(message: types.Message): from states.aloqa_states import BotStates await BotStates.reklama_state.set() -@dp.message_handler(state=BotStates.reklama_state,content_types=types.ContentType.PHOTO) + +@dp.message_handler(state=BotStates.reklama_state, content_types=types.ContentType.PHOTO) async def handle_photo_with_caption(message: types.Message, state: FSMContext): photo = message.photo[-1] photo_file_id = photo.file_id @@ -170,6 +172,7 @@ async def handle_photo_with_caption(message: types.Message, state: FSMContext): await message.reply("Reklama Foydalanuvchiga yuborildi") await state.finish() + @dp.message_handler(commands=["video"]) async def video_handler(message: Message): if message.from_user.id == 433943: @@ -180,17 +183,22 @@ async def video_handler(message: Message): @dp.message_handler(state=BotStates.reklame_video, content_types=ContentType.VIDEO) async def video_handler(message: Message, state: FSMContext): video = message.video + try: + if message.caption: + caption = message.caption + except: + for i in ADMINS: + await bot.send_message(i, f"Reklama jo`natildi Caption {caption}") + file_id = video.file_id await state.finish() user_id = cursor.execute("SELECT tg_id FROM user_full_data").fetchall() for i in user_id: for user in i: - await bot.send_video(user, file_id) + await bot.send_video(user, file_id,caption=caption) await message.answer("Videoni Foydalanuvchilarga yubordim!") - - @dp.message_handler(content_types=types.ContentType.PHOTO) async def reklama_send(message: types.Message): users = cursor.execute("SELECT user_id FROM users_table") @@ -267,8 +275,8 @@ async def admin_bilan_boglanish(message: types.Message): kanal_btn = InlineKeyboardMarkup( inline_keyboard=[ [ - InlineKeyboardButton("@nadia_admini",url="https://t.me/@nadia_admini") + InlineKeyboardButton("@nadia_admini", url="https://t.me/@nadia_admini") ] ] ) - await message.answer("Admin bilan bo'glanish",reply_markup=kanal_btn) + await message.answer("Admin bilan bo'glanish", reply_markup=kanal_btn)