OpenPix.AspNetCore
1.2.1
dotnet add package OpenPix.AspNetCore --version 1.2.1
NuGet\Install-Package OpenPix.AspNetCore -Version 1.2.1
<PackageReference Include="OpenPix.AspNetCore" Version="1.2.1" />
<PackageVersion Include="OpenPix.AspNetCore" Version="1.2.1" />
<PackageReference Include="OpenPix.AspNetCore" />
paket add OpenPix.AspNetCore --version 1.2.1
#r "nuget: OpenPix.AspNetCore, 1.2.1"
#:package OpenPix.AspNetCore@1.2.1
#addin nuget:?package=OpenPix.AspNetCore&version=1.2.1
#tool nuget:?package=OpenPix.AspNetCore&version=1.2.1
OpenPix 🚀
A high-performance, clean-code .NET library for handling Brazilian PIX (EMV BR Code) payments.
💡 Why OpenPix?
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.
- ⚡ High Performance: Uses
ReadOnlySpan<char>for parsing, avoiding unnecessary string allocations. - 🛡️ Bulletproof Validation: Validates CRC-16 checksums, EMV field lengths, and CPF/CNPJ check digits (Mod11) ensuring no invalid keys are generated.
- ✨ Clean Code: Exposes a fluent API and rich Domain Objects (
Merchant,TransactionId) instead of raw strings. - 🔗 Dynamic & Static: Supports both Static PIX (Pix Key) and Dynamic PIX (PSP/Bank URL).
- 📦 Modular: The Core library (
OpenPix.Core) has zero dependencies.
🚀 Installation
1. The Core (Parser & Generator)
Lightweight, pure logic, zero dependencies.
dotnet add package OpenPix.Core
2. ASP.NET Core Integration (Dependency Injection)
Global configuration and injection for Web APIs.
dotnet add package OpenPix.AspNetCore
3. Visual Extension (Optional)
If you need to render the QR Code image (PNG/SVG).
dotnet add package OpenPix.QRCode
⚡ Benchmarks
OpenPix is optimized for high-throughput scenarios.
1. Parsing (Reader)
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 |
2. Building (Generator)
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.
📖 Usage
1. Generating a Static PIX (Pix Key)
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.
2. Generating a Dynamic PIX (PSP URL)
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();
3. Parsing and Validating (Reader)
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.");
}
4. Rendering the QR Code
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());
5. ASP.NET Core Integration
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();
🖥️ CLI Tool
You can use OpenPix directly from your terminal to generate and decode PIX strings.
Installation
# 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
Usage
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..."
🏗️ Architecture
This project follows Clean Architecture principles:
- OpenPix.Core:
Domain: Contains Value Objects (Merchant,TransactionId) that enforce business rules upon instantiation.Infra: Contains low-level algorithms likeCrc16andEmvCodec.- No external dependencies.
- OpenPix.QRCode:
- Depends on
QRCoderto handle the graphical matrix generation. - Extends the Core functionality.
- Depends on
- OpenPix.AspNetCore:
IServiceCollectionextensions andIPixClientfor Web APIs.
🤝 Contribution
Contributions are welcome! Please check the Issues tab.
- Fork the project.
- Create your Feature Branch (
git checkout -b feature/AmazingFeature). - Commit your changes (
git commit -m 'Add some AmazingFeature'). - Push to the Branch (
git push origin feature/AmazingFeature). - Open a Pull Request.
📄 License
Distributed under the MIT License. See LICENSE for more information.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- OpenPix.Core (>= 1.2.1)
- OpenPix.QRCode (>= 1.2.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.2.1 | 269 | 12/16/2025 |
| 0.0.0-alpha.0.27 | 224 | 12/16/2025 |