View Source QRNBU.Versions.V002 (NBU payment QR v0.3.3)

NBU QR Code Version 002 structure with validation and encoding.

V002 uses Base64URL encoding with 13 fields as per NBU specification.

Fields

Required Fields

  • :recipient - Name of the recipient (validated by RecipientValidator)
  • :iban - Bank account IBAN (validated by IBANValidator)
  • :recipient_code - Recipient's identification code (validated by RecipientCodeValidator)
  • :purpose - Payment purpose description (validated by PurposeValidator)

Optional Fields

  • :amount - Payment amount as Decimal (validated by AmountValidator)
  • :reference - Payment reference number (validated by ReferenceValidator)
  • :function - Payment function code: :uct, :ict, or :xct (default: :uct)
  • :encoding - Character encoding: :utf8 or :cp1251 (default: :utf8)

Examples

iex> QRNBU.Versions.V002.new(%{
...>   recipient: "ТОВ Компанія",
...>   iban: "UA213223130000026007233566001",
...>   recipient_code: "12345678",
...>   purpose: "Оплата товарів"
...> })
{:ok, %QRNBU.Versions.V002{...}}

iex> QRNBU.Versions.V002.new(%{
...>   recipient: "ТОВ Компанія",
...>   iban: "UA213223130000026007233566001",
...>   amount: Decimal.new("100.50"),
...>   recipient_code: "12345678",
...>   reference: "INV-12345",
...>   purpose: "Оплата товарів",
...>   function: :uct,
...>   encoding: :utf8
...> })
{:ok, %QRNBU.Versions.V002{...}}

Summary

Functions

Encodes a V002 structure into the NBU QR code data string.

Creates a new V002 QR code structure with validation.

Types

@type t() :: %QRNBU.Versions.V002{
  amount: Decimal.t() | nil,
  display: String.t() | nil,
  encoding: :utf8 | :cp1251,
  function: :uct | :ict | :xct,
  iban: String.t(),
  purpose: String.t(),
  recipient: String.t(),
  recipient_code: String.t(),
  reference: String.t() | nil
}

Functions

@spec encode(t()) :: {:ok, String.t()} | {:error, String.t()}

Encodes a V002 structure into the NBU QR code data string.

Returns the Base64URL encoded format with https://qr.bank.gov.ua/ prefix.

Parameters

  • v002 - V002 structure to encode

Returns

  • {:ok, String.t()} - Encoded QR data string
  • {:error, String.t()} - Encoding error

Examples

iex> {:ok, v002} = QRNBU.Versions.V002.new(%{...})
iex> QRNBU.Versions.V002.encode(v002)
{:ok, "https://qr.bank.gov.ua/MQpVQ1QKVUFICgo..."}
@spec new(map()) :: {:ok, t()} | {:error, String.t()}

Creates a new V002 QR code structure with validation.

Parameters

  • attrs - Map with required and optional fields

Returns

  • {:ok, %QRNBU.Versions.V002{}} - Valid V002 structure
  • {:error, String.t()} - Validation error message

Examples

iex> QRNBU.Versions.V002.new(%{
...>   recipient: "ТОВ Компанія",
...>   iban: "UA213223130000026007233566001",
...>   recipient_code: "12345678",
...>   purpose: "Оплата товарів"
...> })
{:ok, %QRNBU.Versions.V002{}}

iex> QRNBU.Versions.V002.new(%{
...>   recipient: "",
...>   iban: "invalid",
...>   recipient_code: "123",
...>   purpose: ""
...> })
{:error, "Recipient name is required"}