brfiscalfaker is a Go-based command-line tool designed to generate mock Brazilian fiscal invoices (NF-e, NFC-e, CFe, NFeDevolucao) for testing and development purposes. It allows users to create realistic invoice XML files with customizable data, facilitating the development of applications that interact with Brazilian fiscal systems.
- Supports Multiple Invoice Types: Generate NF-e, NFC-e, CFe, and NFeDevolucao invoices.
- Customizable Data: Provide custom CPF and CNPJ numbers.
- Block Specific Tags: Remove or block specific XML tags using the
--block-tags
flag. - Dependency Management: Ensures dependent placeholders are processed in the correct order.
- Cross-Platform: Works seamlessly on various operating systems.
- Comprehensive Logging: Provides detailed logs for debugging and transparency.
- Br documents: This project includes utilities to generate random yet valid Brazilian fiscal identifiers such as Access Key (Chave de Acesso), CPF, and CNPJ. These are essential for creating mock data for testing purposes.
- Unit Tested: Robust unit tests to ensure reliability.
Ensure you have Go installed on your system (version 1.16 or higher).
-
Clone the Repository:
git clone https://github.com/mayckol/brfiscalfaker.git cd brfiscalfaker
-
Build the Application:
go build -o bfiscalfaker ./cmd/bfiscalfaker/main.go
Run the application using the `go run command or the built binary.
--cpf
(optional
): --cpf: (Optional) Provide a custom CPF number to include in the invoice.--cnpj
(optional
): --cnpj: (Optional) Provide a custom CNPJ number to include in the invoice.--block-tags
(optional
): --block-tags: (Optional) Block specific XML tags from being included in the invoice.--type
(default NFCe
): --type: (Optional) Specify the type of invoice to generate (NF-e, NFC-e, CFe, NFeDevolucao).
-
Generate a Basic NFC-e Invoice:
go run cmd/bfiscalfaker/main.go
-
Generate an NF-e Invoice with Custom CPF and CNPJ:
go run cmd/bfiscalfaker/main.go --type NFe --cpf 12345678900 --cnpj 12345678901234
-
Generate a CFe Invoice with Blocked Tags:
go run cmd/bfiscalfaker/main.go --type CFe --block-tags "nItem, vProd"
-
Generate an NFCe Invoice with Custom Data and Blocked Tags:
go run cmd/bfiscalfaker/main.go --type NFCe --cpf 12345678900 --cnpj 12345678901234 --block-tags "nItem, vProd"
go get github.com/mayckol/brfiscalfaker
-
Random CNPJ, CPF, and Access Key Generation:
package main import ( "fmt" "github.com/mayckol/brfiscalfaker/pkg/br_documents" ) func main() { cpf := br_documents.CPF() cnpj := br_documents.CNPJ() accessKey := br_documents.AccessKey() fmt.Println("CPF:", cpf) fmt.Println("CNPJ:", cnpj) fmt.Println("Access Key:", accessKey) }
Parameters Description:
-
CPF()
- Config: Optional parameter to control output format.
Masked
:bool
. Iftrue
, the CPF is formatted asXXX.XXX.XXX-XX
. Default isfalse
(raw digits).
- Config: Optional parameter to control output format.
-
CNPJ()
- Config: Optional parameter to control output format.
Masked
:bool
. Iftrue
, the CNPJ is formatted asXX.XXX.XXX/XXXX-XX
. Default isfalse
(raw digits).
- Config: Optional parameter to control output format.
-
AccessKey()
- Config: Optional parameter to customize the generated key.
Masked
:bool
. Iftrue
, the Access Key is formatted with separators for readability. Default isfalse
(raw digits).
- Config: Optional parameter to customize the generated key.
package main
import (
"log"
"github.com/mayckol/brfiscalfaker/pkg/nfs"
"fmt"
)
func main() {
// Define the desired template type
templateType := nfs.NFCe
// Create the generator
generator, err := nfs.NewTemplateGenerator(templateType)
if err != nil {
log.Fatalf("Failed to create generator: %v", err)
}
options := []nfs.Option{
nfs.WithCPF("01234567890"),
nfs.WithCNPJ("12345678901234"),
}
// Generate the XML template
xmlBytes, err := generator.Generate(options...)
if err != nil {
log.Fatalf("Failed to generate XML template: %v", err)
}
fmt.Println(string(xmlBytes))
}
You can also run the application using Docker.
docker pull mayckol/bfiscalfaker
docker run mayckol/bfiscalfaker --type NFe --cpf 12345678900 --cnpj 12345678901234
Contributions are welcome! Feel free to open issues or submit pull requests to help improve this project.
This project is licensed under the MIT License. See the LICENSE file for more information.