Skip to content
Snippets Groups Projects
Commit 8e1adf4c authored by Tom Teichler's avatar Tom Teichler :beers:
Browse files

Handle payment via Tezor in wizard

parent 59a11a94
No related branches found
No related tags found
1 merge request!14Payments
Pipeline #59283 canceled
...@@ -8,6 +8,7 @@ from django_select2.forms import ModelSelect2MultipleWidget, ModelSelect2Widget ...@@ -8,6 +8,7 @@ from django_select2.forms import ModelSelect2MultipleWidget, ModelSelect2Widget
from material import Fieldset, Layout, Row from material import Fieldset, Layout, Row
from phonenumber_field.formfields import PhoneNumberField from phonenumber_field.formfields import PhoneNumberField
from aleksis.apps.tezor.models.invoice import Invoice
from aleksis.core.mixins import ExtensibleForm from aleksis.core.mixins import ExtensibleForm
from aleksis.core.models import Group, Person from aleksis.core.models import Group, Person
...@@ -326,7 +327,8 @@ class RegisterEventFinancial(ExtensibleForm): ...@@ -326,7 +327,8 @@ class RegisterEventFinancial(ExtensibleForm):
layout = Layout( layout = Layout(
Fieldset( Fieldset(
_("Financial data"), _("Financial data"),
"voucher_code", "donation" "payment_method",
Row("voucher_code", "donation"),
), ),
) )
...@@ -336,6 +338,12 @@ class RegisterEventFinancial(ExtensibleForm): ...@@ -336,6 +338,12 @@ class RegisterEventFinancial(ExtensibleForm):
required=False, required=False,
) )
payment_method = forms.ChoiceField(
choices=Invoice.get_variant_choices(),
label=_("Paymeht method"),
help_text=_("Please choose a payment method. The actual payment will be made after the registration.")
)
class Meta: class Meta:
model = EventRegistration model = EventRegistration
fields = ["voucher_code", "donation"] fields = ["voucher_code", "donation"]
......
# Generated by Django 3.2.12 on 2022-03-11 23:23
from django.db import migrations, models
from payments import PaymentStatus
def create_invoices(apps, schema_editor):
db_alias = schema_editor.connection.alias
Person = apps.get_model("core", "Person")
EventRegistration = apps.get_model("paweljong", "EventRegistration")
SEPAMandate = apps.get_model("djp_sepa", "SEPAMandate")
from aleksis.apps.paweljong.models import EventRegistration as RealEventRegistration
EventRegistration.get_invoice = RealEventRegistration.get_invoice
EventRegistration._get_total_amount = RealEventRegistration._get_total_amount
EventRegistration.get_purchased_items = RealEventRegistration.get_purchased_items
Person.addressing_name = property(lambda p: p.first_name + " " + p.last_name)
for registration in EventRegistration.objects.using(db_alias).all():
invoice = registration.get_invoice()
invoice.status = PaymentStatus.PREAUTH
if registration.accept_sepa:
invoice.variant = "sdd"
SEPAMandate.objects.create(payment_id=invoice.pk, account_holder=f"{registration.person.addressing_name}", iban=registration.iban, bic="XXXXXXXXXXX", date=registration.date_registered)
else:
invoice.variant = "pledge"
invoice.save()
class Migration(migrations.Migration):
dependencies = [
('paweljong', '0017_fix_voucher_max_length'),
('tezor', '0001_initial'),
]
operations = [
migrations.RunPython(create_invoices),
migrations.RemoveField(
model_name='eventregistration',
name='accept_sepa',
),
migrations.RemoveField(
model_name='eventregistration',
name='iban',
),
]
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
{% endif %} {% endif %}
{% if can_print_invoice %} {% if can_print_invoice %}
<a href="{% url 'get_invoice_by_pk' registration.get_invoice.pk %}" class="btn waves-effect waves-light"> <a href="{% url 'invoice_by_token' registration.get_invoice.token %}" class="btn waves-effect waves-light">
<i class="material-icons left">attach_money</i> <i class="material-icons left">attach_money</i>
{% trans "Invoice" %} {% trans "Invoice" %}
</a> </a>
......
...@@ -426,9 +426,9 @@ class RegisterEventWizardView(SessionWizardView): ...@@ -426,9 +426,9 @@ class RegisterEventWizardView(SessionWizardView):
elif self.steps.current == "financial": elif self.steps.current == "financial":
context["info_title"] = _("Payment") context["info_title"] = _("Payment")
context["info_text"] = _( context["info_text"] = _(
"By default, we will send you an invoice, which you or your parents " "Please decide with your parents how you want to pay. In this step, "
"can pay by bank transfer. You can also choose to pay by direct debit – " "you only select a payment method. The real payment will be done "
"please make sure to enter exactly what your parents tell you." "in a separate step, after the registration is complete."
) )
elif self.steps.current == "consent": elif self.steps.current == "consent":
context["info_title"] = _("Consent") context["info_title"] = _("Consent")
...@@ -646,13 +646,17 @@ class RegisterEventWizardView(SessionWizardView): ...@@ -646,13 +646,17 @@ class RegisterEventWizardView(SessionWizardView):
else: else:
messages.error(self.request, _("You entered an invalid voucher code!")) messages.error(self.request, _("You entered an invalid voucher code!"))
invoice = registration.get_invoice()
invoice.variant = cleaned_data_financial["payment_method"]
invoice.save()
context = {} context = {}
context["registration"] = registration context["registration"] = registration
send_templated_mail( send_templated_mail(
template_name="event_registered", template_name="event_registered",
from_email=get_site_preferences()["mail__address"], from_email=get_site_preferences()["mail__address"],
recipient_list=get_site_prefenreces()["paweljong__event_notification_recipient"], recipient_list=[get_site_preferences()["paweljong__event_notification_recipient"]],
headers={ headers={
"reply_to": [ "reply_to": [
person.email, person.email,
...@@ -679,7 +683,7 @@ class RegisterEventWizardView(SessionWizardView): ...@@ -679,7 +683,7 @@ class RegisterEventWizardView(SessionWizardView):
user=person, user=person,
) )
return redirect("index") return redirect("do_payment", registration.get_invoice().token)
class EventFullView(DetailView): class EventFullView(DetailView):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment