Example #1
0
def collect_cart_card(cart_name):
    cart_price = moltin_aps.get_cart(
        cart_name)['meta']['display_price']['with_tax']['formatted']
    return {
        'title':
        f'Ваш заказ на сумму {cart_price}',
        'image_url':
        'https://postium.ru/wp-content/uploads/2018/08/idealnaya-korzina-internet-magazina-1068x713.jpg',
        'subtitle':
        'Выберите опцию:',
        'buttons': [
            {
                'type': 'postback',
                'title': 'Самовывоз',
                'payload': 'pickup',
            },
            {
                'type': 'postback',
                'title': 'Доставка',
                'payload': 'delivery',
            },
            {
                'type': 'postback',
                'title': 'К меню',
                'payload': 'menu',
            },
        ]
    }
Example #2
0
async def notify_deliveryman(deliveryman_id, customer_cart_name,
                             delivery_price, lat, lon):
    cart_items = moltin_aps.get_cart_items(customer_cart_name)
    text = f'Заказ от {customer_cart_name}:\n'
    for item in cart_items:
        text += dedent(f'''\
            {item['name']}
            {item['quantity']} шт. в корзине на сумму {item['meta']['display_price']['with_tax']['value']['formatted']}\n
        ''')
    cart_price = moltin_aps.get_cart(
        customer_cart_name)['meta']['display_price']['with_tax']['amount']
    total_price = int(cart_price) + int(delivery_price)
    text += f'Всего: {total_price} ₽'
    await delivery_bot.send_message(deliveryman_id, text)
    await delivery_bot.send_location(deliveryman_id, lat, lon)
Example #3
0
async def collect_full_cart(cart_items, cart_name, keyboard):
    text = 'In your cart:\n\n'
    for item in cart_items:
        total_price = moltin_aps.get_cart(cart_name)['meta']['display_price']['with_tax']['formatted']
        product_name = item['name']
        item_id = item['id']
        text += dedent(f'''\
            {product_name}
            {item['description']}
            {item['meta']['display_price']['with_tax']['unit']['formatted']} per kg
            {item['quantity']}kg in cart for {item['meta']['display_price']['with_tax']['value']['formatted']}\n
        ''')
        keyboard.add(InlineKeyboardButton(f'Remove {product_name}', callback_data=item_id))
    text += f'Total: {total_price}'
    tg_logger.debug('Cart was collected')
    return text, keyboard
Example #4
0
async def handle_payment(callback_query: types.CallbackQuery):
    user_id = callback_query.message.chat.id
    goods_price = moltin_aps.get_cart(
        f'tg-{user_id}')['meta']['display_price']['with_tax']['amount']
    delivery_price = callback_query.data.split(',')[1]
    total_price = goods_price + int(delivery_price)
    date = int(callback_query.message.date.timestamp())
    await bot.send_invoice(
        user_id,
        title='Оплата заказа',
        description='Тестовая оплата заказа',
        provider_token=os.environ['TG_BOT_PAYMENT_TOKEN'],
        currency='rub',
        prices=[types.LabeledPrice(label='rub', amount=total_price * 100)],
        start_parameter=f'{user_id}-{date}',
        payload=f'payment-{user_id}-{date}-{total_price}')
    await callback_query.answer('Оплатите заказ')
    await callback_query.message.edit_reply_markup()
    return 'WAITING_ADDRESS'
Example #5
0
async def collect_full_cart(cart_items, cart_name, keyboard):
    text = 'Товары в вашей корзине:\n\n'
    total_price = moltin_aps.get_cart(
        cart_name)['meta']['display_price']['with_tax']['formatted']
    for item in cart_items:
        product_name = item['name']
        item_id = item['id']
        text += dedent(f'''\
            {product_name}
            {item['description']}
            {item['meta']['display_price']['with_tax']['unit']['formatted']} за шт.
            {item['quantity']} шт. в корзине на {item['meta']['display_price']['with_tax']['value']['formatted']}\n
        ''')
        keyboard.add(
            InlineKeyboardButton(f'Убрать {product_name}',
                                 callback_data=item_id))
    text += f'Всего: {total_price}'
    tg_logger.debug('Cart was collected')
    return text, keyboard