From c0636c561bfedf338abc4364a17464bc67605d5c Mon Sep 17 00:00:00 2001 From: Dominik George <dominik.george@teckids.org> Date: Wed, 9 Mar 2022 22:14:50 +0100 Subject: [PATCH] Add payment processing UI (entry point). --- aleksis/apps/tezor/templates/tezor/empty.html | 8 -------- .../templates/tezor/invoice/payment.html | 16 ++++++++++++++++ aleksis/apps/tezor/urls.py | 3 ++- aleksis/apps/tezor/views.py | 19 ++++++++++++++++++- 4 files changed, 36 insertions(+), 10 deletions(-) delete mode 100644 aleksis/apps/tezor/templates/tezor/empty.html create mode 100644 aleksis/apps/tezor/templates/tezor/invoice/payment.html diff --git a/aleksis/apps/tezor/templates/tezor/empty.html b/aleksis/apps/tezor/templates/tezor/empty.html deleted file mode 100644 index 2fb4415..0000000 --- a/aleksis/apps/tezor/templates/tezor/empty.html +++ /dev/null @@ -1,8 +0,0 @@ -{% extends 'core/base.html' %} -{% load i18n %} - -{% block content %} - <p class="flow-text"> - {% blocktrans %}Tezor (account and payment system){% endblocktrans %} - </p> -{% endblock %} diff --git a/aleksis/apps/tezor/templates/tezor/invoice/payment.html b/aleksis/apps/tezor/templates/tezor/invoice/payment.html new file mode 100644 index 0000000..7d51c90 --- /dev/null +++ b/aleksis/apps/tezor/templates/tezor/invoice/payment.html @@ -0,0 +1,16 @@ +{% extends 'core/base.html' %} + +{% load i18n %} +{% load material_form %} + +{% block page_title %}{% blocktrans %}Make payment for{% endblocktrans %} {{ payment.transaction_id }}{% endblock %} +{% block browser_title %}{% blocktrans %}Make payment for{% endblocktrans %} {{ payment.transaction_id }}{% endblock %} + +{% block content %} +<form action="{{ form.action }}" method="{{ form.method }}"> + {% csrf_token %} + {% form form=form %}{% endform %} + {% trans "Confirm payment" as caption %} + {% include "core/partials/save_button.html" with caption=caption icon="shopping_cart_checkout" %} +</form> +{% endblock %} diff --git a/aleksis/apps/tezor/urls.py b/aleksis/apps/tezor/urls.py index 571809c..18d1a1c 100644 --- a/aleksis/apps/tezor/urls.py +++ b/aleksis/apps/tezor/urls.py @@ -4,5 +4,6 @@ from . import views urlpatterns = [ path("payments/", include("payments.urls")), - path("invoice/<int:pk>/print", views.GetInvoicePDF.as_view(), name="get_invoice_by_pk") + path("invoice/<int:pk>/print", views.GetInvoicePDF.as_view(), name="get_invoice_by_pk"), + path("invoice/<str:token>/payment", views.payment_details, name="payment_details"), ] diff --git a/aleksis/apps/tezor/views.py b/aleksis/apps/tezor/views.py index 22fe108..378794e 100644 --- a/aleksis/apps/tezor/views.py +++ b/aleksis/apps/tezor/views.py @@ -1,6 +1,7 @@ from django.views.generic import View -from django.shortcuts import render +from django.shortcuts import redirect, render, get_object_or_404 +from payments import get_payment_model, RedirectNeeded from rules.contrib.views import PermissionRequiredMixin from aleksis.core.views import RenderPDFView @@ -20,3 +21,19 @@ class GetInvoicePDF(PermissionRequiredMixin, RenderPDFView): print(invoice.group.__dict__) return context + + +def payment_details(request, token): + payment = get_object_or_404(get_payment_model(), token=token) + + try: + form = payment.get_form(data=request.POST or None) + except RedirectNeeded as redirect_to: + return redirect(str(redirect_to)) + + context = { + "form": form, + "payment": payment, + } + + return render(request, "tezor/invoice/payment.html", context) -- GitLab