Пример #1
0
def make_pay_penalty(request, id_penalty):
    if request.user.is_anonymous or not request.user.is_active:
        return HttpResponseRedirect("/login")

    my_pens = models.DonePenalty.objects.filter(id_user_for=request.user.id)
    pen = models.DonePenalty.objects.get(id=id_penalty)

    user_from = models.MyUser.objects.get(id=pen.id_user_for)
    user_to = models.MyUser.objects.get(is_admin=True)
    c, m = t.Transaction(pen.size_penalty, user_from,
                         user_to, False).make_transaction()

    mes = "Штраф не оплачен."
    if c:
        models.LogOperationsBalance.objects.create(id_user=request.user.id,
                                                   type_operation=pen.describe_penalty,
                                                   describe_operation="Оплата штрафа на сумму " +
                                                                      str(pen.size_penalty) + " BYN. " + str(m),
                                                   date_operation=date.today(),
                                                   amount=pen.size_penalty, status=True)
        pen.is_payd = True
        pen.save()
        mes = "Штраф оплачен."

    return render(request, 'Profile/Thanks.html',
                  {'pen': my_pens, 'mes': mes + " " + m, 'stat': m})
Пример #2
0
def refill_balance_admin(request, id_user):
    if request.user.is_anonymous or not request.user.is_admin and not request.user.is_moder:
        return HttpResponseRedirect("/login")

    error = ''
    if request.method == 'POST':
        form = RefillBalance(request.POST)

        if form.is_valid():
            card_num = form.cleaned_data['card_num']
            period_validity = form.cleaned_data['period_validity']
            name_card_owner = form.cleaned_data['name_card_owner']
            CVC2_CVV = form.cleaned_data['CVC2_CVV']
            size = form.cleaned_data['size']
            user = models.MyUser.objects.get(id=id_user)

            if t.Check(card_num, period_validity, name_card_owner,
                       CVC2_CVV).check_card():
                c, m = t.Transaction(size, card_num, user).make_transaction()

                # Логирование операции пополнения баланса
                models.LogOperationsBalance.objects.create(
                    id_user=request.user.id,
                    type_operation='Пополнение баланса',
                    describe_operation="Баланс успешно пополнен на " +
                    str(size) + " BYN",
                    date_operation=datetime.date.today())
                if c:
                    mes = request.user.name + ", баланс пользователя " + user.username + ", успешно пополнен на " + str(
                        size) + " BYN."
                else:
                    mes = m
                return render(request, 'Admin/Done.html', {'message': mes})
            else:
                return render(request, 'Admin/Done.html',
                              {'message': 'Введены неверные данные!'})

        else:
            err = form.errors.as_data()
            print(err)
            if 'card_num' in err:
                error = 'Номер карты должен содержать только цифры!'
            if 'period_validity' in err:
                error = 'Срок действия карты указан неверно!(Пример: 12/17)'
            if 'name_card_owner' in err:
                error = 'В поле Имя держателя карты введены недопустимые символы!'
            if 'CVC2_CVV' in err:
                error = 'В поле CVC2_CVV введены недопустимые символы!'
            if 'size' in err:
                error = 'Сумма может быть от 10 BYN до 1млн BYN!'

    else:
        form = RefillBalance()
    return render(request, "Admin/RefillBalanceAdmin.html", {
        'form': form,
        'error': error
    })
