Command Line Interface (CLI) for generating and decoding Brazilian Pix codes (Static & Dynamic).
$ dotnet add package OpenPix.CliA high-performance, clean-code .NET library for handling Brazilian PIX (EMV BR Code) payments.
Most PIX implementations in .NET rely on string concatenation and lack proper validation. OpenPix was built with Domain-Driven Design (DDD) and Performance in mind.
ReadOnlySpan<char> for parsing, avoiding unnecessary string allocations.Merchant, TransactionId) instead of raw strings.OpenPix.Core) has zero dependencies.Lightweight, pure logic, zero dependencies.
dotnet add package OpenPix.Core
Global configuration and injection for Web APIs.
dotnet add package OpenPix.AspNetCore
If you need to render the QR Code image (PNG/SVG).
dotnet add package OpenPix.QRCode
OpenPix is optimized for high-throughput scenarios.
Comparing PixParser against a traditional string manipulation:
| Method | Mean | Allocated | Ratio |
|---|---|---|---|
| OpenPix | 2.664 μs | 272 B | 1.00x |
| Naive Implementation | 10.263 μs | 15,824 B | 3.85x |
Comparing PixBuilder (Fluent API + Full Validation) against manual string concatenation:
| Method | Mean | Allocated | Benefits |
|---|---|---|---|
| OpenPix | 1.48 μs | 1.83 KB | Less Memory, Full Validation, Clean Code |
| Naive Implementation | 1.50 μs | 3.02 KB | Error-prone, Hard to Maintain |
> Result: OpenPix allows you to write cleaner and safer code while using 40% less memory than manual concatenation.
Ideal for small businesses or P2P transfers.
using OpenPix;
var payload = PixBuilder.Create()
.WithKey("user@example.com")
.WithMerchant("My Store Name", "Sao Paulo", "12345-000") // ZipCode (Optional)
.WithAmount(12.50m)
.WithTransactionId("ORDER12345")
.Build();
Note: OpenPix automatically verifies CPF/CNPJ checksums (Mod11). If you pass an invalid key (e.g., typo), it will throw an exception immediately to prevent generating a useless QR Code.
Ideal for e-commerce integrations where the Bank/PSP provides a unique URL (Location).
var payload = PixBuilder.Create()
.WithDynamicUrl("https://pix.example.com/qr/v2/9d36b84f-70b3-40a1")
.WithMerchant("My Store Name", "Sao Paulo")
.WithAmount(50.00m) // Optional for Dynamic, but recommended for display
.Build();
Read a raw string, validate its CRC-16 signature, and hydrate a rich Domain Object.
using OpenPix;
var rawString = "00020126..."; // Input from a user or scanner
try
{
var pixData = PixParser.Parse(rawString);
if (!string.IsNullOrEmpty(pixData.Url))
{
Console.WriteLine($"Dynamic URL: {pixData.Url}");
}
else
{
Console.WriteLine($"Pix Key: {pixData.PixKey}");
}
Console.WriteLine($"Merchant: {pixData.Merchant?.Name}");
Console.WriteLine($"Amount: {pixData.Amount:C}");
Console.WriteLine($"TxID: {pixData.TxId.Value}");
}
catch (ArgumentException ex)
{
Console.WriteLine("Invalid PIX Code or Checksum mismatch.");
}
If you installed OpenPix.QRCode, you can convert the string directly to an image.
using OpenPix;
using OpenPix.QRCode; // Import extension methods
var payload = PixBuilder.Create()...Build();
// Generates a Base64 string ready for <img src="...">
// Automatically sets white background/black modules for banking app compatibility.
string base64Png = payload.ToPngBase64(pixelsPerModule: 10);
// Generates an SVG string for scalable vector graphics
string svgContent = payload.ToSvg();
// Generates an ASCII Art string for console applications
Console.WriteLine(payload.ToAsciiArt());
Easily expose an endpoint that generates Pix QR Codes on the fly using our minimal API extension.
Program.cs:
using OpenPix.AspNetCore; // Import namespace
var builder = WebApplication.CreateBuilder(args);
// 1. Add OpenPix services
// Configure PixKey in appsettings.json or via options
builder.Services.AddOpenPix(options =>
{
options.PixKey = "user@example.com";
options.MerchantName = "My Store";
options.City = "Sao Paulo";
});
var app = builder.Build();
// 2. Map the generator endpoint (returns PNG image)
app.MapPixQrCode("/api/pix/qrcode");
// Url example: /api/pix/qrcode?amount=10.50&txid=ORDER123
app.Run();
You can use OpenPix directly from your terminal to generate and decode PIX strings.
# Run from source (dev)
dotnet run --project src/OpenPix.Cli -- --help
# Or install as a global tool (once packed)
dotnet tool install -g OpenPix.Cli
Generate a Pix:
openpix gen --name "My Store" --city "Sao Paulo" --zip "12345-000" --key "user@example.com" --amount 10.50
Decode a Pix:
openpix decode "00020126..."
This project follows Clean Architecture principles:
Domain: Contains Value Objects (Merchant, TransactionId) that enforce business rules upon instantiation.Infra: Contains low-level algorithms like Crc16 and EmvCodec.QRCoder to handle the graphical matrix generation.IServiceCollection extensions and IPixClient for Web APIs.Contributions are welcome! Please check the Issues tab.
git checkout -b feature/AmazingFeature).git commit -m 'Add some AmazingFeature').git push origin feature/AmazingFeature).Distributed under the MIT License. See LICENSE for more information.