facture_rs
A Rust wrapper for the FactureApp API, focused on Mexican electronic invoicing (CFDI) and billing operations.
Introduction
facture_rs provides a type-safe, asynchronous Rust interface to interact with the FactureApp API. It simplifies authentication, electronic stamping (timbrado), branch management, client administration, and other billing-related operations required for CFDI compliance in Mexico.
Features
- Authentication: Password-based OAuth2, refresh tokens, and authorization code flows
- Electronic Stamping (Timbrado): Stamp CFDI invoices in JSON format
- Branch Offices (Sucursales): Query and manage branch office information
- Clients: Client creation and management
- Concepts: Product/service concept management
- Self-Invoicing: Self-billing operations
- Cancellation: Invoice cancellation workflows
- Invoice Management: Query and manage issued invoices
- Emisor: Taxpayer (emisor) information management
Installation
Add facture_rs to your Cargo.toml:
[]
= "0.1.1"
= { = "1", = ["macros", "rt-multi-thread"] }
Or use cargo add:
Usage
Authentication
Obtain an access token using password credentials:
use ;
async
Electronic Stamping (Timbrado)
Stamp a CFDI invoice using a JSON payload:
use fs;
use ;
use ;
async
Branch Offices (Sucursales)
Query branch offices with filters:
use ;
async
How to Compile
This library requires Rust 1.85+ (2024 edition).
Development Build
Release Build
Running Tests
# Run all tests
# Run a specific test
# Run tests with output
Examples
The examples/ directory contains sample CFDI JSON payloads:
# Example CFDI structure
API Overview
| Module | Description | Status |
|---|---|---|
auth |
OAuth2 authentication flows | Implemented |
belling |
Electronic stamping (timbrado) | Implemented |
sucursal |
Branch office management | Implemented |
client |
Client management | Implemented |
concept |
Product/service concepts | Implemented |
self_invoice |
Self-billing operations | Implemented |
cancelation |
Invoice cancellation | Implemented |
invoicement |
Invoice management | Implemented |
emisor |
Taxpayer information | Implemented |
API Base URL
The library communicates with:
https://app.facture.com.mx/api
Dependencies
- reqwest — Async HTTP client
- serde — Serialization framework
- serde_json — JSON support
- tokio — Async runtime
- thiserror — Error handling
- base64 — Base64 encoding
Error Handling
The library uses a custom error type per module, all implementing std::error::Error:
AuthError— Authentication errors (network, parse, API)BillingError— Stamping errors (network, parse, API, setup)SucursalError— Branch office query errors- And more...
Each error provides detailed context about what went wrong.
License
This project is licensed under the MIT License.
MIT License
Copyright (c) 2024 facture_rs contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Contributing
Contributions are welcome! Feel free to open issues or submit pull requests.
Disclaimer
This is an unofficial wrapper. Please refer to the official FactureApp documentation for complete API specifications and usage guidelines.
See Also
- FactureApp — Official website
- CFDI Documentation — Mexican Tax Authority (SAT)
- Rust Async Book — Learn async Rust