Пример #3
0
def refillBalance(request):
    if request.user.is_anonymous or not request.user.is_active:
        return HttpResponseRedirect("/login")

    if request.method == 'GET':
        cards = list()
        for card in [str(i.card_num) for i in request.user.user_card_id.all()]:
            cards.append(card[:4] + ' XXXX XXXX ' + card[-4:])
        user_cards = request.user.user_card_id.all()
        c = [[i, j] for i, j in zip(cards, user_cards)]
        return render(request, "Profile/RefillBalance.html", {'cards': c, 'type': request.GET['type']})
    elif request.method == 'POST':
        try:
            request.user.user_card_id.get(card_num=request.POST['card_from'])
        except:
            return HttpResponse(json.dumps({'message': 'Карта не найдена', 'status': False}, ensure_ascii=False),
                                content_type="text/html; charset=utf-8")
        if int(request.POST['type']):
            c, m = t.Transaction(request.POST['size'], request.POST['card_from'],
                                 request.user, False).make_transaction()
        else:
            c, m = t.Transaction(request.POST['size'], request.user,
                                 request.POST['card_from'], False).make_transaction()
        response = {"message": m, "status": c}
        if int(request.POST['type']):
            models.LogOperationsBalance.objects.create(id_user=request.user.id, type_operation='Пополнение баланса',
                                                       describe_operation="Пополнение баланса на сумму " +
                                                                          str(request.POST['size']) + " BYN. " + str(m),
                                                       date_operation=date.today(), status=c,
                                                       amount=request.POST['size'])
            sm.Sender("Пополнение баланса",
                      "Пополнение баланса на сумму " + str(request.POST['size']) + " BYN. " + str(m),
                      request.user.email).sender()
        else:
            models.LogOperationsBalance.objects.create(id_user=request.user.id, type_operation='Снятие средств',
                                                       describe_operation="Снятие средств на сумму " +
                                                                          str(request.POST['size']) + " BYN. " + str(m),
                                                       date_operation=date.today(), status=c,
                                                       amount=request.POST['size'])
            sm.Sender("Снятие средств", "Снятие средств на сумму " + str(request.POST['size']) + " BYN. " + str(m),
                      request.user.email).sender()

        response = json.dumps(response, ensure_ascii=False)
        return HttpResponse(response, content_type="text/html; charset=utf-8")
Пример #4
0
def quick_payment_info(request, id):
    if request.user.is_anonymous or not request.user.is_active:
        return HttpResponseRedirect("/login")

    if request.method == 'GET':
        try:
            payment = models.QuickPayment.objects.get(id=id)
            rent = models.Rent.objects.get(id=models.DoneRent.objects.get(id=payment.rent_id).id_house.id)
            return render(request, 'Profile/QuickPaymentInfo.html', {'payment': payment, 'rent': rent})
        except models.QuickPayment.DoesNotExist:
            return HttpResponseRedirect('/profile/quickpayment')
        except models.Rent.DoesNotExist:
            return HttpResponseRedirect('/profile/quickpayment')
    else:
        payment = models.QuickPayment.objects.get(id=id)
        if payment.user_payment == 'Кошелек':
            tr_from = request.user
        else:
            tr_from = models.UserCard.objects.get(card_num=payment.user_payment)
        tr_to = models.MyUser.objects.get(
            id=models.Rent.objects.get(id=models.DoneRent.objects.get(id=payment.rent_id).id_house.id).user_login.id)
        c, m = t.Transaction(payment.amount, tr_from, tr_to).make_transaction()
        if c:
            q_pay = models.QuickPayment.objects.get(id=id)
            t.PaymentManager(q_pay.amount, models.DoneRent.objects.get(id=q_pay.rent_id)).run()
        models.LogOperationsBalance.objects.create(id_user=request.user.id,
                                                   type_operation='Выполнение быстрого платежа № ' + str(id),
                                                   describe_operation="Оплата на сумму " + str(payment.amount) +
                                                                      " BYN. " + str(m), amount=payment.amount,
                                                   date_operation=date.today(), status=True)
        done_rent = models.DoneRent.objects.get(id=q_pay.rent_id)
        rent = done_rent.id_house_id
        rrrent = models.Rent.objects.get(id=rent)
        mail_to = models.MyUser.objects.get(id=rrrent.user_login_id).email
        sm.Sender("Оплата аренды с помощью автоматического платежа",
                  "Оплата аренды №" + str(rrrent.id) + " на сумму " +
                  str(payment.amount) + " BYN. " + str(m), request.user.email).sender()

        models.LogOperationsBalance.objects.create(id_user=rrrent.user_login_id,
                                                   type_operation='Получение оплаты за аренду',
                                                   describe_operation="Получение оплаты на аренды дома № " +
                                                                      str(rrrent.id) + " на сумму " +
                                                                      str(payment.amount) + " BYN. " +
                                                                      str(m), date_operation=date.today(),
                                                   status=True, amount=payment.amount)
        sm.Sender("Оплата аренды с помощью автоматического платежа",
                  "Получение оплаты аренды №" + str(rrrent.id) + " на сумму " +
                  str(payment.amount) + " BYN. " + str(m), mail_to).sender()

        return render(request, 'Profile/Thanks.html', {'mes': m})
