Download the PHP package husail/cnab-sdk without Composer
On this page you can find all versions of the php package husail/cnab-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package cnab-sdk
husail/cnab-sdk
PHP SDK for reading and writing CNAB 240 files, built on top of husail/edi-sdk.
Provides tools to generate, parse and validate CNAB 240 files with support for payment grouping, automatic record sequencing, and bank-specific layouts.
π Requirements
- PHP 8.2+
husail/edi-sdk ^1.0symfony/yaml
π¦ Installation
π¦ Supported banks and formats
| Bank | CNAB 240 | CNAB 150 | CNAB 400 |
|---|---|---|---|
| ItaΓΊ (341) | β Pagamentos | β | β |
| Bradesco (237) | π | β | β |
π Writing a payment file β ItaΓΊ CNAB 240
High-level API
batch_code, record_sequence, record_count (batch trailer) and batch_count, record_count (file trailer) are all filled automatically.
PIX by key β Segment A + Segment B PIX
PIX by key requires a segment_b_pix after each segment_a.
The segment_b_pix is distinguished from the standard segment_b by the
pix_key_type field at positions 15-16.
PIX key types (pix_key_type):
| Code | Type |
|---|---|
01 |
Phone |
02 |
|
03 |
CPF / CNPJ |
04 |
Random key (EVP) |
PIX by bank account β Segment A + Segment B
PIX by bank account data uses the standard segment_b (address/email complement).
The parser distinguishes them automatically: positions 15-16 are spaces for
standard segment_b and a key type code for segment_b_pix.
Multiple batches
Each ->batch() call creates a new batch with an incremented batch code:
According to SISPAG rules, PIX payments must be in a separate file from other payment types.
Overriding auto-calculated fields
All automatically calculated fields can be overridden:
π Reading a return file
The same layout covers both remessa (outgoing) and retorno (return).
The file_header.file_code field distinguishes them: 1 = remessa, 2 = retorno.
Return occurrence codes (occurrence_code at positions 231-240):
| Code | Meaning |
|---|---|
00 |
Paid / Processed |
BD |
Invalid bank |
AB |
Scheduling error |
| Others | See ItaΓΊ SISPAG manual (v086) for the full list |
ποΈ Grouped payments
groupPayments() reconstructs each payment with all its segments together,
grouped by batch_code + record_sequence.
Generic access
Typed PIX payments
Typed boleto payments
Filter grouped payments
β Validating a file
π οΈ Generic API β bring your own layout
Use Cnab::write() when you have a custom YAML or JSON layout:
ποΈ CNAB helpers
ποΈ Adding a new bank
Implement BankLayoutInterface and provide a YAML layout file:
The layout YAML follows the same structure as the ItaΓΊ layout.
See src/Layouts/Itau/cnab240/pagamentos/layout.yaml as reference.
A single layout file covers both remessa and retorno.
π How it relates to edi-sdk
Cnab::parse() and Cnab::validate() are thin wrappers over Edi::parse() and Edi::validate().
For full control, use the edi-sdk directly with Cnab240Itau::layout().
π§ͺ Testing
π€ Contributing
Contributions, issues and pull requests are welcome. \ If you find a bug or have a suggestion, feel free to open an issue.
π License
Licensed under the MIT License.