Exemplo n.º 1
0
    def test_bic_validator(self):
        valid = [
            'DEUTDEFF',
            'deutdeff',
            'NEDSZAJJXXX',
            'NEDSZAJJxxx',
            'DABADKKK',
            'daBadKkK',
            'UNCRIT2B912',
            'DSBACNBXSHA',
            None,
        ]

        invalid = {
            'NEDSZAJJXX': 'BIC codes have either 8 or 11 characters.',
            '': 'BIC codes have either 8 or 11 characters.',
            'CIBCJJH2': 'JJ is not a valid country code.',
            'D3UTDEFF': 'is not a valid institution code.',
            'DAAEDEDOXXX': 'is not a valid location code.',
            'DÉUTDEFF': 'codes only contain alphabet letters and digits.',
            'NEDSZAJJ XX': 'codes only contain alphabet letters and digits.',
        }

        bic_validator = BICValidator()
        for bic in valid:
            bic_validator(bic)

        for bic in invalid:
            self.assertRaisesMessage(ValidationError, invalid[bic],
                                     BICValidator(), bic)
Exemplo n.º 2
0
    def test_bic_validator_deconstruct(self):
        bic1 = BICValidator()
        bic2 = BICValidator()
        self.assertEqual(bic1, bic2, msg="BIC validators are not equal.")

        # Call to the deconstruct method to see if it exists.
        bic1.deconstruct()
Exemplo n.º 3
0
    def test_bic_validator_deconstruct(self):
        bic1 = BICValidator()
        bic2 = BICValidator()
        self.assertEqual(bic1, bic2, msg="BIC validators are not equal.")

        # Call to the deconstruct method to see if it exists.
        bic1.deconstruct()
Exemplo n.º 4
0
    def test_bic_validator_deconstruct(self):
        # Deconstruct method is required for django 1.7+ compatibility.
        bic1 = BICValidator()
        bic2 = BICValidator()
        self.assertEqual(bic1, bic2, msg="BIC validators are not equal.")

        # Call to the deconstruct method to see if it exists.
        bic1.deconstruct()
Exemplo n.º 5
0
    def test_bic_validator_deconstruct(self):
        # Deconstruct method is required for django 1.7+ compatibility.
        bic1 = BICValidator()
        bic2 = BICValidator()
        self.assertEqual(bic1, bic2, msg="BIC validators are not equal.")

        # Call to the deconstruct method to see if it exists.
        bic1.deconstruct()
Exemplo n.º 6
0
def get_refund_export_csv(refund_export: RefundExport):
    byte_data = io.BytesIO()
    StreamWriter = codecs.getwriter('utf-8')
    output = StreamWriter(byte_data)

    writer = csv.writer(output)
    writer.writerow(
        [_("Payer"), "IBAN", "BIC",
         _("Amount"),
         _("Currency"),
         _("Code")])
    for row in refund_export.rows_data:
        bic = ''
        if row.get('bic'):
            try:
                BICValidator()(row['bic'])
            except ValidationError:
                pass
            else:
                bic = row['bic']
        writer.writerow([
            row['payer'],
            row['iban'],
            bic,
            localize(Decimal(row['amount'])),
            refund_export.currency,
            row['id'],
        ])

    filename = _get_filename(refund_export) + ".csv"
    byte_data.seek(0)
    return filename, 'text/csv', byte_data
Exemplo n.º 7
0
def build_sepa_xml(refund_export: RefundExport, account_holder, iban, bic):
    if refund_export.currency != "EUR":
        raise ValueError("Cannot create SEPA export for currency other than EUR.")

    config = {
        "name": account_holder,
        "IBAN": iban,
        "BIC": bic,
        "batch": True,
        "currency": refund_export.currency,
    }
    sepa = SepaTransfer(config, clean=True)

    for row in refund_export.rows_data:
        payment = {
            "name": row['payer'],
            "IBAN": row["iban"],
            "amount": int(Decimal(row['amount']) * 100),  # in euro-cents
            "execution_date": datetime.date.today(),
            "description": f"{row['id']} {refund_export.entity_slug} {_('Refund')} {row.get('comment') or ''}".strip()[:140],
        }
        if row.get('bic'):
            try:
                BICValidator()(row['bic'])
            except ValidationError:
                pass
            else:
                payment['BIC'] = row['bic']

        sepa.add_payment(payment)

    data = sepa.export(validate=True)
    filename = _get_filename(refund_export) + ".xml"
    return filename, 'application/xml', io.BytesIO(data)
Exemplo n.º 8
0
 def payment_refund_supported(self, payment: OrderPayment) -> bool:
     if not all(
             payment.info_data.get(key)
             for key in ("payer", "iban", "bic")):
         return False
     try:
         IBANValidator()(self.norm(payment.info_data['iban']))
         BICValidator()(self.norm(payment.info_data['bic']))
     except ValidationError:
         return False
     else:
         return True
Exemplo n.º 9
0
    def clean(self):
        """Clean and validate the form data."""
        data = super().clean()

        # When `bank account` is chosen as refund type, three additional fields must be validated:
        # Bank account owner, IBAN and BIC.
        if data.get("refund_type") == "bank_account":
            if not data.get("bank_account_owner"):
                self.add_error("bank_account_owner", _("This field is required."))

            if data.get("bank_account_iban"):
                iban_validator = IBANValidator()
                try:
                    iban_validator(data.get("bank_account_iban"))
                except ValidationError:
                    self.add_error("bank_account_iban", _("A valid IBAN is required."))
            else:
                self.add_error("bank_account_iban", _("This field is required."))

            if data.get("bank_account_bic"):
                bic_validator = BICValidator()
                try:
                    bic_validator(data.get("bank_account_bic"))
                except ValidationError:
                    self.add_error("bank_account_bic", _("A valid BIC is required."))
            else:
                self.add_error("bank_account_bic", _("This field is required."))

        # Receipt validation
        if not any([data.get("receipt_{}_picture".format(i)) for i in range(10)]):
            self.add_error("receipt_0_picture", _("At least one receipt is required."))

        for i in range(10):
            if data.get(f"receipt_{i}_picture") and not data.get(f"receipt_{i}_amount"):
                self.add_error(f"receipt_{i}_picture",
                               _("The amount for this receipt is required."))
            elif data.get(f"receipt_{i}_amount") and not data.get(f"receipt_{i}_picture"):
                self.add_error(f"receipt_{i}_amount", _("The receipt for this amount is required."))