Пример #5
0
def unfillBalance(request):
    if request.user.is_anonymous or not request.user.is_active:
        return HttpResponseRedirect("/login")

    error, mes = '', ''
    if request.method == 'POST':
        form = RefillBalance(request.POST)

        if form.is_valid():
            card_num = form.cleaned_data['card_num']
            period_validity = form.cleaned_data['period_validity']
            name_card_owner = form.cleaned_data['name_card_owner']
            CVC2_CVV = form.cleaned_data['CVC2_CVV']
            size = form.cleaned_data['size']
            if size > request.user.balance:
                return render(request, 'Profile/Thanks.html', {'mes': "Недостаточно средств на балансе!"})
            if t.Check(card_num, period_validity, name_card_owner, CVC2_CVV).check_card():
                t.Transaction(size, request.user, card_num).make_transaction()

                # Логирование операции вывода средств
                models.LogOperationsBalance.objects.create(id_user=request.user.id, type_operation='Вывод средств',
                                                           describe_operation="Вывод средств на сумму " + str(
                                                               size) + " BYN, успешно проведён.",
                                                           date_operation=date.today(), status=True,
                                                           amount=size)
                sm.Sender("Вывод средств", "Вывод средств на сумму " + str(size) + " BYN, успешно проведён.",
                          request.user.email).sender()
                mes = request.user.name + ", средства на сумму " + str(size) + " BYN, успешно выведены на карту"
            else:
                mes = "Введены неверные данные!"
            return render(request, 'Profile/Thanks.html', {'mes': mes})

        else:
            err = form.errors.as_data()
            print(err)
            if 'card_num' in err:
                error = 'Номер карты должен содержать только цифры!'
            if 'period_validity' in err:
                error = 'Срок действия карты указан неверно!(Пример: 12/17)'
            if 'name_card_owner' in err:
                error = 'В поле Имя держателя карты введены недопустимые символы!'
            if 'CVC2_CVV' in err:
                error = 'В поле CVC2_CVV введены недопустимые символы!'
            if 'size' in err:
                error = 'Сумма может быть от 10 BYN до 1млн BYN!'
    else:
        form = RefillBalance()

    return render(request, 'Profile/UnfillBalance.html', {'form': form, 'error': error})
Пример #6
0
    def auto_pay(self):
        auto_pay = models.AutoPayment.objects.filter(
            next_payment_date=date.today().strftime('%Y-%m-%d'))
        self.stdout.write(str(date.today().strftime('%Y-%m-%d')))
        for pay in auto_pay:
            # Проверка на бан
            user_id = pay.quick_payment.username.id
            user = models.MyUser.objects.get(id=user_id)
            if user.is_active:
                payment = models.QuickPayment.objects.get(
                    id=pay.quick_payment.id)
                if payment.user_payment == 'Кошелек':
                    tr_from = models.MyUser.objects.get(id=payment.username.id)
                else:
                    tr_from = models.UserCard.objects.get(
                        card_num=payment.user_payment)
                tr_to = models.MyUser.objects.get(id=models.Rent.objects.get(
                    id=models.DoneRent.objects.get(
                        id=payment.rent_id).id_house.id).user_login.id)
                c, m = transaction.Transaction(payment.amount, tr_from,
                                               tr_to).make_transaction()
                if c:
                    transaction.PaymentManager(
                        payment.amount,
                        models.DoneRent.objects.get(id=payment.rent_id)).run()
                    pay.next_payment_date += timedelta(
                        days=pay.payment_interval)
                    pay.save()
                qp = models.QuickPayment.objects.get(id=pay.quick_payment_id)
                done_rent = models.DoneRent.objects.get(id=qp.rent_id)
                user_id = models.QuickPayment.objects.get(
                    id=pay.quick_payment_id).username_id
                email_from = models.MyUser.objects.get(id=user_id).email
                amount = models.QuickPayment.objects.get(
                    id=pay.quick_payment_id).amount
                models.LogOperationsBalance.objects.create(
                    id_user=user_id,
                    type_operation='Выполнение автоматического платежа № ' +
                    str(payment.id),
                    describe_operation="Оплата на сумму " +
                    str(payment.amount) + " BYN. " + str(m),
                    status=c,
                    amount=amount,
                    date_operation=date.today())
                sm.Sender(
                    "Оплата аренды с помощью автоматического платежа",
                    "Оплата аренды №" + str(done_rent.id_house_id) +
                    " на сумму " + str(amount) + " BYN. " + str(m),
                    email_from).sender()

                qp = models.QuickPayment.objects.get(id=pay.quick_payment_id)
                done_rent = models.DoneRent.objects.get(id=qp.rent_id)
                email_to = models.MyUser.objects.get(
                    id=done_rent.id_user_owner_id)
                amount = models.QuickPayment.objects.get(
                    id=pay.quick_payment_id).amount
                models.LogOperationsBalance.objects.create(
                    id_user=done_rent.id_user_owner_id,
                    type_operation='Оплата автоматическим платежом № ' +
                    str(payment.id),
                    describe_operation="Оплата аренды на сумму " +
                    str(payment.amount) + " BYN. " + str(m),
                    status=c,
                    amount=amount,
                    date_operation=date.today())
                sm.Sender(
                    "Оплата аренды с помощью автоматического платежа",
                    "Оплата аренды №" + str(done_rent.id_house_id) +
                    " на сумму " + str(amount) + " BYN. " + str(m),
                    email_to).sender()
