igorgbr
Hi everyone! I just published my first library on Hex: pix_brcode.
What is Pix? Pix is Brazil’s instant payment system, run by the Central Bank. It is used by most of the population and moves billions of transactions a month. Payments are usually made by scanning a QR code or pasting its text version, the “copia e cola” (copy and paste) code. That text is a BR Code: an EMV QR Code (Merchant-Presented Mode) payload with Pix-specific fields and a CRC16 checksum.
Why? Libraries for this are common in the JS ecosystem, but I couldn’t find an actively maintained Elixir package focused on generating and parsing Pix payloads, so I built one.
What it does (v0.1.0):
- Generates static payloads (Pix key, optional amount, txid, description)
- Generates dynamic payloads (URL provided by the receiver’s bank)
- Parses any payload into a struct, validating CRC, structure and the Pix GUI
- Validates Pix key formats (CPF, CNPJ, phone, e-mail, random key)
- Zero runtime dependencies
iex> PixBrcode.encode(%{
...> key: "123e4567-e89b-12d3-a456-426614174000",
...> amount: 1050,
...> merchant_name: "Fulano de Tal",
...> merchant_city: "Sao Paulo"
...> })
{:ok, "00020126580014br.gov.bcb.pix0136123e4567-..."}
iex> PixBrcode.decode(payload)
{:ok, %PixBrcode.Payload{type: :static, key: "123e4567-...", amount: "10.50", ...}}
Tested with real banks: a payload generated by the library was paid from Nubank and received at Itaú, and payloads generated by both banks’ apps are parsed correctly. That test caught something the spec alone didn’t: Nubank sends the GUI in uppercase (BR.GOV.BCB.PIX), so decoding is case-insensitive.
Out of scope for now: QR code image generation (the README shows how to do it with eqrcode) and calls to banks’ Pix APIs.
Feedback, issues and PRs are very welcome, especially from anyone already handling Pix in production.
Hex: pix_brcode | Hex
Docs: pix_brcode v0.1.0 — Documentation
Trending in Announcing
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex









