View Source UkraineNbuqrEx.Qr (ukraine_nbuqr v0.1.0)

This module is designed to generate Payment QR codes according to the National Bank of Ukraine (NBU) QR code standard.

Summary

Functions

Generates a QR code from the given data and options. As opttions it accepts the same options as to_qr/2 and to_string/2 functions.

encode/1 encodes the invoice string to Base64 format uses URL-safe Base64 encoding without padding

Generates a complete QR link with encoded invoice data

to_qr/2 generates a QR from the given data and options.

to_string/2 converts QR data struct to string representation of open data of invoice Combines QR data struct (service label, version, encoding, function, recipient, IBAN, amount, tax ID, purpose) into a string representation with newline separators.

Types

input_data()

@type input_data() :: output_data() | String.t()

output_data()

@type output_data() :: {:error, String.t()} | {:ok, String.t()}

Functions

create(data, options \\ [background_color: :transparent])

@spec create(data :: UkraineNbuqrEx.QrData.t(), options :: Keyword.t()) ::
  output_data()

Generates a QR code from the given data and options. As opttions it accepts the same options as to_qr/2 and to_string/2 functions.

encode(negative)

@spec encode(data :: input_data()) :: output_data()

encode/1 encodes the invoice string to Base64 format uses URL-safe Base64 encoding without padding

to_link(negative)

@spec to_link(encoded :: input_data()) :: output_data()

Generates a complete QR link with encoded invoice data

to_qr(data, options \\ [background_color: :transparent])

@spec to_qr(link :: input_data(), options :: Keyword.t()) :: output_data()

to_qr/2 generates a QR from the given data and options.

format option specifies the function for formatiing QR code. The default is &Config.svg/2. Complete list of format functions returns by Config.formats:

  • &Config.svg/2 generates an SVG image
  • &Config.png/2 generates a PNG image
  • &Config.ascii/2 generates a text representation of the QR code

Available options for all formats:

  • color in hexadecimal format. The default is #000
  • background_color in hexadecimal format or :transparent. The default is #FFF.
  • width the width of the QR code in pixel. Without the width attribute, the QR code size will be dynamically generated based on the input string.

Options avaliable for SVG format:

  • shape only square or circle. The default is square
  • viewbox when set to true, the SVG element will specify its height and width using viewBox, instead of explicit height and width tags.

Default options are

  [color: "#000", shape: "square", background_color: "#FFF"]

to_string(data, options \\ [background_color: :transparent])

@spec to_string(data :: UkraineNbuqrEx.QrData.t(), options :: Keyword.t()) ::
  output_data()

to_string/2 converts QR data struct to string representation of open data of invoice Combines QR data struct (service label, version, encoding, function, recipient, IBAN, amount, tax ID, purpose) into a string representation with newline separators.

Takes optional formatting options:

  • encoding specifies encoding (defaults to value from Config.encoding())
  • version specifies version (defaults to value from Config.version())