Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change BIC check to lookup (Z#23149160) #36

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions pretix_sepadebit/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,22 @@ def clean(self):

d = super().clean()

# lookup BIC
if d.get('iban'):
bic_found = False
iban_without_checksum = d['iban'][0:2] + 'XX' + d['iban'][4:]
for k in range(6, 15):
if iban_without_checksum[:k] in DATA:
correct_bic = DATA[iban_without_checksum[:k]]
input_bic = d.get('bic', '')
if len(input_bic) < len(correct_bic):
input_bic += 'XXX'
bic_match = (
correct_bic == input_bic or
(correct_bic.startswith('COBADE') and input_bic.startswith('COBADE')) # https://github.com/pretix/pretix-sepadebit/issues/34
)
if not bic_match:
raise ValidationError(
_('The BIC number {bic} does not match the IBAN. Please double, check your banking '
'details. According to our data, the correct BIC would be {correctbic}.').format(
bic=input_bic, correctbic=correct_bic
)
)
d['bic'] = DATA[iban_without_checksum[:k]]
bic_found = True

return d
if bic_found:
return d
else:
raise ValidationError(
_('There is no BIC number associated with this IBAN. Please double, check your banking '
'details.')
)


class SepaDebit(BasePaymentProvider):
Expand Down Expand Up @@ -247,7 +242,7 @@ def payment_form_fields(self):
return OrderedDict([
('account', forms.CharField(label=_('Account holder'))),
('iban', IBANFormField(label=_('IBAN'), validators=[NotBlocklisted(self)])),
('bic', BICFormField(label=_('BIC'))),
# ('bic', BICFormField(label=_('BIC'), required=False)), # no indication if optional, so we'd better remove the field, since it is no longer required
('mandate', forms.BooleanField(
label=_('I hereby grant the SEPA direct debit mandate for this order (see below)'))),
])
Expand Down Expand Up @@ -282,6 +277,7 @@ def checkout_confirm_render(self, request) -> str:
'event': self.event,
'settings': self.settings,
'iban': request.session['payment_sepa_iban'],
'bic': request.session['payment_sepa_bic'],
'date': self._due_date()
}
return template.render(ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<div class="form-horizontal">
<p>
{% blocktrans trimmed with iban=iban date=date|date:"SHORT_DATE_FORMAT" %}
We will debit the total amount displayed above from your bank account <strong>{{ iban }}</strong>.
We will debit the total amount displayed above from your bank account <strong>{{ iban }}</strong>
(<strong>BIC: {{ bic }}</strong>).
You hereby agree that the amount will be withdrawn from your bank account <strong>on or shortly after
{{ date }}</strong>.
{% endblocktrans %}
Expand Down