SUNAT Electronic Invoicing API
A comprehensive electronic invoicing system for SUNAT Peru, developed with Laravel 12 and Greenter 5.1. This API implements all necessary functionalities for generating, sending, and managing electronic payment vouchers according to SUNAT regulations.What is SUNAT Electronic Invoicing?
SUNAT (Superintendencia Nacional de Aduanas y de Administración Tributaria) requires businesses in Peru to issue electronic invoices and receipts. This API provides a complete solution for:- Generating valid XML documents according to SUNAT specifications
- Sending documents to SUNAT for validation and approval
- Managing certificates, credentials, and company configurations
- Creating professional PDF representations with QR codes
- Handling responses (CDR) from SUNAT
Key Features
Supported Electronic Documents
Facturas
Electronic invoices (Type 01) for B2B transactions
Boletas de Venta
Sales receipts (Type 03) for B2C transactions
System Capabilities
Multi-Company Support
Multi-Company Support
Manage multiple companies and branches from a single installation. Each company can have:
- Independent RUC and credentials
- Separate SUNAT certificates
- Multiple branches with their own document series
- Custom tax configurations
OAuth2 Authentication
OAuth2 Authentication
Secure API access using Laravel Sanctum with:
- Token-based authentication
- Role-based permissions
- IP verification and login tracking
- Automatic token rotation
Automatic PDF Generation
Automatic PDF Generation
Professional PDF documents with:
- QR codes for validation
- Digital hash inclusion
- Company logo and branding
- A4 and custom formats
SUNAT Integration
SUNAT Integration
Direct integration with SUNAT services:
- Real-time document validation
- CDR (Constancia de Recepción) handling
- Beta and production environments
- Automatic retry mechanisms
Technology Stack
| Component | Technology | Version |
|---|---|---|
| Framework | Laravel | 12 |
| PHP | PHP | 8.2+ |
| SUNAT Library | Greenter | 5.1 |
| Database | MySQL/PostgreSQL | 8.0+ / 12+ |
| PDF Generation | DomPDF | 3.1 |
| QR Codes | Endroid QR Code | Latest |
| Authentication | Laravel Sanctum | 4.0 |
| Testing | PestPHP | 4.0 |
Architecture Overview
Data Models
The system uses a normalized database structure: Core Models:Company- Issuing companies with SUNAT credentialsBranch- Branch offices for each companyClient- Customers and suppliersInvoice/Boleta- Electronic documentsCompanyConfiguration- Per-company settingsCorrelative- Document series and numbering
Service Layer
The API implements a clean service-oriented architecture:- DocumentService - Business logic for document creation and validation
- GreenterService - SUNAT integration using Greenter library
- PdfService - PDF generation with templates
- FileService - XML/PDF/CDR file management
- CompanyConfigService - Configuration management
Who Should Use This API?
Software Developers
Integrate SUNAT electronic invoicing into existing systems or build new invoicing solutions.
Accounting Software
Add compliant electronic invoicing to accounting and ERP platforms.
E-commerce Platforms
Generate invoices and receipts automatically for online sales.
POS Systems
Issue electronic receipts directly from point-of-sale systems.
Compliance & Standards
This API is fully compliant with:UBL 2.1 (Universal Business Language) standard
SUNAT electronic invoicing regulations
Digital signature requirements using .pfx/.pem certificates
XML Schema validation for all document types
CDR (Constancia de Recepción) processing
Environment Support
The API supports both SUNAT environments:Always test thoroughly in the Beta environment before switching to production. SUNAT provides test credentials and certificates for the beta environment.
Getting Started
Ready to start issuing electronic invoices? Follow our guides:Quickstart
Get your first invoice created in 10 minutes
Installation
Complete installation and configuration guide
API Reference
Explore all available endpoints
Examples
Real-world implementation examples
License & Usage
This project is open source and free to use under the following conditions:Use, modify, and distribute the code freely
Use for commercial and personal projects
Important Considerations
Next Steps
Install the API
Follow the installation guide to set up the system on your server.
Create your first invoice
Use the quickstart guide to issue your first electronic document.
