mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-24 13:08:47 +02:00
Configure Hello Asso return endpoint
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
@ -6,6 +6,7 @@ import subprocess
|
||||
from tempfile import mkdtemp
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.sites.models import Site
|
||||
@ -19,6 +20,7 @@ from django.urls import reverse_lazy
|
||||
from django.utils import timezone, translation
|
||||
from django.utils.crypto import get_random_string
|
||||
from django.utils.http import urlsafe_base64_decode
|
||||
from django.utils.text import format_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic import CreateView, DetailView, RedirectView, TemplateView, UpdateView, View
|
||||
from django_tables2 import SingleTableView
|
||||
@ -215,6 +217,7 @@ class MyAccountDetailView(LoginRequiredMixin, RedirectView):
|
||||
"""
|
||||
Redirect to our own profile detail page.
|
||||
"""
|
||||
|
||||
def get_redirect_url(self, *args, **kwargs):
|
||||
return reverse_lazy("registration:user_detail", args=(self.request.user.pk,))
|
||||
|
||||
@ -550,10 +553,76 @@ class PaymenRedirectHelloAssoView(LoginRequiredMixin, DetailView):
|
||||
return redirect(checkout_intent["redirectUrl"])
|
||||
|
||||
|
||||
class PaymentHelloAssoReturnView(DetailView):
|
||||
model = Payment
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
checkout_id = request.GET.get("checkoutIntentId")
|
||||
payment = Payment.objects.get(checkout_intent_id=checkout_id).exclude(valid=True)
|
||||
if payment != self.get_object():
|
||||
messages.error(request, _("The payment is not found or is already validated."))
|
||||
return redirect("index")
|
||||
|
||||
team = payment.team
|
||||
tournament = payment.tournament
|
||||
right_to_see = not request.user.is_anonymous \
|
||||
and (request.user.registration.is_admin
|
||||
or request.user.registration in payment.registrations.all()
|
||||
or (request.user.registration.is_volunteer
|
||||
and tournament in request.user.registration.organized_tournaments.all())
|
||||
or (request.user.registration.is_coach and request.user.registration.team == team))
|
||||
|
||||
if right_to_see:
|
||||
error_response = redirect("registration:update_payment", args=(payment.pk,))
|
||||
else:
|
||||
error_response = redirect("index")
|
||||
|
||||
return_type = request.GET.get("type")
|
||||
if return_type == "error":
|
||||
messages.error(request, format_lazy(_("An error occurred during the payment: {error}"),
|
||||
error=request.GET.get("error")))
|
||||
return error_response
|
||||
elif return_type == "return":
|
||||
code = request.GET.get("code")
|
||||
if code == "refused":
|
||||
messages.error(request, _("The payment has been refused."))
|
||||
return error_response
|
||||
elif code != "success":
|
||||
messages.error(request, format_lazy(_("The return code is unknown: {code}"), code=code))
|
||||
return error_response
|
||||
else:
|
||||
messages.error(request, format_lazy(_("The return type is unknown: {type}"), type=return_type))
|
||||
return error_response
|
||||
|
||||
checkout_intent = payment.get_checkout_intent()
|
||||
if 'order' in checkout_intent:
|
||||
payment.valid = True
|
||||
payment.save()
|
||||
messages.success(request, _("The payment has been successfully validated! "
|
||||
"Your registration is now complete."))
|
||||
else:
|
||||
payment.valid = None
|
||||
payment.save()
|
||||
messages.success(request, _("Your payment is done! "
|
||||
"The validation of your payment may takes a few minutes, "
|
||||
"and will be automatically done. "
|
||||
"If it is not the case, please contact us."))
|
||||
|
||||
if request.user.registration in payment.registrations.all():
|
||||
success_response = redirect("registration:user_detail", args=(request.user.pk,))
|
||||
elif right_to_see:
|
||||
success_response = redirect("participation:team_detail", args=(team.pk,))
|
||||
else:
|
||||
success_response = redirect("index")
|
||||
|
||||
return success_response
|
||||
|
||||
|
||||
class PhotoAuthorizationView(LoginRequiredMixin, View):
|
||||
"""
|
||||
Display the sent photo authorization.
|
||||
"""
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
filename = kwargs["filename"]
|
||||
path = f"media/authorization/photo/{filename}"
|
||||
@ -577,6 +646,7 @@ class HealthSheetView(LoginRequiredMixin, View):
|
||||
"""
|
||||
Display the sent health sheet.
|
||||
"""
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
filename = kwargs["filename"]
|
||||
path = f"media/authorization/health/{filename}"
|
||||
@ -600,6 +670,7 @@ class VaccineSheetView(LoginRequiredMixin, View):
|
||||
"""
|
||||
Display the sent health sheet.
|
||||
"""
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
filename = kwargs["filename"]
|
||||
path = f"media/authorization/vaccine/{filename}"
|
||||
@ -623,6 +694,7 @@ class ParentalAuthorizationView(LoginRequiredMixin, View):
|
||||
"""
|
||||
Display the sent parental authorization.
|
||||
"""
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
filename = kwargs["filename"]
|
||||
path = f"media/authorization/parental/{filename}"
|
||||
@ -646,6 +718,7 @@ class ReceiptView(LoginRequiredMixin, View):
|
||||
"""
|
||||
Display the sent payment receipt or scholarship notification.
|
||||
"""
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
filename = kwargs["filename"]
|
||||
path = f"media/authorization/receipt/{filename}"
|
||||
@ -668,6 +741,7 @@ class SolutionView(LoginRequiredMixin, View):
|
||||
"""
|
||||
Display the sent solution.
|
||||
"""
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
filename = kwargs["filename"]
|
||||
path = f"media/solutions/{filename}"
|
||||
@ -686,7 +760,7 @@ class SolutionView(LoginRequiredMixin, View):
|
||||
if not (user.registration.is_admin
|
||||
or user.registration.is_volunteer and user.registration
|
||||
in (solution.participation.tournament
|
||||
if not solution.final_solution else Tournament.final_tournament()).organizers.all()
|
||||
if not solution.final_solution else Tournament.final_tournament()).organizers.all()
|
||||
or user.registration.is_volunteer
|
||||
and Passage.objects.filter(Q(pool__juries=user.registration)
|
||||
| Q(pool__tournament__in=user.registration.organized_tournaments.all()),
|
||||
@ -711,6 +785,7 @@ class SynthesisView(LoginRequiredMixin, View):
|
||||
"""
|
||||
Display the sent synthesis.
|
||||
"""
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
filename = kwargs["filename"]
|
||||
path = f"media/syntheses/{filename}"
|
||||
|
Reference in New Issue
Block a user