diff --git a/aleksis/apps/paweljong/forms.py b/aleksis/apps/paweljong/forms.py index 1e8ad83d817c8a221fabda3444914d4cc4bb28ea..d364971fc94cd099cc6b9f5b00b90a96390cb70f 100644 --- a/aleksis/apps/paweljong/forms.py +++ b/aleksis/apps/paweljong/forms.py @@ -8,6 +8,7 @@ from django_select2.forms import ModelSelect2MultipleWidget, ModelSelect2Widget from material import Fieldset, Layout, Row from phonenumber_field.formfields import PhoneNumberField +from aleksis.apps.tezor.models.invoice import Invoice from aleksis.core.mixins import ExtensibleForm from aleksis.core.models import Group, Person @@ -326,7 +327,8 @@ class RegisterEventFinancial(ExtensibleForm): layout = Layout( Fieldset( _("Financial data"), - "voucher_code", "donation" + "payment_method", + Row("voucher_code", "donation"), ), ) @@ -336,6 +338,12 @@ class RegisterEventFinancial(ExtensibleForm): 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: model = EventRegistration fields = ["voucher_code", "donation"] diff --git a/aleksis/apps/paweljong/migrations/0018_payment_with_tezor.py b/aleksis/apps/paweljong/migrations/0018_payment_with_tezor.py new file mode 100644 index 0000000000000000000000000000000000000000..bed3611ff59c2e9414cf25c2ec96d6566d7d34ad --- /dev/null +++ b/aleksis/apps/paweljong/migrations/0018_payment_with_tezor.py @@ -0,0 +1,49 @@ +# 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', + ), + ] diff --git a/aleksis/apps/paweljong/templates/paweljong/event_registration/full.html b/aleksis/apps/paweljong/templates/paweljong/event_registration/full.html index f1acef891803ba012b0c7de9fe70af5952b50544..4c7931f704b9a5d3c93f087da7751e7b99c935c5 100644 --- a/aleksis/apps/paweljong/templates/paweljong/event_registration/full.html +++ b/aleksis/apps/paweljong/templates/paweljong/event_registration/full.html @@ -39,7 +39,7 @@ {% endif %} {% 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> {% trans "Invoice" %} </a> diff --git a/aleksis/apps/paweljong/views.py b/aleksis/apps/paweljong/views.py index 4d9d533f7fb477ae532cf319099632308ab62f55..6a7bd98bfcaf9ad92efeae4f7880ae3faadb4578 100644 --- a/aleksis/apps/paweljong/views.py +++ b/aleksis/apps/paweljong/views.py @@ -426,9 +426,9 @@ class RegisterEventWizardView(SessionWizardView): elif self.steps.current == "financial": context["info_title"] = _("Payment") context["info_text"] = _( - "By default, we will send you an invoice, which you or your parents " - "can pay by bank transfer. You can also choose to pay by direct debit – " - "please make sure to enter exactly what your parents tell you." + "Please decide with your parents how you want to pay. In this step, " + "you only select a payment method. The real payment will be done " + "in a separate step, after the registration is complete." ) elif self.steps.current == "consent": context["info_title"] = _("Consent") @@ -646,13 +646,17 @@ class RegisterEventWizardView(SessionWizardView): else: 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["registration"] = registration send_templated_mail( template_name="event_registered", 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={ "reply_to": [ person.email, @@ -679,7 +683,7 @@ class RegisterEventWizardView(SessionWizardView): user=person, ) - return redirect("index") + return redirect("do_payment", registration.get_invoice().token) class EventFullView(DetailView):