Skip to main content

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

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
Secure API access using Laravel Sanctum with:
  • Token-based authentication
  • Role-based permissions
  • IP verification and login tracking
  • Automatic token rotation
Professional PDF documents with:
  • QR codes for validation
  • Digital hash inclusion
  • Company logo and branding
  • A4 and custom formats
Direct integration with SUNAT services:
  • Real-time document validation
  • CDR (Constancia de Recepción) handling
  • Beta and production environments
  • Automatic retry mechanisms

Technology Stack

ComponentTechnologyVersion
FrameworkLaravel12
PHPPHP8.2+
SUNAT LibraryGreenter5.1
DatabaseMySQL/PostgreSQL8.0+ / 12+
PDF GenerationDomPDF3.1
QR CodesEndroid QR CodeLatest
AuthenticationLaravel Sanctum4.0
TestingPestPHP4.0

Architecture Overview

Data Models

The system uses a normalized database structure: Core Models:
  • Company - Issuing companies with SUNAT credentials
  • Branch - Branch offices for each company
  • Client - Customers and suppliers
  • Invoice / Boleta - Electronic documents
  • CompanyConfiguration - Per-company settings
  • Correlative - 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:
https://e-beta.sunat.gob.pe/ol-ti-itcpfegem-beta/billService
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
All usage is at your own responsibility
No official warranty or support provided
You must comply with SUNAT regulations in your country

Important Considerations

Before Using in Production:
  • Ensure you have valid SUNAT digital certificates
  • Configure endpoints correctly for your environment (beta/production)
  • Perform thorough testing in beta environment
  • Keep security libraries updated
  • Backup your database regularly

Next Steps

1

Install the API

Follow the installation guide to set up the system on your server.
2

Configure SUNAT credentials

Set up your RUC, SOL credentials, and digital certificates.
3

Create your first invoice

Use the quickstart guide to issue your first electronic document.
4

Integrate with your system

Use the API endpoints to integrate with your existing applications.

Build docs developers (and LLMs) love