From 3897424667f7c674fb5bc321452a025ecaf8c758 Mon Sep 17 00:00:00 2001 From: Phin Wolkwitz Date: Tue, 2 Apr 2024 17:08:42 +0200 Subject: [PATCH 1/2] Change BIC check to lookup --- pretix_sepadebit/payment.py | 23 +++++++------------ .../checkout_payment_confirm.html | 3 ++- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/pretix_sepadebit/payment.py b/pretix_sepadebit/payment.py index f4cedbe..1cd1787 100644 --- a/pretix_sepadebit/payment.py +++ b/pretix_sepadebit/payment.py @@ -44,25 +44,17 @@ def clean(self): d = super().clean() + # lookup BIC if d.get('iban'): 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 + d['bic'] = DATA[iban_without_checksum[:k]] + else: + raise ValidationError( + _('There is no BIC number associated with this IBAN. Please double, check your banking ' + 'details.') ) - 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 - ) - ) return d @@ -247,7 +239,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)'))), ]) @@ -282,6 +274,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) diff --git a/pretix_sepadebit/templates/pretix_sepadebit/checkout_payment_confirm.html b/pretix_sepadebit/templates/pretix_sepadebit/checkout_payment_confirm.html index 6c90966..6bf8f70 100644 --- a/pretix_sepadebit/templates/pretix_sepadebit/checkout_payment_confirm.html +++ b/pretix_sepadebit/templates/pretix_sepadebit/checkout_payment_confirm.html @@ -4,7 +4,8 @@

{% blocktrans trimmed with iban=iban date=date|date:"SHORT_DATE_FORMAT" %} - We will debit the total amount displayed above from your bank account {{ iban }}. + We will debit the total amount displayed above from your bank account {{ iban }} + (BIC: {{ bic }}). You hereby agree that the amount will be withdrawn from your bank account on or shortly after {{ date }}. {% endblocktrans %} From 1ef8922187e7eff132ad787110c781339074b270 Mon Sep 17 00:00:00 2001 From: Phin Wolkwitz Date: Wed, 3 Apr 2024 12:42:38 +0200 Subject: [PATCH 2/2] Fix lookup --- pretix_sepadebit/payment.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pretix_sepadebit/payment.py b/pretix_sepadebit/payment.py index 1cd1787..1a3e267 100644 --- a/pretix_sepadebit/payment.py +++ b/pretix_sepadebit/payment.py @@ -46,17 +46,20 @@ def clean(self): # 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: d['bic'] = DATA[iban_without_checksum[:k]] - else: - raise ValidationError( - _('There is no BIC number associated with this IBAN. Please double, check your banking ' - 'details.') - ) + 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):