Workflow Overview
The complete electronic invoicing process consists of 5 main steps:Prerequisites
Before starting, ensure you have:Valid P12 Certificate
From Banco Central del Ecuador or Security Data
SRI Test Account
For testing in the pruebas environment
Environment Variables
Certificate path, password, and SRI URLs
Open Factura Installed
npm install open-factura
Environment Setup
Create a.env file with your configuration:
Complete Implementation
Here’s a production-ready implementation of the complete workflow:Process Flow Diagram
Here’s a detailed breakdown of each step:Step 1: Generate Invoice
Step 1: Generate Invoice
Function:
generateInvoice()Input: InvoiceInput object with tax info, invoice details, and line itemsOutput:- Invoice object with complete structure
- 49-digit access key (claveAcceso)
Step 2: Convert to XML
Step 2: Convert to XML
Function:
generateInvoiceXml()Input: Invoice object from step 1Output: XML string formatted for SRIDuration: < 10msSee: Generating Invoices GuideStep 3: Sign Document
Step 3: Sign Document
Function:
signXml()Input:- P12 certificate (ArrayBuffer)
- Certificate password
- XML string from step 2
Step 4: Submit to Reception
Step 4: Submit to Reception
Function:
documentReception()Input:- Signed XML from step 3
- SRI reception endpoint URL
Step 5: Wait for Processing
Step 5: Wait for Processing
Action: Sleep/delayDuration: 2-3 seconds recommendedReason: SRI needs time to process and authorize the document
Step 6: Request Authorization
Step 6: Request Authorization
Error Handling Strategy
Implement comprehensive error handling at each step:Testing Checklist
Before moving to production:- Test with valid certificate in testing environment
- Test with expired certificate (should fail gracefully)
- Test with invalid invoice data (should be rejected)
- Test network timeout handling
- Test authorization retry logic
- Verify all XML files are stored correctly
- Verify access keys are generated correctly
- Test with different document types (credit notes, debit notes)
- Load test with multiple concurrent invoices
- Verify logging and monitoring is working
Production Deployment
Set up monitoring
Monitor:
- Success/failure rates
- Response times from SRI
- Certificate expiration dates
- Error types and frequencies
Performance Optimization
Parallel Processing
Process multiple invoices in parallel:Caching Certificates
Load certificate once and reuse:Next Steps
Invoice Generation
Generate invoice objects
Document Signing
Sign XML documents
Type Definitions
Explore available types