From 0d1643da668de00fda4d8915b5486fadd157e082 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Sun, 24 Jun 2018 16:14:29 +0200 Subject: [PATCH] Add manual payments --- src/pretix/plugins/manualpayment/__init__.py | 21 +++++ src/pretix/plugins/manualpayment/payment.py | 92 +++++++++++++++++++ src/pretix/plugins/manualpayment/signals.py | 10 ++ .../pretixplugins/manualpayment/control.html | 11 +++ src/pretix/settings.py | 1 + 5 files changed, 135 insertions(+) create mode 100644 src/pretix/plugins/manualpayment/__init__.py create mode 100644 src/pretix/plugins/manualpayment/payment.py create mode 100644 src/pretix/plugins/manualpayment/signals.py create mode 100644 src/pretix/plugins/manualpayment/templates/pretixplugins/manualpayment/control.html diff --git a/src/pretix/plugins/manualpayment/__init__.py b/src/pretix/plugins/manualpayment/__init__.py new file mode 100644 index 0000000000..16f7f15e7b --- /dev/null +++ b/src/pretix/plugins/manualpayment/__init__.py @@ -0,0 +1,21 @@ +from django.apps import AppConfig +from django.utils.translation import ugettext_lazy as _ + +from pretix import __version__ as version + + +class ManualPaymentApp(AppConfig): + name = 'pretix.plugins.manualpayment' + verbose_name = _("Manual payment") + + class PretixPluginMeta: + name = _("Manual payment") + author = _("the pretix team") + version = version + description = _("This plugin adds a customizable payment method for manual processing.") + + def ready(self): + from . import signals # NOQA + + +default_app_config = 'pretix.plugins.manualpayment.ManualPaymentApp' diff --git a/src/pretix/plugins/manualpayment/payment.py b/src/pretix/plugins/manualpayment/payment.py new file mode 100644 index 0000000000..1ea5be1453 --- /dev/null +++ b/src/pretix/plugins/manualpayment/payment.py @@ -0,0 +1,92 @@ +from collections import OrderedDict + +from django.template.loader import get_template +from django.utils.translation import ugettext_lazy as _ +from i18nfield.fields import I18nFormField, I18nTextarea, I18nTextInput +from i18nfield.strings import LazyI18nString + +from pretix.base.forms import PlaceholderValidator +from pretix.base.payment import BasePaymentProvider +from pretix.base.templatetags.money import money_filter +from pretix.base.templatetags.rich_text import rich_text + + +class ManualPayment(BasePaymentProvider): + identifier = 'manual' + verbose_name = _('Manual payment') + + @property + def public_name(self): + return str(self.settings.get('public_name', as_type=LazyI18nString)) + + @property + def settings_form_fields(self): + d = OrderedDict( + [ + ('public_name', I18nFormField( + label=_('Payment method name'), + widget=I18nTextInput, + )), + ('checkout_description', I18nFormField( + label=_('Payment process description during checkout'), + help_text=_('This text will be shown during checkout when the user selects this payment method. ' + 'It should give a short explanation on this payment method.'), + widget=I18nTextarea, + )), + ('email_instructions', I18nFormField( + label=_('Payment process description in order confirmation emails'), + help_text=_('This text will be included for the {payment_info} placeholder in order confirmation ' + 'mails. It should instruct the user on how to proceed with the payment. You can use' + 'the placeholders {order}, {total}, {currency} and {total_with_currency}'), + widget=I18nTextarea, + validators=[PlaceholderValidator(['{order}', '{total}', '{currency}', '{total_with_currency}'])], + )), + ('pending_description', I18nFormField( + label=_('Payment process description for pending orders'), + help_text=_('This text will be shown on the order confirmation page for pending orders. ' + 'It should instruct the user on how to proceed with the payment. You can use' + 'the placeholders {order}, {total}, {currency} and {total_with_currency}'), + widget=I18nTextarea, + validators=[PlaceholderValidator(['{order}', '{total}', '{currency}', '{total_with_currency}'])], + )), + ] + list(super().settings_form_fields.items()) + ) + d.move_to_end('_enabled', last=False) + return d + + def payment_form_render(self, request) -> str: + return rich_text( + str(self.settings.get('checkout_description', as_type=LazyI18nString)) + ) + + def checkout_prepare(self, request, total): + return True + + def payment_is_valid_session(self, request): + return True + + def checkout_confirm_render(self, request): + return self.payment_form_render(request) + + def format_map(self, order): + return { + 'order': order.code, + 'total': order.total, + 'currency': self.event.currency, + 'total_with_currency': money_filter(order.total, self.event.currency) + } + + def order_pending_mail_render(self, order) -> str: + msg = str(self.settings.get('email_instructions', as_type=LazyI18nString)).format_map(self.format_map(order)) + return msg + + def order_pending_render(self, request, order) -> str: + return rich_text( + str(self.settings.get('pending_description', as_type=LazyI18nString)).format_map(self.format_map(order)) + ) + + def order_control_render(self, request, order) -> str: + template = get_template('pretixplugins/manualpayment/control.html') + ctx = {'request': request, 'event': self.event, + 'order': order} + return template.render(ctx) diff --git a/src/pretix/plugins/manualpayment/signals.py b/src/pretix/plugins/manualpayment/signals.py new file mode 100644 index 0000000000..191b782a5f --- /dev/null +++ b/src/pretix/plugins/manualpayment/signals.py @@ -0,0 +1,10 @@ +from django.dispatch import receiver + +from pretix.base.signals import register_payment_providers + +from .payment import ManualPayment + + +@receiver(register_payment_providers, dispatch_uid="payment_manual") +def register_payment_provider(sender, **kwargs): + return ManualPayment diff --git a/src/pretix/plugins/manualpayment/templates/pretixplugins/manualpayment/control.html b/src/pretix/plugins/manualpayment/templates/pretixplugins/manualpayment/control.html new file mode 100644 index 0000000000..bea520c039 --- /dev/null +++ b/src/pretix/plugins/manualpayment/templates/pretixplugins/manualpayment/control.html @@ -0,0 +1,11 @@ +{% load i18n %} + +{% if order.status == "p" %} +

{% blocktrans trimmed %} + This order has been paid manually. + {% endblocktrans %}

+{% else %} +

{% blocktrans trimmed %} + This order has been planned to be paid manually, but is not marked as paid. + {% endblocktrans %}

+{% endif %} diff --git a/src/pretix/settings.py b/src/pretix/settings.py index 99b1718b4e..73e1d28d8c 100644 --- a/src/pretix/settings.py +++ b/src/pretix/settings.py @@ -242,6 +242,7 @@ INSTALLED_APPS = [ 'pretix.plugins.checkinlists', 'pretix.plugins.pretixdroid', 'pretix.plugins.badges', + 'pretix.plugins.manualpayment', 'django_markup', 'django_otp', 'django_otp.plugins.otp_totp',