Exemplo n.º 1
0
def handle_cart(bot, update):
    query = update.callback_query
    button = query.data
    if button == 'menu':
        return send_menu(bot, update)
    elif button == 'checkout':
        return send_location_request(bot, update)
    else:
        chat_id = update.callback_query.message.chat_id
        cart_item_id = button
        remove_cart_item(chat_id, cart_item_id)
        bot.answer_callback_query(query.id,
                                  text=f'Пица удалена из корзины',
                                  show_alert=False)
        return send_cart(bot, update)
Exemplo n.º 2
0
def handle_cart(update, context, db, token):
    query = update.callback_query
    chat_id = query.message.chat_id
    user_cart = f'{chat_id}_cart'

    if 'remove' in query.data:
        product_id = query.data.split(',')[1]
        moltin.remove_cart_item(token=token,
                                product_id=product_id,
                                chat_id=chat_id)

    reply_markup, message, cart = tg_keyboard.get_cart_reply(
        moltin_token, chat_id)
    db.set(user_cart, json.dumps(cart))
    query.edit_message_text(text=message, reply_markup=reply_markup)

    return 'HANDLE_CART'
def send_remove_from_cart_message(sender_id, message, token, user, item_id):
    moltin.remove_cart_item(token, user, item_id)
    params = {'access_token': env('PAGE_ACCESS_TOKEN')}
    headers = {'Content-Type': 'application/json'}
    text = f'Убрана из корзины'
    request_content = {
        "recipient": {
            "id": sender_id
        },
        "message": {
            "text": text
        }
    }
    url = 'https://graph.facebook.com/v2.6/me/messages'
    response = requests.post(url,
                             params=params,
                             headers=headers,
                             json=request_content)
    response.raise_for_status()
Exemplo n.º 4
0
def handle_cart(bot, update):
    query = update.callback_query
    button = query.data
    logger.debug(f'BUTTON {button} pressed')
    if button == 'menu':
        return send_menu(bot, update)
    if button == 'checkout':
        bot.edit_message_text(text='Пришлите email',
                              chat_id=query.message.chat_id,
                              message_id=query.message.message_id)
        return 'WAITING_EMAIL'
    else:
        chat_id = update.callback_query.message.chat_id
        cart_item_id = button
        remove_cart_item(chat_id, cart_item_id)
        bot.answer_callback_query(query.id,
                                  text=f'removed from cart',
                                  show_alert=False)
        return send_cart(bot, update)
Exemplo n.º 5
0
def handle_cart(bot, update):
    query = update.callback_query
    chat_id = query.message.chat_id
    message_id = query.message.message_id

    if query.data == 'menu':
        return start(bot, update)

    elif query.data == 'pay':
        bot.send_message(chat_id=chat_id,
                         text='Пожалуйста, пришлите ваш email:')
        bot.delete_message(chat_id=chat_id, message_id=message_id)
        return 'HANDLE_WAITING_EMAIL'

    product_id = query.data
    token = moltin_token()
    moltin.remove_cart_item(token, chat_id, product_id)

    send_cart_keyboard(bot, chat_id)
    bot.delete_message(chat_id=chat_id, message_id=message_id)
    return 'HANDLE_CART'