Exemple #1
0
async def pay_in(call: CallbackQuery, state: FSMContext):
    data = call.data
    print(data)
    parcel_num = data.replace('pay_data_in', '')
    get_data = get_payment_data(parcel_num, "")
    print(get_data)
    print(get_data)
    split_pay = get_data['split_pay']
    shipment_uid = get_data['shipment_uid']
    # pay_type = get_data['type']
    description = get_data['description']
    total_amount = my_parcel_debt(shipment_uid)
    print(total_amount)
    total_to_pay = total_amount['Total']
    pay_link = pay_by_portmone_my_parcels(parcel_num, total_to_pay, split_pay,
                                          shipment_uid, description)
    pay_button = types.InlineKeyboardMarkup(row_width=2)
    pay_button.insert(
        types.InlineKeyboardButton(text=f"💸 Оплатити {total_to_pay} грн",
                                   callback_data="pay_my_parcel_in",
                                   url=pay_link))
    # pay_button.insert(types.InlineKeyboardButton(text="Підтверджую оплату", callback_data="my_parcels_pay_confirm"))
    pay_button.add(
        types.InlineKeyboardButton(text="Відмінити дію",
                                   callback_data="Cancel3"))
    await call.message.edit_reply_markup(reply_markup=pay_button)
    # await call.message.edit_text(description, parse_mode=types.ParseMode.HTML, reply_markup=pay_button)
    # await bot.edit_message_reply_markup(call.from_user.id, call.message.message_id, reply_markup=pay_button)
    await state.finish()
async def pay_checkout_out_query(call: CallbackQuery, state: FSMContext):
    data = await state.get_data()
    print(data)
    parcel_id_out = data['parcel_id_out']
    parcel_res = my_parcel_debt(parcel_id_out)
    res_amount = parcel_res['Total']
    pay_link_out = data['pay_link_out']  # раскоментить
    if parcel_res == 0:
        await call.message.delete()
        await call.answer("Посилка оплачена", show_alert=True)
        token_receiver = get_token_receiver(parcel_id_out)
        await state.update_data(token_receiver=token_receiver)
        await call.message.answer(
            hbold(
                "На Ваш мобільний телефон буде відправлено СMC з кодом варіфікації введіть його в телеграм"
            ))
        return await ParcelTake.Take3.set()
    if res_amount != 0:
        pay_button = types.InlineKeyboardMarkup(row_width=2)
        pay_button.add(
            types.InlineKeyboardButton(text=f"💸 Оплатити {res_amount} грн",
                                       callback_data="pay_out",
                                       url=pay_link_out))
        pay_button.add(
            types.InlineKeyboardButton(text="Підтверджую оплату",
                                       callback_data="payment_confirm_out"))
        await call.answer(call.from_user.first_name +
                          ", Ваша посилка ще не оплачена",
                          show_alert=True)
        pay_button.add(
            types.InlineKeyboardButton(text="До головного меню",
                                       callback_data="Cancel3"))
        return await call.message.edit_reply_markup(reply_markup=pay_button)
Exemple #3
0
async def pay_checkout_query(call: CallbackQuery, state: FSMContext):
    # await call.answer(cache_time=30)
    data = await state.get_data()
    parcel_id = data['parcel_id_in']
    parcel_res = my_parcel_debt(parcel_id)
    res_amount = parcel_res['Total']
    print(parcel_res)
    # await call.message.answer(f"РЕЗУЛЬТАТ{parcel_res}")
    pay_link = data['pay_link_in']  # раскоментить
    if res_amount == 0:
        await call.message.delete()
        await call.answer(call.from_user.first_name +
                          hcode(", Ваша посилка оплачена"),
                          show_alert=True)
        token_sender = get_token_sender(parcel_id)
        await state.update_data(token_sender=token_sender)
        await call.message.answer(hbold(
            "На Ваш мобільний телефон буде відправлено СMC з кодом варіфікації введіть його в телеграм"
        ),
                                  parse_mode=types.ParseMode.HTML)
        await ParcelInsert.Insert3.set()
    if res_amount != 0:
        pay_button = types.InlineKeyboardMarkup(row_width=2)
        pay_button.add(
            types.InlineKeyboardButton(text=f"💸 Оплатити {res_amount} грн",
                                       callback_data="pay",
                                       url=pay_link))
        pay_button.add(
            types.InlineKeyboardButton(text="Підтверджую оплату",
                                       callback_data="payment_confirm"))
        await call.answer(call.from_user.first_name +
                          ", Ваша посилка ще не оплачена",
                          show_alert=True)
        # pay_button.add(types.InlineKeyboardButton(text="До головного меню", callback_data="Cancel3"))
        return await call.message.edit_reply_markup(reply_markup=pay_button)
async def choose_out(call: CallbackQuery, state: FSMContext):
    await call.answer(cache_time=60)
    parcel_id = call.data
    print(call.data)
    print("Попало в хендлер получить")
    await state.update_data(parcel_id_out=parcel_id)
    data = await state.get_data()
    # post_num = data['num']
    r = list(filter(lambda x: x['id'] == parcel_id, data['choose_out_result']))
    if r:
        num = r[0]['num']
        await state.update_data(parcel_num=num)
        # await state.update_data(choose_out_result=None)
    else:
        print("НЕ нашел")
        return await state.finish()
    parcel_res = parcel_debt(parcel_id, call.from_user.first_name)
    print(parcel_res)
    if parcel_res is True:
        await call.message.answer(hbold("Посилка оплачена"))
        token_receiver = get_token_receiver(parcel_id)
        await state.update_data(token_receiver=token_receiver)
        print(data)
        # await call.message.answer(f"{parcel_debt(parcel_id, call.from_user.first_name)}")
        await call.message.answer(
            hbold(
                "На Ваш мобільний телефон буде відправлено СMC з кодом варіфікації введіть його в телеграм"
            ))
        await ParcelTake.Take3.set()
    else:
        data = await state.get_data()
        parcel_num = data['parcel_num']
        amount = parcel_res['result']['Total']
        get_data = get_payment_data(parcel_num, amount)
        print(get_data)
        split_pay = get_data['split_pay']
        shipment_uid = get_data['shipment_uid']
        # pay_type = get_data['type']
        description = get_data['description']
        total_amount = my_parcel_debt(shipment_uid)
        total_to_pay = total_amount['Total']
        pay_link_out = pay_by_portmone_my_parcels(parcel_num, total_to_pay,
                                                  split_pay, shipment_uid,
                                                  description)
        print(pay_link_out)
        await state.update_data(pay_link_in=pay_link_out)  # Раскоментить
        pay_button = types.InlineKeyboardMarkup(row_width=2)
        pay_button.add(
            types.InlineKeyboardButton(text=f"💸 Оплатити {amount} грн",
                                       callback_data="pay_out",
                                       url=pay_link_out))
        pay_button.add(
            types.InlineKeyboardButton(text="Підтверджую оплату",
                                       callback_data="payment_confirm_out"))
        # pay_button.add(types.InlineKeyboardButton(text="До головного меню", callback_data="Cancel3"))
        # await call.message.delete()
        await call.message.edit_reply_markup(reply_markup=pay_button)
        await ParcelTake.Take2.set()