SwissQrBill.Validation (SwissQrBill v0.2.0)

Copy Markdown View Source

Validation logic for Swiss QR bill data.

Summary

Functions

Validates that a string contains only characters allowed in Swiss QR codes.

Validates a creditor reference (ISO 11649 / SCOR format). Must start with RF, followed by 2 check digits, then 1-21 alphanumeric chars. Check digits are validated using mod-97-10.

Validates the mod-10 recursive check digit of a QR reference. Uses the standard Swiss modulo-10 table. Returns false for empty or non-digit input.

Validates a complete QR bill. Returns {:ok, bill} or {:error, errors}.

Returns non-blocking advisory warnings for a bill (these do not affect validity).

Functions

valid_characters?(string)

@spec valid_characters?(String.t()) :: boolean()

Validates that a string contains only characters allowed in Swiss QR codes.

valid_creditor_reference?(reference)

@spec valid_creditor_reference?(String.t()) :: boolean()

Validates a creditor reference (ISO 11649 / SCOR format). Must start with RF, followed by 2 check digits, then 1-21 alphanumeric chars. Check digits are validated using mod-97-10.

valid_mod10_check_digit?(reference)

@spec valid_mod10_check_digit?(String.t()) :: boolean()

Validates the mod-10 recursive check digit of a QR reference. Uses the standard Swiss modulo-10 table. Returns false for empty or non-digit input.

validate(bill)

Validates a complete QR bill. Returns {:ok, bill} or {:error, errors}.

warnings(bill)

@spec warnings(map()) :: [String.t()]

Returns non-blocking advisory warnings for a bill (these do not affect validity).

Currently warns when the QR-IBAN / QR-reference (QRR) combination is used with a non-CHF currency. Per SIX IG QR-bill v2.4 this combination is reserved for CHF; EUR invoices must use a regular IBAN with a Creditor Reference (SCOR) or no reference (NON). It becomes a hard rejection once euroSIC is discontinued (EUR QR-bills move to SEPA Credit Transfer by November 2027 at the latest).