mirror of
https://github.com/pretix/pretix.git
synced 2026-05-06 15:24:02 +00:00
Banktransfer: Completely remove HBCI support
This commit is contained in:
@@ -1,119 +0,0 @@
|
||||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
from decimal import Decimal
|
||||
|
||||
from pretix.base.decimal import round_decimal
|
||||
|
||||
|
||||
def hbci_transactions(event, conf):
|
||||
try:
|
||||
from defusedxml import ElementTree
|
||||
except:
|
||||
from xml.etree import ElementTree
|
||||
|
||||
log = []
|
||||
data = []
|
||||
accname = 'pretix_%d_%d' % (event.id, int(time.time() * 1000))
|
||||
try:
|
||||
try:
|
||||
subprocess.call([
|
||||
'aqhbci-tool4', 'deluser', '-a', '--all',
|
||||
'-b', conf['hbci_blz'],
|
||||
'-u', conf['hbci_userid']
|
||||
])
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
aqhbci_params = [
|
||||
'aqhbci-tool4', 'adduser',
|
||||
'-N', accname,
|
||||
'-b', conf['hbci_blz'],
|
||||
'-s', conf['hbci_server'],
|
||||
'-t', conf['hbci_tokentype'],
|
||||
'-u', conf['hbci_userid']
|
||||
]
|
||||
if conf['hbci_customerid']:
|
||||
aqhbci_params += ['-c', conf['hbci_customerid']]
|
||||
if conf['hbci_tokenname']:
|
||||
aqhbci_params += ['-n', conf['hbci_tokenname']]
|
||||
if conf['hbci_version']:
|
||||
aqhbci_params += ['--hbciversion=' + str(conf['hbci_version'])]
|
||||
aqhbci_add = subprocess.check_output(aqhbci_params)
|
||||
log.append("$ " + " ".join(aqhbci_params))
|
||||
log.append(aqhbci_add.decode("utf-8"))
|
||||
with tempfile.NamedTemporaryFile() as f, tempfile.NamedTemporaryFile() as g:
|
||||
f.write(('PIN_%s_%s = "%s"\n' % (
|
||||
conf['hbci_blz'],
|
||||
conf['hbci_userid'],
|
||||
conf['pin'],
|
||||
)).encode("utf-8"))
|
||||
f.flush()
|
||||
aqhbci_params = [
|
||||
'aqhbci-tool4',
|
||||
'-P', f.name,
|
||||
'-n', '-A',
|
||||
'getsysid',
|
||||
'-u', conf['hbci_userid'],
|
||||
'-b', conf['hbci_blz'],
|
||||
]
|
||||
if conf['hbci_customerid']:
|
||||
aqhbci_params += ['-c', conf['hbci_customerid']]
|
||||
aqhbci_test = subprocess.check_output(aqhbci_params)
|
||||
log.append("$ " + " ".join(aqhbci_params))
|
||||
log.append(aqhbci_test.decode("utf-8"))
|
||||
aqbanking_params = [
|
||||
'aqbanking-cli',
|
||||
'-P', f.name, '-A', '-n',
|
||||
'request',
|
||||
'--transactions',
|
||||
'-c', g.name,
|
||||
'-n', accname
|
||||
]
|
||||
aqbanking_trans = subprocess.check_output(aqbanking_params)
|
||||
log.append("$ " + " ".join(aqbanking_params))
|
||||
log.append(aqbanking_trans.decode("utf-8"))
|
||||
aqbanking_params = [
|
||||
'aqbanking-cli',
|
||||
'listtrans',
|
||||
'-c', g.name,
|
||||
'--exporter=xmldb',
|
||||
]
|
||||
aqbanking_conv = subprocess.check_output(aqbanking_params)
|
||||
log.append("$ " + " ".join(aqbanking_params))
|
||||
|
||||
root = ElementTree.fromstring(aqbanking_conv)
|
||||
trans_list = root.find('accountInfoList').find('accountInfo').find('transactionList')
|
||||
for trans in trans_list.findall('transaction'):
|
||||
payer = []
|
||||
for child in trans:
|
||||
if child.tag.startswith('remote'):
|
||||
payer.append(child.find('value').text)
|
||||
date = '%s-%02d-%02d' % (
|
||||
trans.find('date').find('date').find('year').find('value').text,
|
||||
int(trans.find('date').find('date').find('month').find('value').text),
|
||||
int(trans.find('date').find('date').find('day').find('value').text)
|
||||
)
|
||||
value = trans.find('value').find('value').find('value').text
|
||||
if "/" in value:
|
||||
parts = value.split("/")
|
||||
num = int(parts[0])
|
||||
denom = int(parts[1])
|
||||
value = Decimal(num) / Decimal(denom)
|
||||
value = str(round_decimal(value))
|
||||
data.append({
|
||||
'payer': "\n".join(payer),
|
||||
'reference': trans.find('purpose').find('value').text,
|
||||
'amount': value,
|
||||
'date': date
|
||||
})
|
||||
except subprocess.CalledProcessError as e:
|
||||
log.append("Command '%s' failed with %d and output:" % (" ".join(e.cmd), e.returncode))
|
||||
log.append(e.output.decode("utf-8"))
|
||||
except Exception as e:
|
||||
log.append(str(e))
|
||||
finally:
|
||||
subprocess.call([
|
||||
'aqhbci-tool4', 'deluser', '-a', '-N', accname
|
||||
])
|
||||
log = "\n".join(log)
|
||||
return data, log
|
||||
@@ -19,30 +19,16 @@ from pretix.base.services.mail import SendMailException
|
||||
from pretix.base.services.orders import mark_order_paid
|
||||
from pretix.base.settings import SettingsSandbox
|
||||
from pretix.control.permissions import EventPermissionRequiredMixin
|
||||
from pretix.plugins.banktransfer import csvimport, hbci, mt940import
|
||||
from pretix.plugins.banktransfer import csvimport, mt940import
|
||||
|
||||
logger = logging.getLogger('pretix.plugins.banktransfer')
|
||||
|
||||
|
||||
class HbciForm(forms.Form):
|
||||
hbci_blz = forms.CharField(label=_("Bank code"))
|
||||
hbci_userid = forms.CharField(label=_("User ID"))
|
||||
hbci_customerid = forms.CharField(label=_("Customer ID"), required=False)
|
||||
hbci_tokentype = forms.CharField(label=_("Token type"), initial='pintan')
|
||||
hbci_tokenname = forms.CharField(label=_("Token name"), required=False)
|
||||
hbci_server = forms.URLField(label=_("Server URL"))
|
||||
hbci_version = forms.IntegerField(label=_("HBCI version"), required=False, initial=220)
|
||||
pin = forms.CharField(label=_("PIN"), widget=forms.PasswordInput)
|
||||
|
||||
|
||||
class ImportView(EventPermissionRequiredMixin, TemplateView):
|
||||
template_name = 'pretixplugins/banktransfer/import_form.html'
|
||||
permission = 'can_change_orders'
|
||||
|
||||
def post(self, *args, **kwargs):
|
||||
# if 'hbci_server' in self.request.POST:
|
||||
# return self.process_hbci()
|
||||
|
||||
if ('file' in self.request.FILES and 'csv' in self.request.FILES.get('file').name.lower()) \
|
||||
or 'amount' in self.request.POST:
|
||||
# Process CSV
|
||||
@@ -88,22 +74,6 @@ class ImportView(EventPermissionRequiredMixin, TemplateView):
|
||||
def settings(self):
|
||||
return SettingsSandbox('payment', 'banktransfer', self.request.event)
|
||||
|
||||
def process_hbci(self):
|
||||
form = HbciForm(data=self.request.POST if self.request.method == "POST" else None,
|
||||
initial=self.settings)
|
||||
if form.is_valid():
|
||||
for key, value in form.cleaned_data.items():
|
||||
if key.startswith('hbci_'):
|
||||
self.settings.set(key, value)
|
||||
data, log = hbci.hbci_transactions(self.request.event, form.cleaned_data)
|
||||
if data:
|
||||
return self.confirm_view(data)
|
||||
return render(self.request, 'pretixplugins/banktransfer/hbci_log.html', {
|
||||
'log': log
|
||||
})
|
||||
else:
|
||||
return self.get(*self.args, **self.kwargs)
|
||||
|
||||
def process_mt940(self):
|
||||
try:
|
||||
return self.confirm_view(mt940import.parse(self.request.FILES.get('file')))
|
||||
@@ -112,18 +82,6 @@ class ImportView(EventPermissionRequiredMixin, TemplateView):
|
||||
messages.error(self.request, _('We were unable to process your input.'))
|
||||
return self.redirect_back()
|
||||
|
||||
@cached_property
|
||||
def hbci_form(self):
|
||||
return HbciForm(data=self.request.POST if self.request.method == "POST" else None,
|
||||
initial=self.settings)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
ctx = super().get_context_data(**kwargs)
|
||||
ctx['hbci_available'] = shutil.which('aqbanking-cli') and shutil.which('aqhbci-tool4')
|
||||
if ctx['hbci_available']:
|
||||
ctx['hbci_form'] = self.hbci_form
|
||||
return ctx
|
||||
|
||||
def process_csv_file(self):
|
||||
try:
|
||||
data = csvimport.get_rows_from_file(self.request.FILES['file'])
|
||||
|
||||
Reference in New Issue
Block a user