View Source QRNBU.Validators.Recipient (NBU payment QR v0.3.3)

Validates recipient name/description according to NBU QR code specifications.

Rules

  • V001/V002: Maximum 70 characters
  • V003: Maximum 140 characters
  • Cannot be empty or contain only whitespace
  • Should contain valid printable characters

Examples

iex> QRNBU.Validators.Recipient.validate("ТОВ Приватбанк", version: 2)
{:ok, "ТОВ Приватбанк"}

iex> QRNBU.Validators.Recipient.validate("Фізична особа-підприємець Іваненко Іван Іванович", version: 3)
{:ok, "Фізична особа-підприємець Іваненко Іван Іванович"}

iex> QRNBU.Validators.Recipient.validate("", version: 2)
{:error, "Recipient cannot be empty"}

iex> long_name = String.duplicate("А", 71)
iex> QRNBU.Validators.Recipient.validate(long_name, version: 2)
{:error, "Recipient exceeds maximum length of 70 characters for version 2"}

Summary

Functions

Gets the maximum length for recipient based on version.

Normalizes recipient name by trimming and removing extra whitespace.

Truncates recipient to maximum length for the specified version.

Validates recipient name/description for NBU QR code.

Types

@type options() :: [{:version, version()}]
@type version() :: 1 | 2 | 3

Functions

@spec max_length(version()) :: pos_integer()

Gets the maximum length for recipient based on version.

Examples

iex> QRNBU.Validators.Recipient.max_length(1)
70

iex> QRNBU.Validators.Recipient.max_length(2)
70

iex> QRNBU.Validators.Recipient.max_length(3)
140
@spec normalize(String.t()) :: String.t()

Normalizes recipient name by trimming and removing extra whitespace.

Examples

iex> QRNBU.Validators.Recipient.normalize("  ТОВ   Приватбанк  ")
"ТОВ Приватбанк"
Link to this function

truncate(recipient, opts \\ [])

View Source
@spec truncate(String.t(), options()) :: String.t()

Truncates recipient to maximum length for the specified version.

Useful for gracefully handling slightly too-long input.

Examples

iex> long_name = String.duplicate("А", 80)
iex> QRNBU.Validators.Recipient.truncate(long_name, version: 2)
String.slice(long_name, 0, 69)

iex> QRNBU.Validators.Recipient.truncate("Short name", version: 2)
"Short name"
Link to this function

validate(recipient, opts \\ [])

View Source
@spec validate(String.t(), options()) :: {:ok, String.t()} | {:error, String.t()}

Validates recipient name/description for NBU QR code.

Options:

  • version: QR code version (1, 2, or 3). Defaults to 2.

Returns {:ok, trimmed_recipient} or {:error, reason}.