Brasilex (Brasilex v0.3.0)

Copy Markdown View Source

Brazilian utilities for boletos, state registration, and more.

Brasilex provides functions to validate and parse Brazilian documents, including boletos (bank slips) and state registration numbers (IE).

Supported Features

Boleto (Bank Slip)

  • Banking Boleto - Bank collection boletos
    • Linha digitável: 47 digits
    • Barcode: 44 digits
  • Convenio Boleto - Utility/tax boletos (starting with "8")
    • Linha digitável: 48 digits
    • Barcode: 44 digits

State Registration (Inscrição Estadual - IE)

Validates IE numbers for all 27 Brazilian states with auto-detection: AC, AL, AM, AP, BA, CE, DF, ES, GO, MA, MG, MS, MT, PA, PB, PE, PI, PR, RJ, RN, RO, RR, RS, SC, SE, SP, TO

Usage

# Validate a boleto
Brasilex.validate_boleto("23793.38128 60000.000003 00000.000400 1 84340000019900")
#=> :ok

# Parse a boleto
{:ok, boleto} = Brasilex.parse_boleto("23793.38128 60000.000003 00000.000400 1 84340000019900")
boleto.bank_code
#=> "237"

# Validate a state registration (auto-detects state)
Brasilex.validate_ie("110.042.490.114")
#=> :ok

# Parse a state registration (returns all matching states)
{:ok, [ie]} = Brasilex.parse_ie("110.042.490.114")
ie.state
#=> :sp

Error Handling

All functions return {:ok, result} or {:error, reason} tuples, making them pipe-friendly and composable. Bang variants (!) are provided for convenience when exceptions are preferred.

Summary

Functions

Parses a boleto linha digitável or barcode.

Same as parse_boleto/1 but raises on error.

Parses a State Registration (IE) number.

Same as parse_ie/1 but raises on error.

Validates a boleto linha digitável or barcode.

Same as validate_boleto/1 but raises on error.

Validates a State Registration (IE) number.

Same as validate_ie/1 but raises on error.

Functions

parse_boleto(input)

Parses a boleto linha digitável or barcode.

See Brasilex.Boleto.parse/1 for details.

parse_boleto!(input)

Same as parse_boleto/1 but raises on error.

See Brasilex.Boleto.parse!/1 for details.

parse_ie(input)

Parses a State Registration (IE) number.

Returns all possible state matches. See Brasilex.IE.parse/1 for details.

parse_ie!(input)

Same as parse_ie/1 but raises on error.

See Brasilex.IE.parse!/1 for details.

validate_boleto(input)

Validates a boleto linha digitável or barcode.

See Brasilex.Boleto.validate/1 for details.

validate_boleto!(input)

Same as validate_boleto/1 but raises on error.

See Brasilex.Boleto.validate!/1 for details.

validate_ie(input)

Validates a State Registration (IE) number.

See Brasilex.IE.validate/1 for details.

validate_ie!(input)

Same as validate_ie/1 but raises on error.

See Brasilex.IE.validate!/1 for details.