From e45c162b3dca7abf4d06d9b0944f8d7462fe170a Mon Sep 17 00:00:00 2001
From: Raphael Michel
Date: Wed, 14 Sep 2022 17:53:23 +0200
Subject: [PATCH] Bank transfer: Minimal implementation of Swiss QR-bill
(#2767)
Co-authored-by: Richard Schreiber
---
src/pretix/plugins/banktransfer/payment.py | 47 ++++++++++++++
.../pretixplugins/banktransfer/swisscross.css | 15 +++++
.../pretixplugins/banktransfer/pending.html | 64 +++++++++++++------
3 files changed, 105 insertions(+), 21 deletions(-)
create mode 100644 src/pretix/plugins/banktransfer/static/pretixplugins/banktransfer/swisscross.css
diff --git a/src/pretix/plugins/banktransfer/payment.py b/src/pretix/plugins/banktransfer/payment.py
index 192e0e34e..0e733cec3 100644
--- a/src/pretix/plugins/banktransfer/payment.py
+++ b/src/pretix/plugins/banktransfer/payment.py
@@ -47,6 +47,7 @@ from i18nfield.forms import I18nTextInput
from i18nfield.strings import LazyI18nString
from localflavor.generic.forms import BICFormField, IBANFormField
from localflavor.generic.validators import IBANValidator
+from text_unidecode import unidecode
from pretix.base.models import Order, OrderPayment, OrderRefund
from pretix.base.payment import BasePaymentProvider
@@ -261,6 +262,51 @@ class BankTransfer(BasePaymentProvider):
}
return template.render(ctx)
+ def swiss_qrbill(self, payment):
+ if not self.settings.get('bank_details_sepa_iban') or not self.settings.get('bank_details_sepa_iban')[:2] in ('CH', 'LI'):
+ return
+ if self.event.currency not in ('EUR', 'CHF'):
+ return
+ if not self.event.settings.invoice_address_from or not self.event.settings.invoice_address_from_country:
+ return
+
+ data_fields = [
+ 'SPC',
+ '0200',
+ '1',
+ self.settings.get('bank_details_sepa_iban'),
+ 'K',
+ self.settings.get('bank_details_sepa_name')[:70],
+ self.event.settings.invoice_address_from.replace('\n', ', ')[:70],
+ (self.event.settings.invoice_address_from_zipcode + ' ' + self.event.settings.invoice_address_from_city)[:70],
+ '',
+ '',
+ str(self.event.settings.invoice_address_from_country),
+ '', # rfu
+ '', # rfu
+ '', # rfu
+ '', # rfu
+ '', # rfu
+ '', # rfu
+ '', # rfu
+ str(payment.amount),
+ self.event.currency,
+ '', # debtor address
+ '', # debtor address
+ '', # debtor address
+ '', # debtor address
+ '', # debtor address
+ '', # debtor address
+ '', # debtor address
+ 'NON',
+ '', # structured reference
+ self._code(payment.order),
+ 'EPD',
+ ]
+
+ data_fields = [unidecode(d or '') for d in data_fields]
+ return '\r\n'.join(data_fields)
+
def payment_pending_render(self, request: HttpRequest, payment: OrderPayment):
template = get_template('pretixplugins/banktransfer/pending.html')
ctx = {
@@ -269,6 +315,7 @@ class BankTransfer(BasePaymentProvider):
'order': payment.order,
'amount': payment.amount,
'settings': self.settings,
+ 'swiss_qrbill': self.swiss_qrbill(payment),
'pending_description': self.settings.get('pending_description', as_type=LazyI18nString),
'details': self.settings.get('bank_details', as_type=LazyI18nString),
}
diff --git a/src/pretix/plugins/banktransfer/static/pretixplugins/banktransfer/swisscross.css b/src/pretix/plugins/banktransfer/static/pretixplugins/banktransfer/swisscross.css
new file mode 100644
index 000000000..7febb239a
--- /dev/null
+++ b/src/pretix/plugins/banktransfer/static/pretixplugins/banktransfer/swisscross.css
@@ -0,0 +1,15 @@
+.banktransfer-swiss-cross-overlay {
+ position: relative;
+ width: 150px;
+ height: 150px;
+ margin: 0 auto 10px;
+}
+.banktransfer-swiss-cross {
+ position: absolute;
+ width: 15.217%;
+ height: 15.217%;
+ left: 50%;
+ top: 50%;
+ margin-left: -7.609%;
+ margin-top: -7.609%;
+}
diff --git a/src/pretix/plugins/banktransfer/templates/pretixplugins/banktransfer/pending.html b/src/pretix/plugins/banktransfer/templates/pretixplugins/banktransfer/pending.html
index 0c986c478..98991d359 100644
--- a/src/pretix/plugins/banktransfer/templates/pretixplugins/banktransfer/pending.html
+++ b/src/pretix/plugins/banktransfer/templates/pretixplugins/banktransfer/pending.html
@@ -1,6 +1,7 @@
{% load i18n %}
{% load l10n %}
{% load commadecimal %}
+{% load static %}
{% load dotdecimal %}
{% load ibanformat %}
{% load money %}
@@ -41,18 +42,32 @@
{% if settings.bank_details_type == "sepa" %}
-
-
-
GiroCode / EPC-QR
-
-
+
+
+ {% endif %}
+
+
+ {% trans "Scan the qr-code with your banking app" %}
+
+
+
-
-
-
-
-
- {% trans "Open banking app" %}
-
- {% trans "Requires that the app supports BezahlCode" %}
-
+
+
+
+
+ {% trans "Scan the qr-code with your banking app" %}
+
+
+
+
+
+
+
+
{% endif %}
+{% if swiss_qrbill %}
+
+{% endif %}