Add payment information after payment

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello 2024-02-24 22:55:34 +01:00
parent 1d01376703
commit 2a2786ba6d
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
3 changed files with 323 additions and 177 deletions

File diff suppressed because it is too large Load Diff

View File

@ -201,13 +201,82 @@
</div> </div>
</div> </div>
{% else %} {% else %}
<form method="post" enctype="multipart/form-data"> {% if user.registration.is_volunteer %}
<div id="form-content"> <form method="post" enctype="multipart/form-data">
{% csrf_token %} <div id="form-content">
{{ form|crispy }} {% csrf_token %}
</div> {{ form|crispy }}
<button class="btn btn-primary" type="submit">{% trans "Update" %}</button> </div>
</form> <button class="btn btn-primary" type="submit">{% trans "Update" %}</button>
</form>
{% else %}
{% if payment.type == 'helloasso' %}
{% if payment.valid is True %}
<div class="alert alert-success">
{% with order=payment.get_checkout_intent.order %}
{% trans "Your payment by credit card via Hello Asso is successfully validated." %}
{% trans "The paid amount is" %} {% widthratio order.amount.total 100 1 %} €.
{% if grouped %}
{% trans "It includes the registrations of all members of the team." %}
{% endif %}
{% trans "The payer was " %} {{ order.payer.firstName }} {{ order.payer.lastName }}.
{% trans "The payment was done on" %} {{ order.date }}.
{% endwith %}
</div>
{% elif payment.valid is None %}
<div class="alert alert-warning">
{% trans "The payment by credit card via Hello Asso is pending validation." %}
{% trans "It should takes only few minutes. If it takes longer, please contact us." %}
</div>
{% endif %}
{% else %}
{% if payment.valid is True %}
<div class="alert alert-success">
{% trans "Your payment is successfully validated by the organizers." %}
<ul>
<li>{% trans "Type:" %} {{ payment.get_type_display }}</li>
<li>
{% trans "Amount:" %} {{ payment.amount }} €
{% if payment.grouped %}
({% trans "It includes the registrations of all members of the team." %})
{% endif %}
</li>
{% if payment.receipt %}
<li>
{% trans "Receipt:" %}
<a href="{{ payment.receipt.url }}"><i class="fas fa-download"></i> {% trans "Download" %}</a>
</li>
{% endif %}
{% if payment.additional_information %}
<li>{% trans "Additional information:" %} {{ payment.additional_information }}</li>
{% endif %}
</ul>
</div>
{% elif payment.valid is None %}
<div class="alert alert-warning">
{% trans "Your payment is pending validation from the organizers." %}
<ul>
<li>{% trans "Type:" %} {{ payment.get_type_display }}</li>
<li>
{% trans "Amount:" %} {{ payment.amount }} €
{% if payment.grouped %}
({% trans "It includes the registrations of all members of the team." %})
{% endif %}
</li>
{% if payment.receipt %}
<li>
{% trans "Receipt:" %}
<a href="{{ payment.receipt.url }}"><i class="fas fa-download"></i> {% trans "Download" %}</a>
</li>
{% endif %}
{% if payment.additional_information %}
<li>{% trans "Additional information:" %} {{ payment.additional_information }}</li>
{% endif %}
</ul>
</div>
{% endif %}
{% endif %}
{% endif %}
{% endif %} {% endif %}
{% endblock content %} {% endblock content %}

View File

@ -451,8 +451,7 @@ class PaymentUpdateView(LoginRequiredMixin, UpdateView):
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
if not self.request.user.is_authenticated or \ if not self.request.user.is_authenticated or \
not self.request.user.registration.is_admin \ not self.request.user.registration.is_admin \
and (self.request.user.registration not in self.get_object().registrations.all() and self.request.user.registration not in self.get_object().registrations.all():
or self.get_object().valid is not False):
return self.handle_no_permission() return self.handle_no_permission()
return super().dispatch(request, *args, **kwargs) return super().dispatch(request, *args, **kwargs)
@ -477,8 +476,12 @@ class PaymentUpdateView(LoginRequiredMixin, UpdateView):
return context return context
def form_valid(self, form): def form_valid(self, form):
form.instance.valid = None
old_instance = Payment.objects.get(pk=self.object.pk) old_instance = Payment.objects.get(pk=self.object.pk)
if self.request.user.registration.participates:
if old_instance.valid is not False:
raise PermissionDenied(_("This payment is already valid or pending validation."))
else:
form.instance.valid = None
if old_instance.receipt: if old_instance.receipt:
old_instance.receipt.delete() old_instance.receipt.delete()
old_instance.save() old_instance.save()