def payment_method_processor(message: Message): chat_id = message.chat.id user_id = message.from_user.id language = userservice.get_user_language(user_id) current_order = orderservice.get_current_order_by_user(user_id) def error(): error_msg = strings.get_string('order.payment_error', language) bot.send_message(chat_id, error_msg) bot.register_next_step_handler_by_chat_id(chat_id, payment_method_processor) def phone_number(): current_order = orderservice.set_phone_number(user_id) _to_the_confirmation(chat_id, current_order, language) if not message.text: error() return if strings.get_string('go_to_menu', language) in message.text: botutils.to_main_menu(chat_id, language) elif strings.get_string('go_back', language) in message.text: if current_order.shipping_method == Order.ShippingMethods.PICK_UP: back_to_the_catalog(chat_id, language) elif current_order.shipping_method == Order.ShippingMethods.DELIVERY: back_to_the_catalog(chat_id, language) elif strings.from_order_payment_method(Order.PaymentMethods.CASH, language) in message.text: orderservice.set_payment_method(user_id, Order.PaymentMethods.CASH) phone_number() else: error()
def count_processor(message): chat_id = message.chat.id user_id = message.from_user.id language = userservice.get_user_language(user_id) def error(): error_message = strings.get_string('catalog.dish_action_error', language) bot.send_message(chat_id, error_message) bot.register_next_step_handler_by_chat_id(chat_id, count_processor) if strings.get_string('go_back', language) in message.text: botutils.to_main_menu(chat_id, language) return if not message.text.isdigit() or int(message.text) >= 11 or int( message.text) <= 0: error() return userservice.clear_user_cart(user_id) userservice.add_dish_to_cart(user_id, dishservice.get_dish_by_id(1), int(message.text)) orderservice.make_an_order(user_id) orderservice.set_shipping_method(user_id, Order.ShippingMethods.PICK_UP) orderservice.set_payment_method(user_id, Order.PaymentMethods.CASH) orderservice.set_phone_number(user_id) current_order = orderservice.get_current_order_by_user(user_id) _to_the_confirmation(chat_id, current_order, language)
def _to_the_payment_method(chat_id, language, user_id: int): current_order = orderservice.get_current_order_by_user(user_id) if current_order.shipping_method == Order.ShippingMethods.PICK_UP: payment_message = strings.get_string('order.payment_pickup', language) else: payment_message = strings.get_string('order.payment_delivery', language) payment_keyboard = keyboards.get_keyboard('order.payment', language) bot.send_message(chat_id, payment_message, reply_markup=payment_keyboard, parse_mode='HTML') bot.register_next_step_handler_by_chat_id(chat_id, payment_method_processor)
def order_processor(message: Message): chat_id = message.chat.id user_id = message.from_user.id language = userservice.get_user_language(user_id) orderservice.make_an_order(user_id) orderservice.set_shipping_method(user_id, Order.ShippingMethods.PICK_UP) orderservice.set_payment_method(user_id, Order.PaymentMethods.CASH) orderservice.set_phone_number(user_id) current_order = orderservice.get_current_order_by_user(user_id) _to_the_confirmation(chat_id, current_order, language)
def payment_method_processor(message: Message): chat_id = message.chat.id user_id = message.from_user.id language = userservice.get_user_language(user_id) current_order = orderservice.get_current_order_by_user(user_id) def error(): if message.text == '/start': registration.welcome(message) return error_msg = strings.get_string('order.payment_error', language) bot.send_message(chat_id, error_msg) bot.register_next_step_handler_by_chat_id(chat_id, payment_method_processor) def phone_number(): _to_the_phone_number(chat_id, language, current_order.customer) if not message.text: error() return if strings.get_string('go_to_menu', language) in message.text: back_to_the_catalog(chat_id, language) elif strings.get_string('go_back', language) in message.text: if current_order.shipping_method == Order.ShippingMethods.PICK_UP: _to_the_shipping_method(chat_id, language) elif current_order.shipping_method == Order.ShippingMethods.DELIVERY: _to_the_address(chat_id, language) elif strings.from_order_payment_method(Order.PaymentMethods.CASH, language) in message.text: orderservice.set_payment_method(user_id, Order.PaymentMethods.CASH) phone_number() elif strings.from_order_payment_method(Order.PaymentMethods.OtherPAYME, language) in message.text: orderservice.set_payment_method(user_id, Order.PaymentMethods.OtherPAYME) phone_number() elif strings.from_order_payment_method(Order.PaymentMethods.PAYME, language) in message.text: orderservice.set_payment_method(user_id, Order.PaymentMethods.PAYME) phone_number() elif strings.from_order_payment_method(Order.PaymentMethods.CLICK, language) in message.text: orderservice.set_payment_method(user_id, Order.PaymentMethods.CLICK) phone_number() else: error()