Пример #7
0
def choose_payment(request, id_donerent):
    if request.user.is_anonymous or not request.user.is_active:
        return HttpResponseRedirect("/login")

    if request.method == "GET":
        try:
            models.DoneRent.objects.get(id=id_donerent)
            cards = list()
            for card in [str(i.card_num) for i in request.user.user_card_id.all()]:
                cards.append(card[:4] + ' XXXX XXXX ' + card[-4:])
            user_cards = request.user.user_card_id.all()
            c = [[i, j] for i, j in zip(cards, user_cards)]
            return render(request, "Profile/ChoosePayment.html", {'cards': c})
        except models.DoneRent.DoesNotExist:
            return render(request, "Profile/DoesNotExists.html")
    else:
        if not request.user.username == request.POST['card_from']:
            try:
                request.user.user_card_id.get(card_num=request.POST['card_from'])
            except:
                return HttpResponse(json.dumps({'message': 'Карта не найдена', 'status': False}, ensure_ascii=False),
                                    content_type="text/html; charset=utf-8")
        c, m = t.Transaction(request.POST['size'], request.POST['card_from'],
                             request.POST['balance_to'], True).make_transaction()

        if c:
            t.PaymentManager(request.POST['size'], models.DoneRent.objects.get(id=id_donerent)).run()

        response = {"message": m, "status": c}

        # Логирование операции оплаты аренды и отправка уведомлений на почту
        rent = models.DoneRent.objects.get(id=id_donerent)
        house = models.Rent.objects.get(id=rent.id_house_id)
        user_to_email = models.MyUser.objects.get(id=house.user_login_id).email
        models.LogOperationsBalance.objects.create(id_user=request.user.id, type_operation='Оплата аренды',
                                                   describe_operation="Оплата на сумму " +
                                                                      str(request.POST['size']) + " BYN. " +
                                                                      str(m), date_operation=date.today(),
                                                   status=c, amount=str(request.POST['size']))
        sm.Sender("Оплата аренды с помощью быстрого платежа", "Оплата аренды № " + str(house.id) + " на сумму " +
                  str(request.POST['size']) + " BYN. " + str(m), request.user.email).sender()

        models.LogOperationsBalance.objects.create(id_user=rent.id_user_owner_id,
                                                   type_operation='Получение оплаты за аренду',
                                                   describe_operation="Получение оплаты на сумму " +
                                                                      str(request.POST['size']) + " BYN. " +
                                                                      str(m), date_operation=date.today(),
                                                   status=c, amount=str(request.POST['size']))
        sm.Sender("Оплата аренды с помощью быстрого платежа", "Оплата аренды № " + str(house.id) + " на сумму " +
                  str(request.POST['size']) + " BYN. " + str(m), user_to_email).sender()

        response = json.dumps(response, ensure_ascii=False)

        if request.POST['card_from'] == request.user.username:
            card_from = 'Кошелек'
        else:
            card_from = request.POST['card_from']
        if request.POST['is_save'] == 'true' and not models.QuickPayment.objects.filter(username=request.user,
                                                                                        rent=models.DoneRent.objects.get(
                                                                                            id=id_donerent),
                                                                                        user_payment=card_from,
                                                                                        amount=request.POST['size']):
            models.QuickPayment.objects.create(username=request.user,
                                               rent=models.DoneRent.objects.get(id=id_donerent),
                                               user_payment=card_from,
                                               amount=request.POST['size'])
        return HttpResponse(response, content_type="text/html; charset=utf-8")