def address_processor(message: Message): chat_id = message.chat.id user_id = message.from_user.id language = userservice.get_user_language(user_id) def error(): error_msg = strings.get_string('order.address_error') bot.send_message(chat_id, error_msg, parse_mode='HTML') bot.register_next_step_handler_by_chat_id(chat_id, address_processor) orderservice.make_an_order(user_id) orderservice.set_shipping_method(user_id, Order.ShippingMethods.DELIVERY) if message.text: if strings.get_string('go_back', language) in message.text: back_to_the_catalog(chat_id, language) return error() return #orderservice.set_address_by_string(user_id, message.text) #_to_the_payment_method(chat_id, language, user_id) elif message.location: location = message.location result = orderservice.set_address_by_map_location( user_id, (location.latitude, location.longitude)) if result: _to_the_payment_method(chat_id, language, user_id) else: error() else: error()
def shipping_method_processor(message: Message): chat_id = message.chat.id user_id = message.from_user.id language = userservice.get_user_language(user_id) def error(): error_msg = strings.get_string('order.shipping_method_error', language) bot.send_message(chat_id, error_msg) bot.register_next_step_handler_by_chat_id(chat_id, shipping_method_processor) if not message.text: error() return orderservice.make_an_order(user_id) if strings.get_string('go_to_menu', language) in message.text: back_to_the_catalog(chat_id, language) elif strings.from_order_shipping_method(Order.ShippingMethods.PICK_UP, language) in message.text: orderservice.set_shipping_method(user_id, Order.ShippingMethods.PICK_UP) _to_the_payment_method(chat_id, language, user_id) elif strings.from_order_shipping_method(Order.ShippingMethods.DELIVERY, language) in message.text: orderservice.set_shipping_method(user_id, Order.ShippingMethods.DELIVERY) _to_the_address(chat_id, language) else: error() return
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 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 _to_the_payment_method(chat_id, language, user_id: int): orderservice.make_an_order(user_id) orderservice.set_shipping_method(user_id, Order.ShippingMethods.PICK_UP) 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)