async def mobile_operators(message: types.Message): try: user_id = message.from_user.id d = get_lang(user_id) first_name = message.from_user.first_name last_name = message.from_user.last_name update_log(user_id, get_log(user_id) + message.text) if message.text == get_dict('cancel', d): await bot.send_message(user_id, get_dict('section', d), reply_markup=markups.payments(d)) set_user_state(user_id, get_state_by_key('S_PAYMENTS')) elif (str(message.text).startswith('+998') and len(str(message.text)) == 13) or (str(message.text).startswith('998') and len(str(message.text)) == 12): mobile_payment_report_commit(user_id, first_name, last_name, str(message.text).replace('+', ''), str(dt.datetime.now())) set_mobile_payment_oper_id_app_user( user_id, (get_mobile_payment_oper_id(user_id)[0])) set_user_state(user_id, get_state_by_key('S_TYPE_SUM_MOBILE_PAYMENT')) await bot.send_message(user_id, get_dict('enter_amount', d), reply_markup=markups.cancel(d)) elif (str(message.text).startswith('9') and len(str(message.text)) == 9) or \ (str(message.text).startswith('8') and len(str(message.text)) == 9): mobile_payment_report_commit(user_id, first_name, last_name, '998' + str(message.text), str(dt.datetime.now())) set_mobile_payment_oper_id_app_user( user_id, (get_mobile_payment_oper_id(user_id)[0])) set_user_state(user_id, get_state_by_key('S_TYPE_SUM_MOBILE_PAYMENT')) await bot.send_message(user_id, get_dict('enter_amount', d), reply_markup=markups.cancel(d)) else: await bot.send_message( user_id, get_dict('phone_number_error', d), reply_markup=markups.payment_mobile_operators(user_id, d)) set_user_state(user_id, get_state_by_key('S_PAYMENT_MOBILE_OPERATORS')) except Exception as e: logger_app.error("/handlers/payments.py\nMethod: mobile_operators\n" + str(e))
async def card_to_card_transfers(message: types.Message): try: user_id = message.from_user.id first_name = message.from_user.first_name last_name = message.from_user.last_name d = get_lang(user_id) update_log(user_id, get_log(user_id) + message.text) if message.text == get_dict('cancel', d): await bot.send_message(user_id, get_dict('payments_hint', d), reply_markup=markups.payments(d)) set_user_state(user_id, get_state_by_key('S_PAYMENTS')) elif str(message.text).isdecimal() and len(str(message.text)) == 16: receiver = api.getCardName(message.text) if receiver['msgrespdata']['errorCode'] == '0': await bot.send_message( user_id, get_dict('receiver', d) + receiver['msgrespdata']['response']['name'] + '\n' + get_dict('card_number', d) + message.text + '\n' + get_dict('enter_amount', d), reply_markup=markups.cancel(d)) p2p_report_commit(user_id, first_name, last_name, message.text, str(dt.datetime.now())) set_p2p_oper_id_app_user(user_id, (get_p2p_oper_id(user_id)[0])) set_user_state(user_id, get_state_by_key('S_TYPE_SUM')) else: await bot.send_message(message.from_user.id, get_dict('recipient_not_found', d), reply_markup=markups.cancel(d)) else: await bot.send_message(user_id, get_dict('error_enter_card_number', d), reply_markup=markups.cancel(d)) except Exception as e: logger_p2p.error( "/handlers/money_transfer.py\nMethod: card_to_card_transfers\n" + str(e))
async def access(callback_query: types.CallbackQuery): try: user_id = callback_query.from_user.id d = get_lang(user_id) await bot.answer_callback_query(callback_query.id, ) key = load_key() f = Fernet(key) encoded_card = get_card_encode(user_id, callback_query.data[6:]) decrypted_card = f.decrypt( bytes((encoded_card[0])[2:-1], encoding='utf8')) errorCode = api.payP2p(decrypted_card.decode(), encoded_card[1], get_to_card_p2p_oper(user_id)[0], str(get_amount_from_user_p2p_oper(user_id)[0])) if errorCode["msgrespdata"]["errorCode"] == "0": await bot.delete_message(callback_query.message.chat.id, callback_query.message.message_id) await bot.send_message(callback_query.from_user.id, get_dict('sms_code', d), reply_markup=markups.cancel(d)) set_p2p_info((get_p2p_oper_id(user_id)[0]), 'SMS', 'SMS kodni kiriting', str(dt.datetime.now())) set_session_id(user_id, errorCode['msgrespdata']['response']['sessionId']) set_user_state(user_id, get_state_by_key('S_SMS_TYPE_P2P')) else: await bot.send_message( callback_query.from_user.id, get_dict('error_transfer_card_to_card', d) + errorCode["msgrespdata"]["errorMessage"]) set_p2p_info((get_p2p_oper_id(user_id)[0]), errorCode["msgrespdata"]["errorMessage"], 'Xatolik yuzaga keldi', str(dt.datetime.now())) await bot.delete_message(callback_query.message.chat.id, callback_query.message.message_id) await bot.send_message(callback_query.from_user.id, get_dict('section', d), reply_markup=markups.payments(d)) set_user_state(user_id, get_state_by_key('S_PAYMENTS')) except Exception as e: logger_p2p.error("/handlers/money_transfer.py\nMethod: access\n" + str(e))
async def payments(message: types.Message): try: user_id = message.from_user.id d = get_lang(user_id) update_log(user_id, get_log(user_id) + message.text) cards = '' if message.text == get_dict('my_cards', d): cardsList = get_card_json(user_id) if len(cardsList) > 0: for card in cardsList: cards = cards + card[1] + '\n' await bot.send_message(user_id, get_dict('your_cards', d) + '\n\n' + cards, reply_markup=markups.cards_menu(d)) else: await bot.send_message(user_id, get_dict('card_check', d), reply_markup=markups.cards_menu(d)) set_user_state(user_id, get_state_by_key('S_CARD_MENU')) elif message.text == get_dict('back', d): await bot.send_message(user_id, get_dict('main_menu_hint', d), reply_markup=markups.main_menu(d)) set_user_state(user_id, get_state_by_key('S_GET_MAIN_MENU')) elif message.text == get_dict('card_to_card_transfers', d): await bot.send_message(user_id, get_dict('enter_card_number', d), reply_markup=markups.cancel(d)) set_user_state(user_id, get_state_by_key('S_CARD_TO_CARD')) elif message.text == get_dict('repayment_of_loans', d): await bot.send_message(user_id, get_dict('developing', d)) elif message.text == get_dict('mobile_operators', d): await bot.send_message( user_id, get_dict('payment_mobile_operators', d), reply_markup=markups.payment_mobile_operators(user_id, d)) set_user_state(user_id, get_state_by_key('S_PAYMENT_MOBILE_OPERATORS')) else: await bot.send_message(user_id, get_dict('payments_hint', d)) except Exception as e: logger_app.error("/handlers/payments.py\nMethod: payments\n" + str(e))
async def accessPayment(callback_query: types.CallbackQuery): try: user_id = callback_query.from_user.id d = get_lang(user_id) await bot.answer_callback_query(callback_query.id, ) key = load_key() f = Fernet(key) encoded_card = get_card_encode( user_id, get_card_from_user_mobile_payment_oper(user_id)) decrypted_card = f.decrypt( bytes((encoded_card[0])[2:-1], encoding='utf8')) errorCode = api.payCellular( decrypted_card.decode(), encoded_card[1], get_to_phone_number_oper(user_id)[0], str(get_amount_from_user_mobile_payment_oper(user_id)[0])) if errorCode["msgrespdata"]["errorCode"] == "0": await bot.delete_message(callback_query.message.chat.id, callback_query.message.message_id) await bot.send_message(callback_query.from_user.id, get_dict('sms_code', d), reply_markup=markups.cancel(d)) set_user_state(user_id, get_state_by_key('S_SMS_TYPE_MOBILE_PAYMENT')) set_session_id(user_id, errorCode['msgrespdata']['response']['sessionId']) else: await bot.send_message(callback_query.from_user.id, get_dict('error_payment', d)) await bot.delete_message(callback_query.message.chat.id, callback_query.message.message_id) await bot.send_message(callback_query.from_user.id, get_dict('section', d), reply_markup=markups.payments(d)) set_user_state(user_id, get_state_by_key('S_PAYMENTS')) except Exception as e: logger_app.error( "/handlers/money_transfer.py\nMethod: accessPayment\n" + str(e))
async def enter_amount(message: types.Message): try: user_id = message.from_user.id d = get_lang(user_id) update_log(user_id, get_log(user_id) + message.text) if str(message.text).isnumeric(): if float(message.text) < 1000: await bot.send_message(user_id, get_dict('minimum_sum_p2p', d)) set_user_state(user_id, get_state_by_key('S_TYPE_SUM')) else: set_p2p_amount((get_p2p_oper_id(user_id)[0]), float(str(message.text))) set_p2p_info((get_p2p_oper_id(user_id)[0]), 'Enter amount', 'Summani kiriting', str(dt.datetime.now())) res = get_dict('choose_card', d) rows = get_all_cards(user_id) cards_inline = InlineKeyboardMarkup() if len(rows) > 0: for row in rows: cards_inline.add( InlineKeyboardButton(row[0] + ' ' + row[1], callback_data="p2p" + row[0])) await bot.send_message(user_id, res, reply_markup=cards_inline) else: await bot.send_message(user_id, get_dict('card_check', d)) elif message.text == get_dict('cancel', d): await bot.send_message(user_id, get_dict('section', d), reply_markup=markups.payments(d)) set_user_state(user_id, get_state_by_key('S_PAYMENTS')) else: await bot.send_message(user_id, get_dict('error_enter_amount_p2p', d), reply_markup=markups.cancel(d)) except Exception as e: logger_p2p.error( "/handlers/money_transfer.py\nMethod: enter_amount\n" + str(e))
async def new_card_expiry(message: types.Message): try: user_id = message.from_user.id d = get_lang(user_id) update_log(user_id, get_log(user_id) + message.text) if message.text == get_dict('cancel', d): script = 'UPDATE app_users SET new_card_number=(%s), new_card_expiry=(%s) WHERE user_id=(%s);' cur = conn.cursor() cur.execute(script, ('', '', user_id)) conn.commit() await bot.send_message(user_id, get_dict('section', d), reply_markup=markups.cards_menu(d)) set_user_state(user_id, get_state_by_key('S_CARD_MENU')) elif str(message.text).isdecimal() and len(str(message.text)) == 4: script = 'UPDATE app_users SET new_card_expiry=(%s) WHERE user_id=(%s);' cur = conn.cursor() cur.execute(script, (str(message.text), user_id)) conn.commit() script = 'SELECT new_card_number, new_card_expiry FROM app_users WHERE user_id=(%s);' cur = conn.cursor() cur.execute(script, (str(user_id),)) row = cur.fetchone() respJson = api.authCard(row[0], row[1]) errorCode = respJson['msgrespdata']['errorCode'] if errorCode == '0': await bot.send_message(user_id, get_dict('sms_code', d), reply_markup=markups.cancel(d)) set_session_id(user_id, respJson['msgrespdata']['response']['sessionId']) set_user_state(user_id, get_state_by_key('S_SMS_TYPE_AUTH_CARD')) else: await bot.send_message(user_id, get_dict('error_add_card', d), reply_markup=markups.payments(d)) set_user_state(user_id, get_state_by_key('S_PAYMENTS')) else: await bot.send_message(user_id, get_dict('error_enter_card_expiry', d), reply_markup=markups.cancel(d)) except Exception as e: logger_app.error("/handlers/individual_cards.py\nMethod: new_card_number\n" + str(e))
async def new_card_number(message: types.Message): try: user_id = message.from_user.id d = get_lang(user_id) update_log(user_id, get_log(user_id) + message.text) if message.text == get_dict('cancel', d): script = 'UPDATE app_users SET new_card_number=(%s) WHERE user_id=(%s);' cur = conn.cursor() cur.execute(script, ('', user_id)) conn.commit() await bot.send_message(user_id, get_dict('section', d), reply_markup=markups.cards_menu(d)) set_user_state(user_id, get_state_by_key('S_CARD_MENU')) elif str(message.text).isdecimal() and len(str(message.text)) == 16: script = 'UPDATE app_users SET new_card_number=(%s) WHERE user_id=(%s);' cur = conn.cursor() cur.execute(script, (str(message.text), user_id)) conn.commit() await bot.send_message(user_id, get_dict('add_new_card_expiry', d), reply_markup=markups.cancel(d)) set_user_state(user_id, get_state_by_key('S_NEW_CARD_EXPIRY')) else: await bot.send_message(user_id, get_dict('error_enter_card_number', d), reply_markup=markups.cancel(d)) except Exception as e: logger_app.error("/handlers/individual_cards.py\nMethod: new_card_number\n" + str(e))
async def card_agreement(message: types.Message): try: user_id = message.from_user.id d = get_lang(user_id) update_log(user_id, get_log(user_id) + message.text) if message.text == get_dict('cancel', d): await bot.send_message(user_id, get_dict('section', d), reply_markup=markups.cards_menu(d)) set_user_state(user_id, get_state_by_key('S_CARD_MENU')) elif message.text == get_dict('create_card_next', d): await bot.send_message(user_id, get_dict('add_new_card_number', d), reply_markup=markups.cancel(d)) set_user_state(user_id, get_state_by_key('S_NEW_CARD_NUMBER')) except Exception as e: logger_app.error("/handlers/individual_cards.py\nMethod: card_agreement\n" + str(e))
async def repayment_of_loans(message: types.Message): try: user_id = message.from_user.id d = get_lang(user_id) update_log(user_id, get_log(user_id) + message.text) if message.text == get_dict('back', d): await bot.send_message(user_id, get_dict('main_menu_hint', d), reply_markup=markups.payments(d)) set_user_state(user_id, get_state_by_key('S_PAYMENTS')) elif message.text == get_dict('repayment_of_loans_bank_type_hamkorbank', d): await bot.send_message(user_id, get_dict('repayment_of_loans_id', d), reply_markup=markups.cancel(d)) set_user_state(user_id, get_state_by_key('S_REPAYMENT_OF_LOANS_HAMKORBANK')) elif message.text == get_dict('repayment_of_loans_bank_type_other', d): await bot.send_message(user_id, get_dict('repayment_of_loans_id', d), reply_markup=markups.cancel(d)) set_user_state(user_id, get_state_by_key('S_REPAYMENT_OF_LOANS_HAMKORBANK')) else: await bot.send_message(user_id, get_dict('section', d)) except Exception as e: logger_app.error("/handlers/payments.py\nMethod: repayment_of_loans\n"+str(e))
async def repayment_of_loans_hamkorbank_id(message: types.Message): try: user_id = message.from_user.id d = get_lang(user_id) update_log(user_id, get_log(user_id) + message.text) if message.text == get_dict('cancel', d): await bot.send_message(user_id, get_dict('section', d), reply_markup=markups.repayment_of_loans_bank_type(d)) set_user_state(user_id, get_state_by_key('S_REPAYMENT_OF_LOANS')) elif str(message.text).isdecimal(): await bot.send_message(user_id, get_dict('repayment_of_loans_password', d), reply_markup=markups.cancel(d)) set_user_state(user_id, get_state_by_key('S_REPAYMENT_OF_LOANS_PASSWORD')) else: await bot.send_message(user_id, get_dict('error_enter_amount_p2p', d)) set_user_state(user_id, get_state_by_key('S_REPAYMENT_OF_LOANS_HAMKORBANK')) except Exception as e: logger_app.error("/handlers/payments.py\nMethod: repayment_of_loans_hamkorbank_id\n"+str(e))