2018-09-01 16:38:12 +00:00
|
|
|
# -*- mode: python; coding: utf-8 -*-
|
2020-11-23 16:06:37 +00:00
|
|
|
# Re2o est un logiciel d'administration développé initiallement au Rézo Metz. Il
|
2018-09-01 16:38:12 +00:00
|
|
|
# se veut agnostique au réseau considéré, de manière à être installable en
|
|
|
|
# quelques clics.
|
|
|
|
#
|
|
|
|
# Copyright © 2018 Gabriel Detraz
|
2019-11-04 16:55:03 +00:00
|
|
|
# Copyright © 2018 Pierre-Antoine Comby
|
2018-09-01 16:38:12 +00:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
"""Payment
|
|
|
|
|
|
|
|
Here are the views needed by comnpay
|
|
|
|
"""
|
|
|
|
|
|
|
|
from collections import OrderedDict
|
|
|
|
|
|
|
|
from django.urls import reverse
|
|
|
|
from django.shortcuts import redirect, get_object_or_404
|
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
from django.contrib import messages
|
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
|
from django.utils.datastructures import MultiValueDictKeyError
|
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
from django.http import HttpResponse, HttpResponseBadRequest
|
|
|
|
|
|
|
|
from cotisations.models import Facture
|
|
|
|
from cotisations.utils import find_payment_method
|
|
|
|
from .models import NotePayment
|
|
|
|
from re2o.views import form
|
2019-11-04 16:55:03 +00:00
|
|
|
from re2o.acl import can_create, can_edit
|
2018-09-01 16:38:12 +00:00
|
|
|
from .note import login, don
|
|
|
|
from .forms import NoteCredentialForm
|
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-09-01 16:38:12 +00:00
|
|
|
@login_required
|
|
|
|
@can_edit(Facture)
|
|
|
|
def note_payment(request, facture, factureid):
|
|
|
|
"""
|
|
|
|
Build a request to start the negociation with NoteKfet by using
|
|
|
|
a facture id, the price and the login/password data stored in
|
|
|
|
the preferences.
|
|
|
|
"""
|
|
|
|
user = facture.user
|
|
|
|
payment_method = find_payment_method(facture.paiement)
|
|
|
|
if not payment_method or not isinstance(payment_method, NotePayment):
|
2019-01-08 23:38:53 +00:00
|
|
|
messages.error(request, _("Unknown error."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:profil", kwargs={"userid": user.id}))
|
2018-09-01 16:38:12 +00:00
|
|
|
noteform = NoteCredentialForm(request.POST or None)
|
|
|
|
if noteform.is_valid():
|
2019-11-04 16:55:03 +00:00
|
|
|
pseudo = noteform.cleaned_data["login"]
|
|
|
|
password = noteform.cleaned_data["password"]
|
|
|
|
result, sock, err = login(
|
|
|
|
payment_method.server, payment_method.port, pseudo, password
|
|
|
|
)
|
2018-09-01 16:38:12 +00:00
|
|
|
if not result:
|
|
|
|
messages.error(request, err)
|
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"form": noteform, "amount": facture.prix_total()},
|
2018-09-01 16:38:12 +00:00
|
|
|
"cotisations/payment.html",
|
2019-11-04 16:55:03 +00:00
|
|
|
request,
|
2018-09-01 16:38:12 +00:00
|
|
|
)
|
|
|
|
else:
|
2019-11-04 16:55:03 +00:00
|
|
|
result, err = don(
|
|
|
|
sock, facture.prix_total(), payment_method.id_note, facture
|
|
|
|
)
|
2018-09-01 16:38:12 +00:00
|
|
|
if not result:
|
|
|
|
messages.error(request, err)
|
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"form": noteform, "amount": facture.prix_total()},
|
2018-09-01 16:38:12 +00:00
|
|
|
"cotisations/payment.html",
|
2019-11-04 16:55:03 +00:00
|
|
|
request,
|
2018-09-01 16:38:12 +00:00
|
|
|
)
|
|
|
|
facture.valid = True
|
|
|
|
facture.save()
|
2019-01-08 23:38:53 +00:00
|
|
|
messages.success(request, _("The payment with note was done."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:profil", kwargs={"userid": user.id}))
|
2018-09-01 16:38:12 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"form": noteform, "amount": facture.prix_total()},
|
|
|
|
"cotisations/payment.html",
|
|
|
|
request,
|
|
|
|
)
|