コード例 #1
0
async def sms(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.payments(d))
            set_user_state(user_id, get_state_by_key('S_PAYMENTS'))
        else:
            sessionId = get_session_id(user_id)
            confirmCode = str(message.text)
            errorCode = (api.confirmOperationAuthCard(
                sessionId, confirmCode))['msgrespdata']['errorCode']
            if errorCode == '0':
                await bot.send_message(user_id,
                                       get_dict(
                                           'success_transfer_card_to_card', d),
                                       reply_markup=markups.payments(d))
                set_p2p_info((get_p2p_oper_id(user_id)[0]), 'Success', 'To'
                             'lov amalga oshirildi', str(dt.datetime.now()))
                set_user_state(user_id, get_state_by_key('S_PAYMENTS'))
            else:
                await bot.send_message(user_id,
                                       get_dict('error_transfer_card_to_card',
                                                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/individual_cards.py\nMethod: new_card_number\n" +
            str(e))
コード例 #2
0
async def main_menu(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('individual', d):
            await bot.send_message(user_id,
                                   get_dict('individual_hint', d),
                                   reply_markup=markups.individual(d))
            set_user_state(user_id, get_state_by_key('S_INDIVIDUAL'))
        elif message.text == get_dict('legal_entity', d):
            await bot.send_message(user_id,
                                   get_dict('legal_entity_hint', d),
                                   reply_markup=markups.legal_entity(d))
            set_user_state(user_id, get_state_by_key('S_LEGAL_ENTITY'))
        elif message.text == get_dict('payments', 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 message.text == get_dict('news', d):
            await bot.send_message(user_id, get_news(d))
        elif message.text == get_dict('general', d):
            await bot.send_message(user_id,
                                   get_dict('general_hint', d),
                                   reply_markup=markups.general(d))
            set_user_state(user_id, get_state_by_key('S_GENERAL'))
        elif message.text == get_dict('settings', d):
            await bot.send_message(user_id,
                                   get_dict('section', d),
                                   reply_markup=markups.settings(d))
            set_user_state(user_id, get_state_by_key('S_SETTINGS'))
        elif message.text == get_dict('contact_bank', d):
            if markups.buttons(d, 'feedback')["keyboard"][0][0] is None or \
                    markups.buttons(d, 'feedback')["keyboard"][0][0] == '':
                set_user_state(user_id, get_state_by_key('S_GET_MAIN_MENU'))
                if get_buttons(d, 'feedback')[0][4]:
                    await bot.send_message(
                        user_id,
                        get_buttons(d, 'feedback')[0][2],
                        reply_markup=markups.inline_keyboards(
                            d, 'feedback',
                            get_buttons(d, 'feedback')[0][0]))
                else:
                    await bot.send_message(user_id,
                                           get_buttons(d, 'feedback')[0][2])
            else:
                await bot.send_message(user_id,
                                       get_dict('section', d),
                                       reply_markup=markups.buttons(
                                           d, 'feedback'))
                set_user_state(user_id, get_state_by_key('S_FEEDBACK'))
        else:
            await bot.send_message(user_id, get_dict('main_menu_hint', d))
    except Exception as e:
        logger_app.error("/handlers/bot.py\nMethod: main_menu\n" + str(e))
コード例 #3
0
async def p2p(callback_query: types.CallbackQuery):
    try:
        user_id = callback_query.from_user.id
        d = get_lang(user_id)
        key = load_key()
        f = Fernet(key)

        encoded_card = get_card_encode(user_id, callback_query.data[3:])
        decrypted_card = f.decrypt(
            bytes((encoded_card[0])[2:-1], encoding='utf8'))
        balance = api.getCardBalance(decrypted_card.decode(), encoded_card[1])

        set_p2p_from_user_card((get_p2p_oper_id(user_id)[0]),
                               callback_query.data[3:])
        if float(get_amount_from_user_p2p_oper(user_id)[0]) >= (
                float(balance['msgrespdata']['response']['balance']) / 100):
            set_p2p_info((get_p2p_oper_id(user_id)[0]),
                         'Error: Unsufficient funds', 'Mablag'
                         ' yetarli emas', str(dt.datetime.now()))
            await bot.send_message(callback_query.from_user.id,
                                   get_dict('insufficient_funds', d))
            await bot.edit_message_text(
                chat_id=callback_query.message.chat.id,
                message_id=callback_query.message.message_id,
                text=get_dict('section', d),
                reply_markup=markups.payments(d))
            set_user_state(user_id, get_state_by_key('S_PAYMENTS'))
        else:
            access = InlineKeyboardMarkup().add(
                InlineKeyboardButton(get_dict('confirm', d),
                                     callback_data="access" +
                                     callback_query.data[3:]))
            res = get_dict(
                'confirm_transfer_card_to_card',
                d) + ' ' + callback_query.data[3:] + "\n" + get_dict(
                    'to_card', d
                ) + ' ' + get_to_card_p2p_oper(user_id)[0] + '\n' + get_dict(
                    'amount', d) + ' ' + "{:,.2f}".format(
                        (int(get_amount_from_user_p2p_oper(user_id)[0])
                         )) + ' ' + get_dict('sum', d)

            await bot.edit_message_text(
                chat_id=callback_query.message.chat.id,
                message_id=callback_query.message.message_id,
                text=res,
                reply_markup=access)
    except Exception as e:
        logger_p2p.error("/handlers/money_transfer.py\nMethod: p2p\n" + str(e))
コード例 #4
0
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))
コード例 #5
0
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))
コード例 #6
0
async def card_menu(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('balance', d):
            cards_list = get_all_cards(user_id)
            res = ''
            if len(cards_list) > 0:
                key = load_key()
                f = Fernet(key)
                res = get_dict('card_balance', d) + '\n\n'
                for row in cards_list:
                    decrypted_card = f.decrypt(bytes((row[2])[2:-1], encoding='utf8'))
                    balance = api.getCardBalance(decrypted_card.decode(), row[1])
                    if balance['msgrespdata']['errorCode'] == '0':
                        res = res + "💳 " + row[0] + '\n💰' + "{:,.2f}".format(
                            (int(balance["msgrespdata"]["response"]["balance"]) / 100)) + ' ' + get_dict('sum',
                                                                                                         d) + '\n\n'
                await bot.send_message(user_id, res)
            else:
                await bot.send_message(user_id, get_dict('card_check', d))
        elif message.text == get_dict('statement', d):
            await bot.send_message(user_id, get_dict('developing', d))
        elif message.text == get_dict('block', d):
            await bot.send_message(user_id, get_dict('developing', d))
        elif message.text == get_dict('add_new_card', d):
            await bot.send_message(user_id, get_dict('create_card_agreement', d), reply_markup=markups.create_card_agreement(d))
            set_user_state(user_id, get_state_by_key('S_CREATE_CARD_AGREEMENT'))
            files_list = os.listdir(config['OFFER_PATH']['path']+d)
            for i in files_list:
                file = open(config['OFFER_PATH']['path'] + d + '/' + i, 'rb')
                await bot.send_document(user_id, file)
        elif message.text == get_dict('main_menu', 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('back', 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('section', d))
    except Exception as e:
        logger_app.error("/handlers/individual_cards.py\nMethod: card_menu\n" + str(e))
コード例 #7
0
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))
コード例 #8
0
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))
コード例 #9
0
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))
コード例 #10
0
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))
コード例 #11
0
async def sms(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'))
        else:
            sessionId = get_session_id(user_id)
            confirmCode = str(message.text)
            errorCode = (api.confirmOperationAuthCard(sessionId, confirmCode))['msgrespdata']['errorCode']

            if errorCode == '0':
                cards = ''
                key = load_key()
                encoded_card_number = (get_card(user_id)[0]).encode()
                f = Fernet(key)
                encrypted_card_number = f.encrypt(encoded_card_number)
                card_mask = (get_card(user_id)[0])[:6] + '*' * 6 + (get_card(user_id)[0])[-4:]
                authCard(user_id, card_mask, get_card(user_id)[1], str(encrypted_card_number))

                await bot.send_message(user_id, get_dict('added_new_card', d) + '\n',
                                       reply_markup=markups.cards_menu(d))
                cardsList = get_card_json(user_id)
                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))
                cards = ''
                set_user_state(user_id, get_state_by_key('S_CARD_MENU'))
            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'))
    except Exception as e:
        logger_app.error("/handlers/individual_cards.py\nMethod: new_card_number\n" + str(e))
コード例 #12
0
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))