コード例 #1
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
コード例 #2
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"{_('Refund')} {refund_export.entity_slug} {row['id']} {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)
コード例 #3
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."))