Overview
Facturas (Invoices) are the primary electronic documents for B2B transactions in Peru. This guide covers creating, sending to SUNAT, and managing invoices using the API.Prerequisites
Before creating invoices, ensure you have:- A configured company with valid SUNAT credentials
- At least one active branch with configured invoice series
- Valid client information (RUC for invoices)
Creating an Invoice
Basic Invoice Creation
Complete Request Example
Success Response
Required Fields
ID of the company issuing the invoice
ID of the branch (must belong to the company)
Invoice series (max 4 characters, e.g., “F001”)
Issue date in YYYY-MM-DD format
Currency code:
PEN (Soles) or USD (Dollars)Operation type:
0101: Internal sale0200: Export0401: Non-domiciled sale
Payment type:
Contado (Cash) or Credito (Credit)Client Object
Document type:
6: RUC (required for invoices)4: Carnet de Extranjería1: DNI (only for amounts < 700 PEN)
Client’s document number (11 digits for RUC)
Client’s legal name
Details Array
Product/service code
Item description (max 500 characters)
Unit of measure (SUNAT catalog 03):
NIU: UnitsZZ: ServiceKGM: Kilograms
Quantity (minimum 0.001)
Unit value (without taxes)
Tax affectation type:
10: Taxable - IGV20: Exempt30: Unaffected40: Export
IGV percentage (usually 18%)
Sending to SUNAT
After creating an invoice, send it to SUNAT for validation:Success Response
Error Response
The API automatically generates the correlative number for each series. The invoice totals (IGV, subtotals) are calculated automatically from the details.
Downloading Documents
Download XML
Download CDR (SUNAT Response)
Download PDF
Available PDF formats:
A4, A5, 80mm, ticketAdvanced Features
Credit Payment with Installments
Invoice with Perception
Related Documents
Querying Invoices
List invoices with filters:Query Parameters
company_id: Filter by companybranch_id: Filter by branchestado_sunat: Filter by status (PENDIENTE,ACEPTADO,RECHAZADO)fecha_desde: Start date (YYYY-MM-DD)fecha_hasta: End date (YYYY-MM-DD)per_page: Items per page (default: 15)
Tax Affectation Types
| Code | Description | IGV |
|---|---|---|
10 | Taxable - IGV | Yes (18%) |
20 | Exempt | No |
30 | Unaffected | No |
40 | Export | No |
11 | Taxable - Free transfer | No (but calculated for reference) |
17 | Taxable - IVAP (rice) | Yes (4%) |
Implementation Notes
The invoice creation process fromapp/Http/Controllers/Api/InvoiceController.php:71-92 and app/Services/DocumentService.php:34-114:
- Validates company and branch relationship
- Creates or retrieves client record
- Generates automatic correlative number
- Processes details based on operation type (export vs. domestic)
- Calculates all totals automatically
- Generates standard legends
- Stores invoice in database with status
PENDIENTE
For export operations (
tipo_operacion: "0200"), the system automatically sets tip_afe_igv: "40" and calculates with 0% IGV.Common Errors
| Error | Cause | Solution |
|---|---|---|
| Branch doesn’t belong to company | branch_id doesn’t match company_id | Verify branch belongs to the company |
| Invalid RUC | Client RUC doesn’t exist in SUNAT | Verify RUC with SUNAT first |
| Invalid series | Series not configured for branch | Configure series in branch settings |
| Document already accepted | Trying to resend accepted invoice | Only pending invoices can be sent |
Best Practices
- Always validate client data before creating invoices
- Use consistent series for each document type and branch
- Store correlative numbers safely to avoid duplicates
- Handle SUNAT errors gracefully with proper error codes
- Generate PDF after SUNAT acceptance for better QR code data
- Keep XML and CDR files for auditing purposes
Next Steps
Credit Notes
Learn how to create credit notes for invoice corrections
PDF Generation
Customize invoice PDF templates and formats
